memberclicks

package module
v0.0.0-...-377ecce Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2017 License: MIT Imports: 14 Imported by: 0

README

Overview

GoDoc Build Status codecov

Golang API bindings to the MemberClicks API. It's being used in production but is far from complete. It should work in most, if not all environments, including Google App Engine.

For Memberclicks API documentation click here

Contributing

Pull requests are welcome, please submit tests with any new functionality.

Roadmap

[ ] Documentation examples [ ] Benchmarks [ ] 100% test coverage

Documentation

Index

Constants

View Source
const (
	ScopeRead = "read"
)

Scopes

Variables

View Source
var (
	ErrNoSuchField = errors.New("no such field")
	ErrEmptyMap    = errors.New("map is empty")
)

Error messages

View Source
var (
	ErrInvalidDstVal     = errors.New("invalid destination value")
	ErrCannotAssignValue = errors.New("cannot assign to destination value")
)

Errors related to copying values between interfaces

View Source
var (
	// Timeout is the duration before HTTP requests to the API servers time out
	Timeout = 15 * time.Second
)

Functions

This section is empty.

Types

type API

type API struct {
	Client  *http.Client
	Timeout time.Duration

	sync.RWMutex
	// contains filtered or unexported fields
}

API is an MemberClicks API client

func New

func New(orgID, clientID, clientSecret string) *API

New creates a new API client

func (*API) Auth

func (a *API) Auth(ctx context.Context) error

Auth initializes a default ClientCredentials requests and stores the resulting access token if successful

func (*API) AuthCodeRedirect

func (a *API) AuthCodeRedirect(w http.ResponseWriter, r *http.Request, scope, state, redirectURL string)

AuthCodeRedirect does an http.Redirect to the authcodeurl

func (*API) CheckPassword

func (a *API) CheckPassword(ctx context.Context, username, password string) (err error)

CheckPassword is shorthand for OwnerPasswordGrant, without returning the token

func (*API) ClientCredentials

func (a *API) ClientCredentials(ctx context.Context, scope string) (*Token, error)

ClientCredentials returns a client_credentials token

func (*API) Countries

func (a *API) Countries(ctx context.Context) (Countries, error)

Countries returns a list of countries

func (*API) CreateProfileSearch

func (a *API) CreateProfileSearch(ctx context.Context, params interface{}) (*ProfileSearchResp, error)

CreateProfileSearch creates a profile search and returns the resulting search ID. Profile searches exipre every half an hour.

func (*API) Do

func (a *API) Do(ctx context.Context, req *http.Request, result interface{}) error

Do sends the http.Request and marshals the JSON response into result

func (*API) Events

func (a *API) Events(ctx context.Context) (Events, error)

Events returns an event list

func (*API) Get

func (a *API) Get(ctx context.Context, urlStr string, result interface{}) error

Get sends a GET request to the urlStr and marshals the response into result

func (*API) GetAuthCodeURL

func (a *API) GetAuthCodeURL(scope, state, redirectURL string) string

GetAuthCodeURL returns a auth code URL for redirecting the client to authorize with MemberClicks

func (*API) GetAuthRequestURL

func (a *API) GetAuthRequestURL(scope, state, redirectURL string) string

func (*API) GetProfileSearch

func (a *API) GetProfileSearch(ctx context.Context, search *ProfileSearchResp) (*ProfileResp, error)

ProfileSearch returns a profile search with the given ID.

func (*API) GetToken

func (a *API) GetToken(ctx context.Context, authCode, scope, state, redirectURL string) (*Token, error)

GetToken trades an auth code for an access token

func (*API) Groups

func (a *API) Groups(ctx context.Context) (Groups, error)

Groups returns a list of groups for the acccount

func (*API) LastRequest

func (a *API) LastRequest() *http.Request

LastRequest returns a copy of the last HTTP request make to the API

func (*API) LastResponse

func (a *API) LastResponse() *http.Response

LastResponse returns a copy of the last HTTP request make to the API

func (*API) Me

func (a *API) Me(ctx context.Context, accessToken string) (*Profile, error)

Me returns the profile associated with the accessToken

func (*API) MemberStatuses

func (a *API) MemberStatuses(ctx context.Context) (MemberStatuses, error)

MemberStatuses returns the complete list of member statuses.

func (*API) MemberTypes

func (a *API) MemberTypes(ctx context.Context) (MemberTypes, error)

MemberTypes returns a slice of member types for the account

func (*API) OwnerPassword

func (a *API) OwnerPassword(ctx context.Context, username, password string) (*Token, error)

OwnerPassword returns a token with the owner "password" grant type

func (*API) Post

func (a *API) Post(ctx context.Context, urlStr string, form url.Values, result interface{}) error

Post sends a POST request to the urlStr and marshals the response into result

func (*API) PostJSON

func (a *API) PostJSON(ctx context.Context, urlStr string, data, result interface{}) error

PostJSON sends a JSON POST request to the API with the JSON encoded data

func (*API) Profile

