client

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package client provides internal utilities for the reach-go client library.

Package error provides the interface for Reach specific errors.

Package mock_client is a generated GoMock package.

Package client provides internal utilities for the reach-go client library.

Package config for config files.

Index

Constants

View Source
const LibraryVersion = "1.0.0"

LibraryVersion specifies the current version of reach-go.

Variables

This section is empty.

Functions

func GetNext

func GetNext(baseUrl string, response interface{}, getNextPage func(nextPageUri string) (interface{}, error)) (interface{}, error)

func GetPrevious

func GetPrevious(baseUrl string, response interface{}, getPreviousPage func(previousPageUri string) (interface{}, error)) (interface{}, error)

func ReadLimits

func ReadLimits(pageSize *int, limit *int) int

Takes a limit on the max number of records to read and a max pageSize and calculates the max number of pages to read.

func UnmarshalFloat32

func UnmarshalFloat32(input *interface{}) (*float32, error)

func UrlWithoutPaginationInfo

func UrlWithoutPaginationInfo(baseUrl string, data url.Values) (string, error)

Types

type BaseClient

type BaseClient interface {
	AccountSid() string
	SetTimeout(timeout time.Duration)
	SendRequest(method string, rawURL string, data url.Values,
		headers map[string]interface{}) (*http.Response, error)
}

type Client

type Client struct {
	*Credentials
	HTTPClient          *http.Client
	UserAgentExtensions []string
}

Client encapsulates a standard HTTP backend with authorization.

func (*Client) AccountSid

func (c *Client) AccountSid() string

Returns the Account SID.

func (*Client) SendRequest

func (c *Client) SendRequest(method string, rawURL string, data url.Values,
	headers map[string]interface{}) (*http.Response, error)

SendRequest verifies, constructs, and authorizes an HTTP request.

func (*Client) SetTimeout

func (c *Client) SetTimeout(timeout time.Duration)

SetTimeout sets the Timeout for HTTP requests.

type Credentials

type Credentials struct {
	ApiUser string
	ApiKey  string
}

Credentials store user authentication credentials.

func NewCredentials

func NewCredentials(apiUser string, apiKey string) *Credentials

type MockBaseClient

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

MockBaseClient is a mock of BaseClient interface.

func NewMockBaseClient

func NewMockBaseClient(ctrl *gomock.Controller) *MockBaseClient

NewMockBaseClient creates a new mock instance.

func (*MockBaseClient) AccountSid

func (m *MockBaseClient) AccountSid() string

AccountSid mocks base method.

func (*MockBaseClient) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockBaseClient) SendRequest

func (m *MockBaseClient) SendRequest(method, rawURL string, data url.Values, headers map[string]interface{}) (*http.Response, error)

SendRequest mocks base method.

func (*MockBaseClient) SetTimeout

func (m *MockBaseClient) SetTimeout(timeout time.Duration)

SetTimeout mocks base method.

type MockBaseClientMockRecorder

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

MockBaseClientMockRecorder is the mock recorder for MockBaseClient.

func (*MockBaseClientMockRecorder) AccountSid

func (mr *MockBaseClientMockRecorder) AccountSid() *gomock.Call

AccountSid indicates an expected call of AccountSid.

func (*MockBaseClientMockRecorder) SendRequest

func (mr *MockBaseClientMockRecorder) SendRequest(method, rawURL, data, headers interface{}) *gomock.Call

SendRequest indicates an expected call of SendRequest.

func (*MockBaseClientMockRecorder) SetTimeout

func (mr *MockBaseClientMockRecorder) SetTimeout(timeout interface{}) *gomock.Call

SetTimeout indicates an expected call of SetTimeout.

type ReachRestError

type ReachRestError struct {
	Code     int                    `json:"errorCode"`
	Details  map[string]interface{} `json:"errorDetails"`
	Message  string                 `json:"errorMessage"`
	MoreInfo string                 `json:"more_info"`
	Status   int                    `json:"status"`
}

ReachRestError provides information about an unsuccessful request.

func (*ReachRestError) Error

func (err *ReachRestError) Error() string

type RequestHandler

type RequestHandler struct {
	Client BaseClient
}

func NewRequestHandler

func NewRequestHandler(client BaseClient) *RequestHandler

func (*RequestHandler) BuildUrl

func (c *RequestHandler) BuildUrl(rawURL string) (string, error)

BuildUrl builds the target host string taking into account region and edge configurations.

func (*RequestHandler) Delete

func (c *RequestHandler) Delete(path string, nothing url.Values, headers map[string]interface{}) (*http.Response, error)

func (*RequestHandler) Get

func (c *RequestHandler) Get(path string, queryData url.Values, headers map[string]interface{}) (*http.Response, error)

func (*RequestHandler) Post

func (c *RequestHandler) Post(path string, bodyData url.Values, headers map[string]interface{}) (*http.Response, error)

type RequestValidator

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

RequestValidator is used to verify the Reach Signature included with Reach requests to webhooks. This ensures the request is actually coming from Reach and helps with securing your webhooks.

func NewRequestValidator

func NewRequestValidator(authToken string) RequestValidator

NewRequestValidator returns a new RequestValidator which uses the specified auth token when verifying Reach signatures.

func (*RequestValidator) Validate

func (rv *RequestValidator) Validate(url string, params map[string]string, expectedSignature string) bool

Validate can be used for Reach Signatures sent with webhooks configured for GET calls. It returns true if the computed signature matches the expectedSignature. Params are a map of string to string containing all the query params Reach added to the configured webhook URL.

func (*RequestValidator) ValidateBody

func (rv *RequestValidator) ValidateBody(url string, body []byte, expectedSignature string) bool

ValidateBody can be used for Reach Signatures sent with webhooks configured for POST calls. It returns true if the computed signature matches the expectedSignature. Body is the HTTP request body from the webhook call as a slice of bytes.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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