common

package
v1.27.3 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2024 License: MIT Imports: 16 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 ConvertSourceToJsonStrIfPossible added in v1.13.1

func ConvertSourceToJsonStrIfPossible(source interface{}) string

func ConvertStructToMap added in v1.4.0

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

func Die added in v1.13.1

func Die(err 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) GetSession added in v1.15.0

func (cli *Client) GetSession() (sessionKey string, err error)

func (*Client) InvalidateSession added in v1.15.0

func (cli *Client) InvalidateSession()

func (*Client) Scan added in v1.15.0

func (cli *Client) Scan(ctx context.Context, apiMethod string, filters map[string]string, dest DestRespWithStatus) error

func (*Client) SendParametersInRequestBody added in v1.22.0

func (cli *Client) SendParametersInRequestBody()

SendParametersInRequestBody indicates to the client that the request should add the data payload in the request body instead of using the query parameters. Using the request body eliminates the query size limitations imposed by the maximum URL length

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 ClientConstructor added in v1.15.0

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

func (*ClientConstructor) Build added in v1.15.0

func (cc *ClientConstructor) Build() *Client

func (*ClientConstructor) WithClientCode added in v1.15.0

func (cc *ClientConstructor) WithClientCode(clientCode string)

func (*ClientConstructor) WithHeaderFunc added in v1.15.0

func (cc *ClientConstructor) WithHeaderFunc(headersForEveryRequestFunc AuthFunc)

func (*ClientConstructor) WithHttpClient added in v1.15.0

func (cc *ClientConstructor) WithHttpClient(httpCli *http.Client)

func (*ClientConstructor) WithPartnerKey added in v1.15.0

func (cc *ClientConstructor) WithPartnerKey(partnerKey string)

func (*ClientConstructor) WithSessionKey added in v1.15.0

func (cc *ClientConstructor) WithSessionKey(sk string)

func (*ClientConstructor) WithSessionProvider added in v1.15.0

func (cc *ClientConstructor) WithSessionProvider(sessProv SessionProvider)

func (*ClientConstructor) WithURL added in v1.15.0

func (cc *ClientConstructor) WithURL(url string)

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

type DefaultSessionProvider added in v1.15.0

type DefaultSessionProvider struct {
	SessionKey string
}

func (*DefaultSessionProvider) GetSession added in v1.15.0

func (dsp *DefaultSessionProvider) GetSession() (sessionKey string, err error)

func (*DefaultSessionProvider) Invalidate added in v1.15.0

func (dsp *DefaultSessionProvider) Invalidate()

type DestRespWithStatus added in v1.15.0

type DestRespWithStatus interface {
	GetStatus() *common.Status
}

type SessionProvider added in v1.15.0

type SessionProvider interface {
	GetSession() (sessionKey string, err error)
	Invalidate()
}

Jump to

Keyboard shortcuts

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