Documentation ¶
Index ¶
- Constants
- Variables
- type AccessTokenResponse
- type BodyFormat
- type DatastoreManager
- type Date
- type Endpoint
- type HTTPHeader
- type HTTPMethod
- type HTTPStatusCode
- type Method
- type ModulesMethod
- type OAuth
- type Operation
- type Parameter
- type Scope
- type ScopeString
- type Service
- type SettingsMethod
- type Time
- type TokenLoaderSaver
- type TokenWrapper
- type Zoho
- func (z *Zoho) AuthorizationCodeRequest(clientID, clientSecret string, scopes []ScopeString, redirectURI string) (err error)
- func (z *Zoho) CheckForSavedTokens() error
- func (z *Zoho) CustomHTTPClient(c *http.Client)
- func (z *Zoho) GenerateTokenRequest(clientID, clientSecret, code, redirectURI string) (err error)
- func (z *Zoho) HTTPRequest(endpoint *Endpoint) (err error)
- func (z Zoho) LoadAccessAndRefreshToken() (AccessTokenResponse, error)
- func (z *Zoho) RefreshTokenRequest() (err error)
- func (z Zoho) SaveTokens(t AccessTokenResponse) error
- func (z *Zoho) SetClientID(clientID string)
- func (z *Zoho) SetClientSecret(clientSecret string)
- func (z *Zoho) SetOrganizationID(orgID string)
- func (z *Zoho) SetRefreshToken(refreshToken string)
- func (z *Zoho) SetTokenManager(tm TokenLoaderSaver)
- func (z *Zoho) SetTokensFile(s string)
- func (z *Zoho) SetZohoTLD(s string)
Constants ¶
const ( JSON = "" JSON_STRING = "jsonString" FILE = "file" URL = "url" // Added new BodyFormat option )
const ( // AllMethod is a possible Method portion of the scope string AllMethod Method = "ALL" // Territories is a possible Method portion of the scope string Territories SettingsMethod = "territories" // CustomViews is a possible Method portion of the scope string CustomViews SettingsMethod = "custom_views" // RelatedLists is a possible Method portion of the scope string RelatedLists SettingsMethod = "related_lists" // Modules is a possible Method portion of the scope string Modules SettingsMethod = "modules" // TabGroups is a possible Method portion of the scope string TabGroups SettingsMethod = "tab_groups" // Fields is a possible Method portion of the scope string Fields SettingsMethod = "fields" // Layouts is a possible Method portion of the scope string Layouts SettingsMethod = "layouts" // Macros is a possible Method portion of the scope string Macros SettingsMethod = "macros" // CustomLinks is a possible Method portion of the scope string CustomLinks SettingsMethod = "custom_links" // CustomButtons is a possible Method portion of the scope string CustomButtons SettingsMethod = "custom_buttons" // Roles is a possible Method portion of the scope string Roles SettingsMethod = "roles" // Profiles is a possible Method portion of the scope string Profiles SettingsMethod = "profiles" // Approvals is a possible Method portion of the scope string Approvals ModulesMethod = "approvals" // Leads is a possible Method portion of the scope string Leads ModulesMethod = "leads" // Accounts is a possible Method portion of the scope string Accounts ModulesMethod = "accounts" // Contacts is a possible Method portion of the scope string Contacts ModulesMethod = "contacts" // Deals is a possible Method portion of the scope string Deals ModulesMethod = "deals" // Campaigns is a possible Method portion of the scope string Campaigns ModulesMethod = "campaigns" // Tasks is a possible Method portion of the scope string Tasks ModulesMethod = "tasks" // Cases is a possible Method portion of the scope string Cases ModulesMethod = "cases" // Events is a possible Method portion of the scope string Events ModulesMethod = "events" // Calls is a possible Method portion of the scope string Calls ModulesMethod = "calls" // Solutions is a possible Method portion of the scope string Solutions ModulesMethod = "solutions" // Products is a possible Method portion of the scope string Products ModulesMethod = "products" // Vendors is a possible Method portion of the scope string Vendors ModulesMethod = "vendors" // PriceBooks is a possible Method portion of the scope string PriceBooks ModulesMethod = "pricebooks" // Quotes is a possible Method portion of the scope string Quotes ModulesMethod = "quotes" // SalesOrders is a possible Method portion of the scope string SalesOrders ModulesMethod = "salesorders" // PurchaseOrders is a possible Method portion of the scope string PurchaseOrders ModulesMethod = "purchaseorders" // Invoices is a possible Method portion of the scope string Invoices ModulesMethod = "invoices" // Custom is a possible Method portion of the scope string Custom ModulesMethod = "custom" // Dashboards is a possible Method portion of the scope string Dashboards ModulesMethod = "dashboards" // Notes is a possible Method portion of the scope string Notes ModulesMethod = "notes" // Activities is a possible Method portion of the scope string Activities ModulesMethod = "activities" // Search is a possible Method portion of the scope string Search ModulesMethod = "search" )
Variables ¶
var ErrClientSecretInvalidCode = errors.New("zoho: client secret used in authorization is invalid")
ErrClientSecretInvalidCode is turned when the client secret used is invalid
var ErrTokenExpired = errors.New("zoho: oAuth2 token already expired")
ErrTokenExpired should be returned when the token is expired but still exists in persistence
var ErrTokenInvalidCode = errors.New("zoho: authorization-code is invalid ")
ErrTokenInvalidCode is turned when the autorization code in a request is invalid
var HTTPStatusCodes = map[HTTPStatusCode]string{
200: "The API request is successful.",
201: "Request fulfilled for single record insertion.",
202: "Request fulfilled for multiple records insertion.",
204: "There is no content available for the request.",
304: "The requested page has not been modified. In case \"If-Modified-Since\" header is used for GET APIs",
400: "The request or the authentication considered is invalid.",
401: "Invalid API key provided.",
403: "No permission to do the operation.",
404: "Invalid request.",
405: "The specified method is not allowed.",
413: "The server did not accept the request while uploading a file, since the limited file size has exceeded.",
415: "The server did not accept the request while uploading a file, since the media/ file type is not supported.",
429: "Number of API requests per minute/day has exceeded the limit.",
500: "Generic error that is encountered due to an unexpected server error.",
}
HTTPStatusCodes is a map of possible HTTP Status Code and Messages
Functions ¶
This section is empty.
Types ¶
type AccessTokenResponse ¶
type AccessTokenResponse struct { AccessToken string `json:"access_token,omitempty"` RefreshToken string `json:"refresh_token,omitempty"` ExpiresIn int `json:"expires_in,omitempty"` APIDomain string `json:"api_domain,omitempty"` TokenType string `json:"token_type,omitempty"` Error string `json:"error,omitempty"` }
AccessTokenResponse is the data returned when generating AccessTokens, or Refreshing the token
type BodyFormat ¶
type BodyFormat string
type DatastoreManager ¶
DatastoreManager is an example TokenManager that satisfies the TokenManager interface When instantiating, user must provide the *http.Request for the current app engine request and the token key where the tokens are to be saved to/loaded from.
func (DatastoreManager) LoadAccessAndRefreshToken ¶
func (d DatastoreManager) LoadAccessAndRefreshToken() (AccessTokenResponse, error)
LoadAccessAndRefreshToken will use datastore package to get tokens from the datastore under the entity namespace 'ZohoAccessTokens' unless a value is provided to the EntityNamespace field
func (DatastoreManager) SaveTokens ¶
func (d DatastoreManager) SaveTokens(t AccessTokenResponse) error
SaveTokens will use datastore package to put tokens to the datastore under the entity namespace 'ZohoAccessTokens' unless a value is provided to the EntityNamespace field
type Date ¶
Date iis a time.Time which can be marshalled/unmarshalled according to Zoho's specific date scheme
func (*Date) MarshalJSON ¶
MarshalJSON is the json marshalling function for Date internal type
func (*Date) UnmarshalJSON ¶
UnmarshalJSON is the json unmarshalling function for Date internal type
type Endpoint ¶
type Endpoint struct { Method HTTPMethod URL string Name string ResponseData interface{} RequestBody interface{} URLParameters map[string]Parameter Headers map[string]string BodyFormat BodyFormat Attachment string }
Endpoint defines the data required to interact with most Zoho REST api endpoints
type HTTPHeader ¶
type HTTPHeader string
HTTPHeader is a type for defining possible HTTPHeaders that zoho request could return
type HTTPMethod ¶
type HTTPMethod string
HTTPMethod is a type for defining the possible HTTP request methods that can be used
const ( // HTTPGet is the GET method for http requests HTTPGet HTTPMethod = "GET" // HTTPPost is the POST method for http requests HTTPPost HTTPMethod = "POST" // HTTPPut is the PUT method for http requests HTTPPut HTTPMethod = "PUT" // HTTPDelete is the DELETE method for http requests HTTPDelete HTTPMethod = "DELETE" )
type HTTPStatusCode ¶
type HTTPStatusCode int
HTTPStatusCode is a type for resolving the returned HTTP Status Code Content
type OAuth ¶
type OAuth struct {
// contains filtered or unexported fields
}
OAuth is the OAuth part of the Zoho struct
type Operation ¶
type Operation string
Operation is a type for building scopes
const ( // NoOp is a possible Operation portion of the scope string NoOp Operation = "" // All is a possible Operation portion of the scope string All Operation = "ALL" // Read is a possible Operation portion of the scope string Read Operation = "READ" // Create is a possible Operation portion of the scope string Create Operation = "CREATE" // Update is a possible Operation portion of the scope string Update Operation = "UPDATE" // Delete is a possible Operation portion of the scope string Delete Operation = "DELETE" )
type Parameter ¶
type Parameter string
Parameter is used to provide URL Parameters to zoho endpoints
type Scope ¶
type Scope string
Scope is a type for building scopes
const ( // UsersScope is a possible Scope portion of the scope string UsersScope Scope = "users" // OrgScope is a possible Scope portion of the scope string OrgScope Scope = "org" // SettingsScope is a possible Scope portion of the scope string SettingsScope Scope = "settings" // ModulesScope is a possible Scope portion of the scope string ModulesScope Scope = "modules" // FullAccessScope is a possible Method portion of the scope string FullAccessScope Scope = "fullaccess" // ExpenseReportScope is a possible Method portion of the scope string ExpenseReportScope Scope = "expensereport" // ApprovalScope is a possible Method portion of the scope string ApprovalScope Scope = "approval" // ReimbursementScope is a possible Method portion of the scope string ReimbursementScope Scope = "reimbursement" // AdvanceScope is a possible Method portion of the scope string AdvanceScope Scope = "advance" // DataScope is a possible Method portion of the scope string DataScope Scope = "data" )
type ScopeString ¶
type ScopeString string
ScopeString is a type for defining scopes for oAuth2 flow
func BuildScope ¶
func BuildScope(service Service, scope Scope, method Method, operation Operation) ScopeString
BuildScope is used to generate a scope string for oAuth2 flow
type Time ¶
Time is a time.Time which can be marshalled/unmarshalled according to Zoho's specific time scheme
func (*Time) MarshalJSON ¶
MarshalJSON is the json marshalling function for Time internal type
func (*Time) UnmarshalJSON ¶
UnmarshalJSON is the json unmarshalling function for Time internal type
type TokenLoaderSaver ¶
type TokenLoaderSaver interface { SaveTokens(t AccessTokenResponse) error LoadAccessAndRefreshToken() (AccessTokenResponse, error) }
TokenLoaderSaver is an interface that can be implemented when using a system that does not allow disk persistence, or a different type of persistence is required. The use case that was in mind was AppEngine where datastore is the only persistence option.
type TokenWrapper ¶
type TokenWrapper struct { Token AccessTokenResponse Expires time.Time }
TokenWrapper should be used to provide the time.Time corresponding to the expiry of an access token
func (*TokenWrapper) CheckExpiry ¶
func (t *TokenWrapper) CheckExpiry() bool
CheckExpiry if the token expired before this instant
func (*TokenWrapper) SetExpiry ¶
func (t *TokenWrapper) SetExpiry()
SetExpiry sets the TokenWrappers expiry time to now + seconds until expiry
type Zoho ¶
Zoho is for accessing all APIs. It is used by subpackages to simplify passing authentication values between API subpackages.
func (*Zoho) AuthorizationCodeRequest ¶
func (z *Zoho) AuthorizationCodeRequest(clientID, clientSecret string, scopes []ScopeString, redirectURI string) (err error)
AuthorizationCodeRequest will request an authorization code from Zoho. This authorization code is then used to generate access and refresh tokens. This function will print a link that needs to be pasted into a browser to continue the oAuth2 flow. Then it will redirect to the redirectURL, it must be the same as the redirect URL that was provided to Zoho when generating your client ID and client secret. If the redirect URL was a localhost domain, the function will start a server that will get the code from the URL when the browser redirects. If the domain is not a localhost, you will be prompted to paste the code from the URL back into the terminal window, eg. https://domain.com/redirect-url?code=xxxxxxxxxx
func (*Zoho) CheckForSavedTokens ¶
func (*Zoho) CustomHTTPClient ¶
CustomHTTPClient can be used to provide a custom HTTP Client that replaces the once instantiated when executing New()
A notable use case is AppEngine where a user must use the appengine/urlfetch packages provided http client when performing outbound http requests.
func (*Zoho) GenerateTokenRequest ¶
GenerateTokenRequest will get the Access token and Refresh token and hold them in the Zoho struct. This function can be used rather than AuthorizationCodeRequest is you do not want to click on a link and redirect to a consent screen. Instead you can go to, https://accounts.zoho.com/developerconsole and click the kebab icon beside your clientID, and click 'Self-Client'; then you can define you scopes and an expiry, then provide the generated authorization code to this function which will generate your access token and refresh tokens.
func (*Zoho) HTTPRequest ¶
HTTPRequest is the function which actually performs the request to a Zoho endpoint as specified by the provided endpoint
func (Zoho) LoadAccessAndRefreshToken ¶
func (z Zoho) LoadAccessAndRefreshToken() (AccessTokenResponse, error)
LoadAccessAndRefreshToken will check for a provided 'TokenManager' interface if one exists it will use its provided method
func (*Zoho) RefreshTokenRequest ¶
RefreshTokenRequest is used to refresh the oAuth2 access token
func (Zoho) SaveTokens ¶
func (z Zoho) SaveTokens(t AccessTokenResponse) error
SaveTokens will check for a provided 'TokenManager' interface if one exists it will use its provided method
func (*Zoho) SetClientID ¶
func (*Zoho) SetClientSecret ¶
func (*Zoho) SetOrganizationID ¶
SetOrganizationID can be used to add organization id in zoho struct which is needed for expense apis
func (*Zoho) SetRefreshToken ¶
func (*Zoho) SetTokenManager ¶
func (z *Zoho) SetTokenManager(tm TokenLoaderSaver)
SetTokenManager can be used to provide a type which implements the TokenManager interface which will get/set AccessTokens/RenewTokens using a persistence mechanism
func (*Zoho) SetTokensFile ¶
SetTokensFile can be used to set the file location of the token persistence location, by default tokens are stored in a file in the current directory called '.tokens.zoho'
func (*Zoho) SetZohoTLD ¶
SetZohoTLD can be used to set the TLD extension for API calls for example for Zoho in EU and China. by default this is set to "com", other options are "eu" and "ch"