func (a *API) Profile(ctx context.Context, id string) (*Profile, error)

Profile retrieves a profile with the given id

func (*API) ProfilePageCt

func (a *API) ProfilePageCt(ctx context.Context, pageSize int) (int, error)

ProfilePageCt gets the total number of profiles

func (*API) ProfileSearch

func (a *API) ProfileSearch(ctx context.Context, searchID string, pageNum int) (*ProfileResp, error)

ProfileSearch returns a profile search with the given ID. If pageNum is less than 1, all pages of the search will be returned.

func (*API) Profiles

func (a *API) Profiles(ctx context.Context, pageNum, pageSize int) (*ProfileResp, error)

Profiles returns a page of profiles. Set the pageNum to be < 1 to get all pages at the same time.

func (*API) RefreshToken

func (a *API) RefreshToken(ctx context.Context, scope string, refreshToken string) (*Token, error)

RefreshToken gets a new token from a refresh token

func (*API) ResourceOwnerCredentials

func (a *API) ResourceOwnerCredentials(ctx context.Context, username, password string) (*Token, error)

func (*API) SetAccessToken

func (a *API) SetAccessToken(accessToken string) *API

SetAccessToken sets the internal access token to use on requests if no other Authorization header is set.

type Countries

type Countries []Country

Countries is a list of countries

type Country

type Country struct {
	Name string `json:"name"`
}

Country is a country struct

func (Country) String

func (c Country) String() string

type Event

type Event struct {
	Name string `json:"name"`
	Date string `json:"date"`
}

Event is an event

type Events

type Events []Event

Events is a list of events

type Group

type Group struct {
	Name string `json:"name"`
}

Group is a group

type Groups

type Groups []Group

Groups is an slice of groups

type MemberStatus

type MemberStatus struct {
	Name string `json:"name"`
}

MemberStatus is a member status

type MemberStatuses

type MemberStatuses []MemberStatus

MemberStatuses is a complete list of member statuses.

type MemberType

type MemberType struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

MemberType is a member type

type MemberTypes

type MemberTypes []MemberType

MemberTypes is a MemberType list

type Profile

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

Profile is a memberclicks user profile. It stores the attributes in a private attributes map, and implmenets the interface of json.Marshaler, json.Unmarshaler, and datastore.PropertyLoadSaver to make the values accessible

func (*Profile) Attributes

func (p *Profile) Attributes() map[string]interface{}

func (*Profile) DeleteAttr

func (p *Profile) DeleteAttr(names ...string)

DeleteAttr deletes a given attribute

func (*Profile) Entity

func (p *Profile) Entity() string

Entity implements the aedstorm.EntityName interface

func (*Profile) Get

func (p *Profile) Get(name string, dstVal interface{}) error

Get retrieves the profile attribute with the given name into dstVal

func (*Profile) GetID

func (p *Profile) GetID() string

GetID implements the aedstorm.EntityID interface

func (*Profile) Groups

func (p *Profile) Groups() []string

func (*Profile) ID

func (p *Profile) ID() int64

ID returns the ID of the profile

func (*Profile) Load

func (p *Profile) Load(ps []datastore.Property) error

Load implements the datastore.PropertyLoadSaver interface

func (*Profile) MarshalJSON

func (p *Profile) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface

func (*Profile) MemberType

func (p *Profile) MemberType() string

MemberType returns the profile member type

func (*Profile) Save

func (p *Profile) Save() (list []datastore.Property, err error)

Save implements the PropertyLoadSaver interface

func (*Profile) Set

func (p *Profile) Set(name string, val interface{})

Set sets the profile attribute with the given name to val

func (*Profile) UnmarshalJSON

func (p *Profile) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface

type ProfileResp

type ProfileResp struct {
	TotalCount     int       `json:"totalCount"`
	TotalPageCount int       `json:"totalPageCount"`
	PageNumber     int       `json:"pageNumber"`
	PageSize       int       `json:"pageSize"`
	Count          int       `json:"count"`
	FirstPageURL   string    `json:"firstPageUrl"`
	NextPageURL    string    `json:"nextPageUrl"`
	LastPageURL    string    `json:"lastPageUrl"`
	Profiles       []Profile `json:"profiles"`
}

type ProfileSearchResp

type ProfileSearchResp struct {
	ID          string                 `json:"id"`
	ExpireDate  string                 `json:"expireDate"`
	Status      int                    `json:"status"`
	Timestamp   int64                  `json:"timestamp"`
	URL         string                 `json:"url"`
	Item        map[string]interface{} `json:"item"`
	ProfilesURL string                 `json:"profilesUrl"`
}

type Token

type Token struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	RefreshToken string `json:"refresh_token"`
	// ExpiresIn is expiration time in seconds, usually 3600 or one hour
	ExpiresIn int64  `json:"expires_in"`
	Scope     string `json:"scope"`
	ServiceID int64  `json:"serviceId"`
	UserID    int64  `json:"userId"`
	JTI       string `json:"jti"`
}

Token is a OAuth2 access token response from the server

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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