Go (Golang) client for MediaMath APIs
Go
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
authenticators/cookie
models
schema
testdata
time
.gitignore
.travis.yml
CONTRIBUTING.md
LICENSE
NOTICE
README.md
client.go
client_test.go
doc.go
entity.go
entity_test.go
errors.go
errors_test.go
integration_test.go
interfaces.go
masheryresponse.go
meta.go
pools.go
pools_test.go
session.go
struct_to_map.go
struct_to_map_test.go
user_params.go

README.md

go-t1

go-t1 is a Go client for MediaMath's APIs. API Documentation is available on the developer portal.

Reference: GoDoc

Table of Contents

Installation

$ go get github.com/MediaMath/go-t1

Usage

import (
	"fmt"
	"github.com/MediaMath/go-t1"
	"github.com/MediaMath/go-t1/authenticators/cookie"
	"github.com/MediaMath/go-t1/models"
	"log"
	"time"
)

To set up authentication, use an authenticator:

	// Set up configuration from envvars
	conf := cookie.GetCredentialsFromEnv()

	// Create new *http.Client with these credentials
	c, err := cookie.New(conf, t1.ProductionURL)
	if err != nil {
		log.Fatalf("initial login: %v", err)
	}

The authenticators are just *http.Client objects that know how to authenticate. Cookie is provided in the package authenticators/cookie, and OAuth2 is supported. To use OAuth2, use Google's OAuth2 package, with a MediaMath endpoint. An example is provided in the testdata/examples directory.

Construct a new client, then use the various services on the client to access different parts of the MediaMath API.

	// Construct new t1 client
	t1Client := t1.NewClient(c, conf.APIKey, t1.ProductionURL)

	// Model object gets passed in to the various service methods
	var org models.Organization

	meta, err := t1Client.Organizations.Get(100048, &org)
	if err != nil {
		log.Fatalf("get org error: %v", err)
	}
	fmt.Printf("Meta:\t%#v\nOrg:\t%#v\n", meta, org)

This whole example is available in the testdata/examples/get_organization directory. The testdata/examples directory also has examples of listing, creating, and updating entities.

Time Types

Execution and Management API currently returns times in a format conforming to ISO 8601 but not RFC 3339. As such, there is a time package t1time that provides a time type compatible with this. This is a time.Time type, so can be converted easily:

embedmd:# (testdata/examples/get_organization/main.go /time.[^)]*)/)

time.Time(org.CreatedOn)