client

package
v0.0.0-...-6b96c70 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountService

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

AccountService holds API functionality for accounts API.

func (*AccountService) Create

func (s *AccountService) Create(ctx context.Context, account *models.Account) (*models.Account, *Response, error)

Create registers an existing bank account with Form3 or create a new one. The country attribute must be specified as a minimum. Depending on the country, other attributes such as bank_id and bic are mandatory.

func (*AccountService) Delete

func (s *AccountService) Delete(ctx context.Context, id string) (*Response, error)

Delete an account using the account ID.

func (*AccountService) Fetch

func (s *AccountService) Fetch(ctx context.Context, id string) (*models.Account, *Response, error)

Fetch a single account using the account ID.

func (*AccountService) List

func (s *AccountService) List(ctx context.Context, pagination *Pagination) ([]models.Account, *Response, error)

List accounts with the ability to filter and page.

type Client

type Client struct {
	BaseURL *url.URL

	Account *AccountService
	// contains filtered or unexported fields
}

Client is API client.

func NewClient

func NewClient(httpClient *http.Client, baseURL *url.URL) *Client

NewClient creates new API client instance.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*Response, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, which will be resolved to the BaseURL of the Client. If body parameter is specified, the value pointed to by body is JSON encoded and included in as the request body.

type ErrorResponse

type ErrorResponse struct {
	Response   *http.Response
	StatusCode int
	Code       string `json:"error_code"`
	Message    string `json:"error_message"`
}

ErrorResponse is a custom error structure for API errors. It hold HTTP response that caused error and has all given details about an error.

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

Error is required to be implemented to meet error interface

type Links struct {
	First string `json:"first"`
	Last  string `json:"last"`
	Prev  string `json:"prev"`
	Next  string `json:"next"`
	Self  string `json:"self"`
}

Links holds information about response pagination.

func (*Links) CurrentPage

func (l *Links) CurrentPage() (int, error)

CurrentPage returns current page from given response. if prev link URL is invalid it throws an error.

func (*Links) IsLastPage

func (l *Links) IsLastPage() bool

IsLastPage check if page is last.

type Pagination

type Pagination struct {
	Page    int `url:"page[number],omitempty"`
	PerPage int `url:"page[size],omitempty"`
}

Pagination is a structure required to build query parameters for pagination.

type Response

type Response struct {
	Response *http.Response
	Data     json.RawMessage `json:"data"`
	Links    Links           `json:"links,omitempty"`
}

Response is API HTTP response.

func NewResponse

func NewResponse(r *http.Response) *Response

NewResponse creates a new Response for the provided http.Response

Jump to

Keyboard shortcuts

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