Documentation
¶
Index ¶
- func InvokeRequestAll(getFunc PaginatedGetFunc, responseFunc RequestAllResponseFunc, ...) error
- type APIConnection
- func (c *APIConnection) Delete(resource string, body interface{}) (*APIResponse, error)
- func (c *APIConnection) Get(resource string, parameters APIRequestParameters) (*APIResponse, error)
- func (c *APIConnection) Invoke(request APIRequest) (*APIResponse, error)
- func (c *APIConnection) InvokeRequest(req *http.Request) (*APIResponse, error)
- func (c *APIConnection) NewRequest(request APIRequest) (*http.Request, error)
- func (c *APIConnection) Patch(resource string, body interface{}) (*APIResponse, error)
- func (c *APIConnection) Post(resource string, body interface{}) (*APIResponse, error)
- func (c *APIConnection) Put(resource string, body interface{}) (*APIResponse, error)
- type APIKeyCredentials
- type APIRequest
- type APIRequestBodyDefaultValidator
- type APIRequestFiltering
- type APIRequestFilteringOperator
- type APIRequestPagination
- type APIRequestParameters
- func (p *APIRequestParameters) Copy() APIRequestParameters
- func (p *APIRequestParameters) WithFilter(filters ...APIRequestFiltering) *APIRequestParameters
- func (p *APIRequestParameters) WithPagination(pagination APIRequestPagination) *APIRequestParameters
- func (p *APIRequestParameters) WithSorting(sorting APIRequestSorting) *APIRequestParameters
- type APIRequestSorting
- type APIResponse
- type APIResponseBody
- type APIResponseBodyStringData
- type APIResponseError
- type APIResponseMetadata
- type APIResponseMetadataPagination
- type APIResponseMetadataPaginationLinks
- type AuthHeaders
- type Connection
- type Credentials
- type Date
- type DateTime
- type Enum
- type EnumSlice
- type ErrInvalidEnumValue
- type IPAddress
- type Paginated
- type PaginatedBase
- func (p *PaginatedBase) CurrentPage() int
- func (p *PaginatedBase) First() (Paginated, error)
- func (p *PaginatedBase) Last() (Paginated, error)
- func (p *PaginatedBase) Next() (Paginated, error)
- func (p *PaginatedBase) Previous() (Paginated, error)
- func (p *PaginatedBase) Total() int
- func (p *PaginatedBase) TotalPages() int
- type PaginatedGetFunc
- type RequestAll
- type RequestAllResponseFunc
- type ResponseBody
- type ResponseHandler
- type Validatable
- type ValidationError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InvokeRequestAll ¶ added in v1.1.0
func InvokeRequestAll(getFunc PaginatedGetFunc, responseFunc RequestAllResponseFunc, parameters APIRequestParameters) error
InvokeRequestAll is a convenience method for initialising RequestAll and calling Invoke()
Types ¶
type APIConnection ¶
type APIConnection struct { HTTPClient *http.Client Credentials Credentials APIURI string APIScheme string Headers http.Header UserAgent string }
func NewAPIConnection ¶
func NewAPIConnection(credentials Credentials) *APIConnection
func NewAPIKeyCredentialsAPIConnection ¶
func NewAPIKeyCredentialsAPIConnection(apiKey string) *APIConnection
NewAPIKeyCredentialsAPIConnection creates a new client
func (*APIConnection) Delete ¶
func (c *APIConnection) Delete(resource string, body interface{}) (*APIResponse, error)
Delete invokes a DELETE request, returning an APIResponse
func (*APIConnection) Get ¶
func (c *APIConnection) Get(resource string, parameters APIRequestParameters) (*APIResponse, error)
Get invokes a GET request, returning an APIResponse
func (*APIConnection) Invoke ¶
func (c *APIConnection) Invoke(request APIRequest) (*APIResponse, error)
Invoke invokes a request, returning an APIResponse
func (*APIConnection) InvokeRequest ¶
func (c *APIConnection) InvokeRequest(req *http.Request) (*APIResponse, error)
InvokeRequest invokes a request, returning an APIResponse
func (*APIConnection) NewRequest ¶
func (c *APIConnection) NewRequest(request APIRequest) (*http.Request, error)
NewRequest generates a new Request from given parameters
func (*APIConnection) Patch ¶
func (c *APIConnection) Patch(resource string, body interface{}) (*APIResponse, error)
Patch invokes a PATCH request, returning an APIResponse
func (*APIConnection) Post ¶
func (c *APIConnection) Post(resource string, body interface{}) (*APIResponse, error)
Post invokes a POST request, returning an APIResponse
func (*APIConnection) Put ¶
func (c *APIConnection) Put(resource string, body interface{}) (*APIResponse, error)
Put invokes a PUT request, returning an APIResponse
type APIKeyCredentials ¶
type APIKeyCredentials struct {
APIKey string
}
func (*APIKeyCredentials) GetAuthHeaders ¶
func (c *APIKeyCredentials) GetAuthHeaders() AuthHeaders
GetAuthHeaders returns the Authorization header for API key
type APIRequest ¶
type APIRequest struct { Method string Resource string Body interface{} Parameters APIRequestParameters }
type APIRequestBodyDefaultValidator ¶
type APIRequestBodyDefaultValidator struct { }
APIRequestBodyDefaultValidator provides convenience method Validate() for validating a struct/item, utilising the validator.v9 package
func (*APIRequestBodyDefaultValidator) Validate ¶
func (a *APIRequestBodyDefaultValidator) Validate(v interface{}) *ValidationError
Validate performs validation on item v using the validator.v9 package
type APIRequestFiltering ¶
type APIRequestFiltering struct { Property string Operator APIRequestFilteringOperator Value []string }
func NewAPIRequestFiltering ¶ added in v1.3.28
func NewAPIRequestFiltering(property string, operator APIRequestFilteringOperator, value []string) *APIRequestFiltering
type APIRequestFilteringOperator ¶
type APIRequestFilteringOperator int
const ( // EQOperator - equals EQOperator APIRequestFilteringOperator = iota // LKOperator - like LKOperator // GTOperator - greater than GTOperator // LTOperator - less than LTOperator // INOperator - in set INOperator // NEQOperator - not equal NEQOperator // NINOperator - not in set NINOperator // NLKOperator - not like NLKOperator )
func ParseOperator ¶
func ParseOperator(o string) (APIRequestFilteringOperator, error)
ParseOperator attempts to parse an operator from string
func (APIRequestFilteringOperator) String ¶
func (o APIRequestFilteringOperator) String() string
type APIRequestPagination ¶
type APIRequestParameters ¶
type APIRequestParameters struct { Pagination APIRequestPagination Sorting APIRequestSorting Filtering []APIRequestFiltering }
APIRequestParameters holds a collection of supported API request parameters
func NewAPIRequestParameters ¶ added in v1.3.5
func NewAPIRequestParameters() *APIRequestParameters
func (*APIRequestParameters) Copy ¶ added in v1.1.0
func (p *APIRequestParameters) Copy() APIRequestParameters
func (*APIRequestParameters) WithFilter ¶
func (p *APIRequestParameters) WithFilter(filters ...APIRequestFiltering) *APIRequestParameters
WithFilter is a fluent method for adding a set of filters to request parameters
func (*APIRequestParameters) WithPagination ¶
func (p *APIRequestParameters) WithPagination(pagination APIRequestPagination) *APIRequestParameters
WithPagination is a fluent method for adding pagination to request parameters
func (*APIRequestParameters) WithSorting ¶
func (p *APIRequestParameters) WithSorting(sorting APIRequestSorting) *APIRequestParameters
WithSorting is a fluent method for adding sorting to request parameters
type APIRequestSorting ¶
type APIResponse ¶
APIResponse represents the base API response
func (*APIResponse) DeserializeResponseBody ¶
func (r *APIResponse) DeserializeResponseBody(out interface{}) error
DeserializeResponseBody deserializes the API response body and stores the result in parameter out
func (*APIResponse) HandleResponse ¶
func (r *APIResponse) HandleResponse(respBody ResponseBody, handlers ...ResponseHandler) error
HandleResponse deserializes the response body into provided respBody, and validates the response using the optionally provided ResponseHandler handler
func (*APIResponse) ValidateStatusCode ¶
func (r *APIResponse) ValidateStatusCode(codes []int, respBody ResponseBody) error
ValidateStatusCode validates the API response
type APIResponseBody ¶
type APIResponseBody struct { Metadata APIResponseMetadata `json:"meta"` Errors []APIResponseError `json:"errors"` Message string `json:"message"` }
APIResponseBody represents the base API response body
func (*APIResponseBody) ErrorString ¶
func (a *APIResponseBody) ErrorString() string
ErrorString returns a formatted error string for API response
func (*APIResponseBody) Pagination ¶
func (a *APIResponseBody) Pagination() APIResponseMetadataPagination
TotalPages returns amount of pages for API response
type APIResponseBodyStringData ¶ added in v1.3.17
type APIResponseBodyStringData struct { APIResponseBody Data string `json:"data"` }
APIResponseBodyStringData represents the API response body containing string data
type APIResponseError ¶
type APIResponseError struct { Title string `json:"title"` Detail string `json:"detail"` Status int `json:"status"` Source string `json:"source"` }
APIResponseError represents an API response error
func (*APIResponseError) Error ¶
func (a *APIResponseError) Error() error
func (*APIResponseError) String ¶
func (a *APIResponseError) String() string
type APIResponseMetadata ¶
type APIResponseMetadata struct {
Pagination APIResponseMetadataPagination `json:"pagination"`
}
APIResponseMetadata represents the API response metadata
type APIResponseMetadataPagination ¶
type APIResponseMetadataPagination struct { Total int `json:"total"` Count int `json:"count"` PerPage int `json:"per_page"` TotalPages int `json:"total_pages"` Links APIResponseMetadataPaginationLinks `json:"links"` }
APIResponseMetadataPagination represents the API response pagination data
type APIResponseMetadataPaginationLinks ¶
type APIResponseMetadataPaginationLinks struct { Next string `json:"next"` Previous string `json:"previous"` First string `json:"first"` Last string `json:"last"` }
APIResponseMetadataPaginationLinks represents the links returned within the API response pagination data
type AuthHeaders ¶
AuthHeaders is a string map of authorization headers
type Connection ¶
type Connection interface { Get(resource string, parameters APIRequestParameters) (*APIResponse, error) Post(resource string, body interface{}) (*APIResponse, error) Put(resource string, body interface{}) (*APIResponse, error) Patch(resource string, body interface{}) (*APIResponse, error) Delete(resource string, body interface{}) (*APIResponse, error) Invoke(request APIRequest) (*APIResponse, error) }
type Credentials ¶
type Credentials interface {
GetAuthHeaders() AuthHeaders
}
type EnumSlice ¶ added in v1.3.3
type EnumSlice []Enum
func (EnumSlice) String ¶ added in v1.3.3
String returns string containing a comma separated list of enum string values
func (EnumSlice) StringSlice ¶ added in v1.3.3
StringSlice returns a slice of strings containing the string values of enums for EnumSlice
type ErrInvalidEnumValue ¶ added in v1.3.0
type ErrInvalidEnumValue struct {
Message string
}
func NewErrInvalidEnumValue ¶ added in v1.3.0
func NewErrInvalidEnumValue(msg string) *ErrInvalidEnumValue
func (*ErrInvalidEnumValue) Error ¶ added in v1.3.0
func (e *ErrInvalidEnumValue) Error() string
type Paginated ¶ added in v1.1.0
type Paginated interface { TotalPages() int CurrentPage() int Total() int First() (Paginated, error) Previous() (Paginated, error) Next() (Paginated, error) Last() (Paginated, error) }
Paginated represents a paginated API response
type PaginatedBase ¶ added in v1.1.0
type PaginatedBase struct {
// contains filtered or unexported fields
}
PaginatedBase implements the Paginated interface, and can be embedded to represent different paginated types
func NewPaginatedBase ¶ added in v1.1.0
func NewPaginatedBase(parameters APIRequestParameters, pagination APIResponseMetadataPagination, getFunc PaginatedGetFunc) *PaginatedBase
NewPaginatedBase returns a pointer to an initialised PaginatedBase
func (*PaginatedBase) CurrentPage ¶ added in v1.1.0
func (p *PaginatedBase) CurrentPage() int
CurrentPage returns the current page
func (*PaginatedBase) First ¶ added in v1.1.0
func (p *PaginatedBase) First() (Paginated, error)
First returns the the first page
func (*PaginatedBase) Last ¶ added in v1.1.0
func (p *PaginatedBase) Last() (Paginated, error)
Last returns the the last page
func (*PaginatedBase) Next ¶ added in v1.1.0
func (p *PaginatedBase) Next() (Paginated, error)
Next returns the the next page, or nil if current page is the last page
func (*PaginatedBase) Previous ¶ added in v1.1.0
func (p *PaginatedBase) Previous() (Paginated, error)
Previous returns the the previous page, or nil if current page is the first page
func (*PaginatedBase) Total ¶ added in v1.1.0
func (p *PaginatedBase) Total() int
Total returns the total number of items for current page
func (*PaginatedBase) TotalPages ¶ added in v1.1.0
func (p *PaginatedBase) TotalPages() int
TotalPages returns the total number of pages
type PaginatedGetFunc ¶ added in v1.1.0
type PaginatedGetFunc func(parameters APIRequestParameters) (Paginated, error)
PaginatedGetFunc represents a function which can be called for returning an implementation of Paginated
type RequestAll ¶
type RequestAll struct {
// contains filtered or unexported fields
}
RequestAll contains a single method Invoke(), which is a convenience method for iterating over paginated API responses
func NewRequestAll ¶ added in v1.1.0
func NewRequestAll(getFunc PaginatedGetFunc, responseFunc RequestAllResponseFunc) *RequestAll
NewRequestAll returns a pointer to an initialised RequestAll struct
func (*RequestAll) Invoke ¶
func (r *RequestAll) Invoke(parameters APIRequestParameters) error
Invoke iterates over all pages using provided parameters and the getFunc which RequestAll was intialised with
type RequestAllResponseFunc ¶ added in v1.1.0
type RequestAllResponseFunc func(Paginated)
RequestAllResponseFunc represents a function which is called after every request within Invoke()
type ResponseBody ¶
type ResponseBody interface { ErrorString() string Pagination() APIResponseMetadataPagination }
type ResponseHandler ¶ added in v1.0.32
type ResponseHandler func(resp *APIResponse) error
type Validatable ¶
type Validatable interface {
Validate() *ValidationError
}
type ValidationError ¶
type ValidationError struct {
Message string
}
func NewValidationError ¶
func NewValidationError(msg string) *ValidationError
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string