Giter Club home page Giter Club logo

aa-client-go's Introduction

Adobe Analytics API 2.0 Client

This project provides a client library for accessing the Adobe Analytics API 2.0.

Installation

Use the standard Go tool chain to use this library in your project.

Example:

go get -u github.com/adobe/aa-client-go

Usage

Create a new Analytics client with a http.DefaultClient.

client, err := analytics.NewClient(&analytics.Config{
    BaseURL:     "https://analytics.adobe.io/api",
    ClientID:    "<CLIENT-ID>",
    OrgID:       "<ORG-ID>",
    AccessToken: "<ACCESS-TOKEN>",
    CompanyID:   "<COMPANY-ID>",
})

Use specific API endpoint. For example, get all available metrics.

metrics, err := client.Metrics.GetAll("<ReportSuiteID>", "en_US", false, []string{})

See examples for more information about using the various API endpoints.

Authentication

Use ims-go to get an authentication token.

client, err := ims.NewClient(&ims.ClientConfig{
    URL: "https://ims-na1.adobelogin.com",
})

resp, err := client.ExchangeJWT(&ims.ExchangeJWTRequest{
    Expiration:   time.Now().Add(12 * time.Hour),
    PrivateKey:   []byte("<PRIVATE-KEY>"),
    Issuer:       "<ORG-ID>",
    Subject:      "<TECHNICAL-ACCOUNT-ID>",
    ClientID:     "<CLIENT-ID>",
    ClientSecret: "<CLIENT-SECRET>",
    MetaScope:    []ims.MetaScope{ims.MetaScopeAnalyticsBulkIngest},
})

accessToken := resp.AccessToken

Handling 429 status codes

To handle 429 response status codes (returned if the API rate limit is hit), a HTTP client with retry/backoff like go-retryablehttp can be used.

See the examples/utils/utils.go for an example of a custom rate limit policy.

retryClient := retryablehttp.NewClient()
retryClient.RetryMax = 10
retryClient.CheckRetry = rateLimitPolicy

client, err := analytics.NewClient(&analytics.Config{
    HTTPClient:  retryClient.StandardClient(),
    BaseURL:     "https://analytics.adobe.io/api",
    ClientID:    "<CLIENT-ID>",
    OrgID:       "<ORG-ID>",
    AccessToken: "<ACCESS-TOKEN>",
    CompanyID:   "<COMPANY-ID>",
})

Development

The module provides a Makefile with following targets.

  • all - Runs fmt, vet, lint and test.
  • fmt - Formats all code.
    Runs go fmt ./...
  • vet - Vets all code.
    Runs go vet -all ./...
  • lint - Lints all code.
    Runs golint ./...
  • test - Runs the test of the analytics package.
    Runs go test ./analytics -cover
  • coverage - Runs the tests of the analytics package and opens the coverage report.
    Runs go test -coverprofile=coverage.out ./analytics & go tool cover -html=coverage.out

A specific target can be executed by running the following command (Linux, macOS).

make [target]

Windows users can simply bypass make and run the plain commands as indicated above or install make via GNUWin32, Chocolatey or Windows Subsystem for Linux.

Contributing

Contributions are welcome! Read the Contributing Guide for more information.

Licensing

This project is licensed under the Apache 2.0 License. See LICENSE for more information.

aa-client-go's People

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.