client

package module
v0.0.0-...-47b9fc9 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2020 License: MIT Imports: 9 Imported by: 0

README

api-client-go

1CRM API client in Go

This is WIP.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithClientID

func WithClientID(id string) func(*AuthFlow)

WithClientID is used to set Client ID for Oauth2 flow

func WithClientSecret

func WithClientSecret(secret string) func(*AuthFlow)

WithClientSecret is used to set Client Secret for Oauth2 flow

func WithOwnerType

func WithOwnerType(ownerType string) func(*AuthFlow)

WithOwnerType is used to set Owner Type for Oauth2 flow

func WithPassword

func WithPassword(password string) func(*AuthFlow)

WithPassword is used to set password for Oauth2 flow

func WithRedirectURI

func WithRedirectURI(uri string) func(*AuthFlow)

WithRedirectURI is used to set redirect URI for Oauth2 flow

func WithScope

func WithScope(scope string) func(*AuthFlow)

WithScope is used to set Scope for Oauth2 flow

func WithState

func WithState(state string) func(*AuthFlow)

WithState is used to set State for Oauth2 flow

func WithUserName

func WithUserName(username string) func(*AuthFlow)

WithUserName is used to set User Name for Oauth2 flow

Types

type Auth

type Auth interface {
	ApplyRequestOptions(*http.Request) error
}

Auth is an interface that provides authentication info

type AuthCodeRequest

type AuthCodeRequest struct {
	GrantType    string `json:"grant_type"`
	ClientID     string `json:"client_id"`
	Scope        string `json:"scope"`
	ClientSecret string `json:"client_secret"`
	Code         string `json:"code"`
	RedirectURI  string `json:"redirect_uri"`
}

AuthCodeRequest is used to initiate Authorization Code flow

type AuthFlow

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

AuthFlow contains parameters of OAuth2 flow

func NewAuthFlow

func NewAuthFlow(url string, params ...AuthFlowOption) *AuthFlow

NewAuthFlow returns a AuthFlow

func (*AuthFlow) FinalizeAuthCode

func (flow *AuthFlow) FinalizeAuthCode(ctx context.Context, code string) (*OAuth2AccessToken, error)

FinalizeAuthCode completes the Authorization Code flow and returns an access token

func (*AuthFlow) InitAuthCode

func (flow *AuthFlow) InitAuthCode() (string, error)

InitAuthCode is used to initiate Authorization Code flow. It returns an URL the user is to be redirected to in order to complete the flow.

func (*AuthFlow) InitClientCredentials

func (flow *AuthFlow) InitClientCredentials(ctx context.Context) (*OAuth2AccessToken, error)

InitClientCredentials returns an access token using the client credentials

func (*AuthFlow) InitResourceOwner

func (flow *AuthFlow) InitResourceOwner(ctx context.Context) (*OAuth2AccessToken, error)

InitResourceOwner returns an access token for resource owner (user or contact)

type AuthFlowOption

type AuthFlowOption func(*AuthFlow)

AuthFlowOption provdes parameters for AuthFlow

type BasicAuth

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

BasicAuth provides Basic authentication

func NewBasicAuth

func NewBasicAuth(username, password string) *BasicAuth

NewBasicAuth returns a new BasicAuth

func (*BasicAuth) ApplyRequestOptions

func (auth *BasicAuth) ApplyRequestOptions(req *http.Request) error

ApplyRequestOptions implements Auth.ApplyRequestOptions

type Client

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

Client is used to send requests to the API

func NewClient

func NewClient(ctx context.Context, url string, auth Auth) *Client

NewClient returns a new API Client

func (*Client) Delete

func (c *Client) Delete(endpoint string, options ...RequestOption) (*Response, error)

Delete is convenience wrapper around Request() to send a DELETE request

func (*Client) Get

func (c *Client) Get(endpoint string, options ...RequestOption) (*Response, error)

Get is convenience wrapper around Request() to send a GET request

func (*Client) Patch

func (c *Client) Patch(endpoint string, options ...RequestOption) (*Response, error)

Patch is convenience wrapper around Request() to send a Patch request

func (*Client) Post

func (c *Client) Post(endpoint string, options ...RequestOption) (*Response, error)

Post is convenience wrapper around Request() to send a POST request

func (*Client) Put

func (c *Client) Put(endpoint string, options ...RequestOption) (*Response, error)

Put is convenience wrapper around Request() to send a PUT request

func (*Client) Request

func (c *Client) Request(method string, endpoint string, options ...RequestOption) (*Response, error)

Request sends an HTTP request with arbitrary HTTP method

type ClientCredentialsRequest

type ClientCredentialsRequest struct {
	GrantType    string `json:"grant_type"`
	ClientID     string `json:"client_id"`
	Scope        string `json:"scope"`
	ClientSecret string `json:"client_secret"`
}

revive:disable:exported ClientCredentialsRequest is used to initiate Client Credentials flow

type Error

type Error interface {
	error
	Code() int
}

Error is used to represent errors returned by the API. It contains error message and HTTP code.

type OAuth2AccessToken

type OAuth2AccessToken struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
}

OAuth2AccessToken is a token used for OAuth 2.0

func (*OAuth2AccessToken) ApplyRequestOptions

func (auth *OAuth2AccessToken) ApplyRequestOptions(req *http.Request) error

ApplyRequestOptions implements Auth.ApplyRequestOptions

type RequestOption

type RequestOption func(*requestOptions) error

RequestOption is a function used to set options of a request to the API

func WitchContext

func WitchContext(ctx context.Context) RequestOption

WitchContext is a RequestOption that sets the request's context

func WithBody

func WithBody(body io.Reader) RequestOption

WithBody is a RequestOption that sets the body of the HTTP request

func WithContentType

func WithContentType(contentType string) RequestOption

WithContentType is a RequestOption that sets the Content-Type header of the HTTP request

func WithHeader

func WithHeader(name, value string) RequestOption

WithHeader is a RequestOption that sets a header of the HTTP request

func WithJSONBody

func WithJSONBody(content interface{}) RequestOption

WithJSONBody is a RequestOption that sets the request's body to a JSON string

func WithQuery

func WithQuery(query url.Values) RequestOption

WithQuery is a RequestOption that sets the query part of the HTTP request URL

func WithQueryValue

func WithQueryValue(key, value string, append bool) RequestOption

WithQueryValue is a RequestOption that sets one parameter of the the query part of the HTTP request URL

type ResourceOwnerRequest

type ResourceOwnerRequest struct {
	GrantType    string `json:"grant_type"`
	ClientID     string `json:"client_id"`
	Scope        string `json:"scope"`
	ClientSecret string `json:"client_secret"`
	Username     string `json:"username"`
	Password     string `json:"password"`
}

ResourceOwnerRequest is used to initiate Resource Owner flow

type Response

type Response struct {
	HTTPResponse *http.Response
}

Response is a response returned from requests to the API

func (*Response) ParseJSON

func (res *Response) ParseJSON(out interface{}) error

ParseJSON parses response body into supplied argument

func (*Response) String

func (res *Response) String() (string, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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