api

package
v0.0.0-...-858aeaf Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2015 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package api implements the Mixpanel API

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client provides a client to the Mixpanel API

func NewClient

func NewClient(config Config) *Client

NewClient returns a new client

func (*Client) Engage

func (c *Client) Engage(q *QueryOptions, out io.Writer) error

Engage implements mixpanel engage API

func (*Client) Export

func (c *Client) Export(q *QueryOptions, out io.Writer) error

Export implements the mixpanel export API

type Config

type Config struct {
	// Scheme is the URI scheme for the Mixpanel server.
	Scheme string

	// Address is URI of mixpanel server.
	Address string

	// Key is the API key for mixpanel access.
	Key string

	// Secret is the API secret for mixpanel access.
	Secret string

	// HttpClient is the client to use. Default will be used if not provided.
	HttpClient *http.Client
}

Config is used to configure the creation of a client

func DefaultConfig

func DefaultConfig() (*Config, error)

DefaultConfig returns a default configuration for the client

type EngageResponse

type EngageResponse struct {
	Page      int    `json:"page"`
	PageSize  int    `json:"page"`
	SessionID string `json:"session_id"`
	Status    string `json:"status"`
	Total     int    `json:"total"`

	Results []map[string]interface{} `json:"results"`
}

type QueryOptions

type QueryOptions struct {
	// Key is the API key for mixpanel access.
	Key string `json:"api_key"`

	// Secret is the API key for mixpanel access.
	Secret string `json:"api_secret"`

	// Expire is the UTC time in seconds;
	// used to expire an API request.
	Expire string `json:"expire"`

	// Sig is the auth signature for the method call, more documentation here
	// https://mixpanel.com/docs/api-documentation/data-export-api#auth-implementation .
	Sig string `json:"sig"`

	// FromDate sets the start date for export API. json/csv
	FromDate string `json:"from_date"`

	// ToDate sets the start date for export API.
	ToDate string `json:"to_date"`

	// Format describes the response format. json/csv
	Format string `json:"format"`

	// Event only exports data for this event.
	Event string `json:"event"`

	// SessionID used to maintain session in engage API
	SessionID string `json:"session_id"`

	// Page is page number to get results
	Page string `json:"page"`
}

QueryOptions describe the various options required for different requests the `json` struct tag value, decides name used in HTTP request

func DefaultExportQueryOptions

func DefaultExportQueryOptions(config *Config) *QueryOptions

func DefaultQueryOptions

func DefaultQueryOptions(config *Config) *QueryOptions

func MergeQueryOptions

func MergeQueryOptions(a, b *QueryOptions) *QueryOptions

func (*QueryOptions) AddSig

func (q *QueryOptions) AddSig()
 Adds sig to QueryOptions
 args = all query parameters going to be sent out with the request
 (e.g. api_key, unit, interval, expire, format, etc.) excluding sig.

 args_sorted = sort_args_alphabetically_by_key(args)

 args_concat = join(args_sorted)

 Output: api_key=ed0b8ff6cc3fbb37a521b40019915f18event=["pages"]
	  expire=1248499222format=jsoninterval=24unit=hour

 sig = md5(args_concat + api_secret)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL