internal

package
v0.0.0-...-a9d8f56 Latest Latest
Warning

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

Go to latest
Published: May 15, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultUserAgent oxylabs.UserAgent = oxylabs.UA_DESKTOP
	DefaultDomain    oxylabs.Domain    = oxylabs.DOMAIN_COM

	DefaultStartPage int = 1
	DefaultPages     int = 1

	DefaultLimit_SERP      int = 10
	DefaultLimit_ECOMMERCE int = 48

	SyncBaseUrl  string = "https://realtime.oxylabs.io/v1/queries"
	AsyncBaseUrl string = "https://data.oxylabs.io/v1/queries"
)

Variables

View Source
var (
	DefaultTimeout      = 50 * time.Second
	DefaultPollInterval = 2 * time.Second
)

Functions

func InList

func InList[T comparable](val T, list []T) bool

InList checks if a value is present in the given slice.

func SetDefaultContentEncoding

func SetDefaultContentEncoding(contentEncoding *string)

SetDefaultContentEncoding sets the content_encoding parameter if it is not set.

func SetDefaultDomain

func SetDefaultDomain(domain *oxylabs.Domain)

SetDefaultDomain sets the domain parameter if it is not set.

func SetDefaultHotelOccupancy

func SetDefaultHotelOccupancy(ctx oxylabs.ContextOption)

SetDefaultHotelOccupancy sets the hotel_occupancy parameter if it is not set.

func SetDefaultHttpMethod

func SetDefaultHttpMethod(ctx oxylabs.ContextOption)

SetDefaultHttpMethod sets the http_method parameter in the ctx if it is not set.

func SetDefaultLimit

func SetDefaultLimit(limit *int, defaultLimit int)

SetDefaultLimit sets the limit parameter if it is not set.

func SetDefaultPages

func SetDefaultPages(pages *int)

SetDefaultPages sets the pages parameter if it is not set.

func SetDefaultSortBy

func SetDefaultSortBy(ctx oxylabs.ContextOption)

SetDefaultSortBy sets the sort_by parameter in the ctx if it is not set.

func SetDefaultStartPage

func SetDefaultStartPage(startPage *int)

SetDefaultStartPage sets the start_page parameter if it is not set.

func SetDefaultUserAgent

func SetDefaultUserAgent(userAgent *oxylabs.UserAgent)

SetDefaultUserAgent sets the user_agent_type parameter if it is not set.

func ValidateUrl

func ValidateUrl(
	inputUrl string,
	host string,
) error

ValidateUrl validates non-empty URL's scheme, host, and matches expected domain or host.

Types

type ApiCredentials

type ApiCredentials struct {
	Username string
	Password string
}

type Client

type Client struct {
	BaseUrl        string
	ApiCredentials *ApiCredentials
	HttpClient     *http.Client
}

func (*Client) GetHttpResp

func (c *Client) GetHttpResp(
	jobID string,
	httpChan chan *http.Response,
	errChan chan error,
)

Helper function for getting the http response from the request.

func (*Client) GetJobID

func (c *Client) GetJobID(
	jsonPayload []byte,
) (string, error)

Helper function to make a POST req and retrieve the Job ID.

func (*Client) PollJobStatus

func (c *Client) PollJobStatus(
	ctx context.Context,
	jobID string,
	pollInterval time.Duration,
	httpRespChan chan *http.Response,
	errChan chan error,
)

PollJobStatus polls the job status and manages the resp/error channels. ctx is the context of the req. jsonPayload is the payload for the req. pollInterval is the time to wait between each subsequent polling req. httpRespChan and errChan are the channels for the http resp and error respectively.

func (*Client) Req

func (c *Client) Req(
	ctx context.Context,
	jsonPayload []byte,
	method string,
) (*http.Response, error)

Req to the API. Ctx is the context of the req. JsonPayload is the payload for the req. Method is the HTTP method of the req.

type Job

type Job struct {
	ID     string `json:"id"`
	Status string `json:"status"`
}

Job struct to get job id and status for the async polling.

Jump to

Keyboard shortcuts

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