Skip to content

MediaMath/go-t1

Repository files navigation

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)