httpapi

package
v0.0.0-...-8883774 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultBackoff

func DefaultBackoff(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration

DefaultBackoff provides a default callback for Backoff which will perform exponential backoff based on the attempt number and limited by the provided minimum and maximum durations. It also tries to parse XRateLimitReset response header when a http.StatusTooManyRequests (HTTP Code 429) is found in the resp parameter. Hence it will return the number of seconds the server states it may be ready to process more requests from this client.

func DefaultRetryPolicy

func DefaultRetryPolicy(resp *http.Response, err error) (bool, error)

DefaultRetryPolicy provides a default callback for CheckForRetry.

func ExecuteGet

func ExecuteGet[T any](ctx context.Context, apiClient *Client, url string, params any) (*T, error)

func ExecutePost

func ExecutePost[T any](ctx context.Context, apiClient *Client, url string, body any) (*T, error)

func ExecuteRawGet

func ExecuteRawGet(ctx context.Context, apiClient *Client, url string) (*http.Response, error)

func GetRawInspection

func GetRawInspection(ctx context.Context, apiClient *Client, id string) (*json.RawMessage, error)

GetRawInspection returns the JSON Raw Message of an inspection response

Types

type Backoff

type Backoff func(min, max time.Duration, attemptNum int, resp *http.Response) time.Duration

Backoff specifies a policy for how long to wait between retries. It is called after a failing request to determine the amount of time that should pass before trying again.

type CheckForRetry

type CheckForRetry func(resp *http.Response, err error) (bool, error)

CheckForRetry specifies a policy for handling retries. It is called following each request with the response and error values returned by the http.Client. If it returns false, the Client stops retrying and returns the response to the caller. If it returns an error, that error value is returned in lieu of the error from the request.

type Client

type Client struct {
	BaseURL string

	Duration      time.Duration
	CheckForRetry CheckForRetry

	RetryMax     int
	RetryWaitMin time.Duration
	RetryWaitMax time.Duration
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg *ClientCfg, opts ...Opt) *Client

NewClient creates a new instance of the Client

func (*Client) Do

func (a *Client) Do(ctx context.Context, doer HTTPDoer) (*http.Response, error)

func (*Client) HTTPClient

func (a *Client) HTTPClient() *http.Client

HTTPClient returns the http Client used by APIClient

func (*Client) HTTPTransport

func (a *Client) HTTPTransport() *http.Transport

HTTPTransport returns the http Transport used by APIClient

func (*Client) NewSling

func (a *Client) NewSling() *sling.Sling

type ClientCfg

type ClientCfg struct {
	Addr                string
	AuthorizationHeader string
	IntegrationID       string
	IntegrationVersion  string
}

type GetAccountsActivityLogRequestParams

type GetAccountsActivityLogRequestParams struct {
	OrgID     string                    `json:"org_id"`
	PageSize  int                       `json:"page_size"`
	PageToken string                    `json:"page_token"`
	Filters   accountsActivityLogFilter `json:"filters"`
}

GetAccountsActivityLogRequestParams contains fields required to make a post request to activity log history api

func NewGetAccountsActivityLogRequest

func NewGetAccountsActivityLogRequest(pageSize int, from time.Time, events []string) *GetAccountsActivityLogRequestParams

NewGetAccountsActivityLogRequest build a request for AccountsActivityLog for now it serves the purposes only for inspection.deleted. If we need later, we can change this builder

type GetAccountsActivityLogResponse

type GetAccountsActivityLogResponse struct {
	Activities    []activityResponse
	NextPageToken string `json:"next_page_token"`
}

GetAccountsActivityLogResponse is the response from activity log history api

type GetSheqsyCompanyResponse

type GetSheqsyCompanyResponse struct {
	CompanyID   int         `json:"companyId"`
	CompanyName string      `json:"companyName"`
	Name        interface{} `json:"name"`
	CompanyUID  string      `json:"companyUId"`
}

func GetSheqsyCompany

func GetSheqsyCompany(ctx context.Context, apiClient *Client, companyID string) (*GetSheqsyCompanyResponse, error)

GetSheqsyCompany returns the details for the selected company

type HTTPDoer

type HTTPDoer interface {
	Do() (*http.Response, error)
	URL() string
	Error() interface{}
}

HTTPDoer executes http requests.

type Header string

Header is used to represent name of a header

const (
	Authorization      Header = "Authorization"
	XRequestID         Header = "X-Request-ID"
	IntegrationID      Header = "sc-integration-id"
	IntegrationVersion Header = "sc-integration-version"
	XRateLimitReset    Header = "X-RateLimit-Reset"
)

Headers that are sent with each request when making api calls

type Inspection

type Inspection struct {
	ID         string    `json:"audit_id"`
	ModifiedAt time.Time `json:"modified_at"`
}

Inspection represents some properties present in an inspection

type InspectionReportExportCompletionResponse

type InspectionReportExportCompletionResponse struct {
	Status string `json:"status"`
	URL    string `json:"url,omitempty"`
}

InspectionReportExportCompletionResponse represents the response of report export completion status

func CheckInspectionReportExportCompletion

func CheckInspectionReportExportCompletion(ctx context.Context, apiClient *Client, auditID string, messageID string) (*InspectionReportExportCompletionResponse, error)

type ListInspectionsParams

type ListInspectionsParams struct {
	ModifiedAfter time.Time `url:"modified_after,omitempty"`
	TemplateIDs   []string  `url:"template,omitempty"`
	Archived      string    `url:"archived,omitempty"`
	Completed     string    `url:"completed,omitempty"`
	Limit         int       `url:"limit,omitempty"`
}

ListInspectionsParams is a list of all parameters we can set when fetching inspections

type ListInspectionsResponse

type ListInspectionsResponse struct {
	Count       int          `json:"count"`
	Total       int          `json:"total"`
	Inspections []Inspection `json:"audits"`
}

ListInspectionsResponse represents the response of listing inspections

func ListInspections

func ListInspections(ctx context.Context, apiClient *Client, params *ListInspectionsParams) (*ListInspectionsResponse, error)

ListInspections retrieves the list of inspections from SafetyCulture

type Opt

type Opt func(*Client)

Opt is an option to configure the Client

func OptAddTLSCert

func OptAddTLSCert(certPath string) Opt

OptAddTLSCert adds a certificate at the supplied path to the cert pool

func OptSetInsecureTLS

func OptSetInsecureTLS(insecureSkipVerify bool) Opt

OptSetInsecureTLS sets whether TLS certs should be verified

func OptSetProxy

func OptSetProxy(proxyURL *url.URL) Opt

OptSetProxy sets the proxy URL to use for API requests

func OptSetTimeout

func OptSetTimeout(t time.Duration) Opt

OptSetTimeout sets the timeout for the request

type WhoAmIResponse

type WhoAmIResponse struct {
	UserID         string `json:"user_id"`
	OrganisationID string `json:"organisation_id"`
	Firstname      string `json:"firstname"`
	Lastname       string `json:"lastname"`
}

WhoAmIResponse represents the response of WhoAmI

func WhoAmI

func WhoAmI(ctx context.Context, apiClient *Client) (*WhoAmIResponse, error)

WhoAmI returns the details for the user who is making the request

Jump to

Keyboard shortcuts

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