common

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	//MaxIdleConns for Erply API
	MaxIdleConns = 25

	//MaxConnsPerHost for Erply API
	MaxConnsPerHost = 25
)
View Source
const (
	BaseUrl = "https://%s.erply.com/api/"
)

Variables

This section is empty.

Functions

func AssertFormValues added in v1.9.1

func AssertFormValues(t *testing.T, r *http.Request, expectedValues map[string]interface{})

func AssertRequestBulk added in v1.9.1

func AssertRequestBulk(t *testing.T, r *http.Request, expectedBulkRequest []map[string]interface{})

func ConvertStructToMap added in v1.4.0

func ConvertStructToMap(input interface{}) (map[string]interface{}, error)

func ExtractBulkFiltersFromRequest added in v1.7.5

func ExtractBulkFiltersFromRequest(r *http.Request) (res map[string]interface{}, err error)

func GetBaseURL

func GetBaseURL(cc string) string

func GetBaseURLFromAuthFunc added in v1.3.1

func GetBaseURLFromAuthFunc(f AuthFunc) string

func GetDefaultHTTPClient

func GetDefaultHTTPClient() *http.Client

func IsJSONResponseOK

func IsJSONResponseOK(responseStatus *common.Status) bool

Types

type AuthFunc added in v1.3.1

type AuthFunc func(string) url.Values

type BodyMock

type BodyMock struct {
	Body       io.Reader
	WasClosed  bool
	CloseError error
}

BodyMock implements resp.Body

func NewMockFromStr

func NewMockFromStr(body string) *BodyMock

NewFromStr creates BodyMock from a string

func NewMockFromStruct

func NewMockFromStruct(input interface{}) *BodyMock

NewFromStruct creates BodyMock from a struct converted to json or string

func (*BodyMock) Close

func (bm *BodyMock) Close() error

Close io.Closer implementation

func (*BodyMock) Read

func (bm *BodyMock) Read(p []byte) (n int, err error)

Read io.Reader implementation

type BulkInput added in v1.3.1

type BulkInput struct {
	MethodName string
	Filters    map[string]interface{}
}

type Client

type Client struct {
	Url string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(sk, cc, partnerKey string, httpCli *http.Client, headersForEveryRequestFunc AuthFunc) *Client

func NewClientWithURL added in v1.7.3

func NewClientWithURL(sk, cc, partnerKey, url string, httpCli *http.Client, headersForEveryRequestFunc AuthFunc) *Client

NewClientWithURL allows creating a new Client with a hardcoded URL. Useful for testing purposes

func (*Client) Close

func (cli *Client) Close()

func (*Client) SendRequest

func (cli *Client) SendRequest(ctx context.Context, apiMethod string, filters map[string]string) (*http.Response, error)

func (*Client) SendRequestBulk added in v1.3.1

func (cli *Client) SendRequestBulk(ctx context.Context, inputs []BulkInput, filters map[string]string) (*http.Response, error)

type ClientMock

type ClientMock struct {
	ErrToGive      error
	ResponseToGive *http.Response
	Requests       []*http.Request
	Lock           sync.Mutex
}

ClientMock mocks HttpClient interface

func (*ClientMock) Do

func (cm *ClientMock) Do(req *http.Request) (*http.Response, error)

Do HttpClient interface implementation

Jump to

Keyboard shortcuts

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