client

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 22 Imported by: 25

Documentation

Overview

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

Copyright 2014 Alvaro J. Genial. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. nolint

Package error provides the interface for Twilio specific errors.

Package form implements encoding and decoding of application/x-www-form-urlencoded data.

Copyright 2014 Alvaro J. Genial. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. nolint

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

Package config for config files.

Index

Constants

View Source
const LibraryVersion = "0.13.0"

LibraryVersion specifies the current version of twilio-go.

Variables

This section is empty.

Functions

func EncodeToString

func EncodeToString(dst interface{}) (string, error)

EncodeToString encodes dst as a form and returns it as a string.

func EncodeToStringWith

func EncodeToStringWith(dst interface{}, d rune, e rune, z bool) (string, error)

EncodeToStringWith encodes dst as a form with delimiter d, escape e, keeping zero values if z, and returns it as a string.

func EncodeToValues

func EncodeToValues(dst interface{}) (url.Values, error)

EncodeToValues encodes dst as a form and returns it as Values.

func EncodeToValuesWith

func EncodeToValuesWith(dst interface{}, d rune, e rune, z bool) (url.Values, error)

EncodeToValuesWith encodes dst as a form with delimiter d, escape e, keeping zero values if z, and returns it as Values.

func GetNext added in v0.13.0

func GetNext(response interface{}, curRecord *int, limit *int, getNextPage func(nextPageUri string) (interface{}, error)) (interface{}, error)

func GetPayload added in v0.13.0

func GetPayload(response interface{}) ([]interface{}, string, error)

func ReadLimits added in v0.13.0

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.

Types

type BaseClient added in v0.5.0

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
	// contains filtered or unexported fields
}

Client encapsulates a standard HTTP backend with authorization.

func (*Client) AccountSid added in v0.8.0

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) SetAccountSid added in v0.9.0

func (c *Client) SetAccountSid(sid string)

SetAccountSid sets the Client's accountSid field

func (*Client) SetTimeout

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

SetTimeout sets the Timeout for HTTP requests.

type Credentials

type Credentials struct {
	Username string
	Password string
}

Credentials store user authentication credentials.

func NewCredentials added in v0.8.0

func NewCredentials(username string, password string) *Credentials

type Encoder

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

Encoder provides a way to encode to a Writer.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new form Encoder.

func (*Encoder) DelimitWith

func (e *Encoder) DelimitWith(r rune) *Encoder

DelimitWith sets r as the delimiter used for composite keys by Encoder e and returns the latter; it is '.' by default.

func (Encoder) Encode

func (e Encoder) Encode(dst interface{}) error

Encode encodes dst as form and writes it out using the Encoder's Writer.

func (*Encoder) EscapeWith

func (e *Encoder) EscapeWith(r rune) *Encoder

EscapeWith sets r as the escape used for delimiters (and to escape itself) by Encoder e and returns the latter; it is '\\' by default.

func (*Encoder) KeepZeros

func (e *Encoder) KeepZeros(z bool) *Encoder

KeepZeros sets whether Encoder e should keep zero (default) values in their literal form when encoding, and returns the former; by default zero values are not kept, but are rather encoded as the empty string.

type RequestHandler added in v0.9.0

type RequestHandler struct {
	Client BaseClient
	Edge   string
	Region string
}

func NewRequestHandler added in v0.9.0

func NewRequestHandler(client BaseClient) *RequestHandler

func (*RequestHandler) BuildUrl added in v0.9.0

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

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

func (*RequestHandler) Delete added in v0.9.0

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

func (*RequestHandler) Get added in v0.9.0

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

func (*RequestHandler) Post added in v0.9.0

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

type RequestValidator added in v0.13.0

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

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

func NewRequestValidator added in v0.13.0

func NewRequestValidator(authToken string) RequestValidator

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

func (*RequestValidator) Validate added in v0.13.0

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

Validate can be used for Twilio 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 Twilio added to the configured webhook URL.

func (*RequestValidator) ValidateBody added in v0.13.0

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

ValidateBody can be used for Twilio 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.

type TwilioRestError added in v0.11.0

type TwilioRestError struct {
	Code     int                    `json:"code"`
	Details  map[string]interface{} `json:"details"`
	Message  string                 `json:"message"`
	MoreInfo string                 `json:"more_info"`
	Status   int                    `json:"status"`
}

TwilioRestError provides information about an unsuccessful request.

func (*TwilioRestError) Error added in v0.11.0

func (err *TwilioRestError) Error() string

Jump to

Keyboard shortcuts

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