Documentation
¶
Index ¶
- Constants
- type ApiRequest
- func (request *ApiRequest) AddField(field ApiRequestQueryParamField) *ApiRequestQueryParamField
- func (request *ApiRequest) AddQueryParam(key, value string)
- func (request *ApiRequest) Execute() (string, error)
- func (request *ApiRequest) ExecuteContext(ctx context.Context) (string, error)
- func (request *ApiRequest) SetBody(body string)
- func (request *ApiRequest) SetMethod(method string)
- type ApiRequestQueryParamField
- type GraphAPIError
- type Options
- type RequestClient
- func (client *RequestClient) ApiVersion() string
- func (client *RequestClient) BaseUrl() string
- func (client *RequestClient) NewApiRequest(path, method string) *ApiRequest
- func (rc *RequestClient) RequestMultipart(method string, path string, body io.Reader, contentType string) (string, error)
- func (rc *RequestClient) RequestMultipartContext(ctx context.Context, method string, path string, body io.Reader, ...) (string, error)
- type RequestCloudApiParams
- type WhatsappApiType
Constants ¶
const ( API_VERSION = "v20.0" BASE_URL = "graph.facebook.com" REQUEST_PROTOCOL = "https" )
const DefaultResponseHeaderTimeout = 60 * time.Second
DefaultResponseHeaderTimeout bounds how long the default HTTP client waits for Meta to start responding once a request has been fully written. It does not limit how long writing the request body takes, so large media uploads are not cut off.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ApiRequest ¶
type ApiRequest struct {
Path string
Method string
Body string
Fields []ApiRequestQueryParamField
QueryParams map[string]string
Requester *RequestClient
}
func (*ApiRequest) AddField ¶
func (request *ApiRequest) AddField(field ApiRequestQueryParamField) *ApiRequestQueryParamField
AddField adds a field to the request's "fields" query parameter and returns a pointer to the stored field, so filters added through it are sent.
Fields are comma separated, and filters are rendered as chained calls, e.g. fields=field1.filter1(value1).filter2(value2),field2
func (*ApiRequest) AddQueryParam ¶
func (request *ApiRequest) AddQueryParam(key, value string)
AddQueryParam adds a query parameter to the request.
func (*ApiRequest) Execute ¶
func (request *ApiRequest) Execute() (string, error)
Execute executes the request and returns the response body.
A non-2xx status yields a *GraphAPIError while still returning the body, so callers can both detect the failure and inspect Meta's error envelope.
func (*ApiRequest) ExecuteContext ¶ added in v0.8.1
func (request *ApiRequest) ExecuteContext(ctx context.Context) (string, error)
ExecuteContext is like Execute but carries ctx for cancellation and deadlines.
func (*ApiRequest) SetBody ¶
func (request *ApiRequest) SetBody(body string)
SetBody sets the body for the request.
func (*ApiRequest) SetMethod ¶
func (request *ApiRequest) SetMethod(method string)
SetMethod sets the method for the request.
type ApiRequestQueryParamField ¶
func (*ApiRequestQueryParamField) AddFilter ¶
func (field *ApiRequestQueryParamField) AddFilter(key, value string)
type GraphAPIError ¶ added in v0.8.0
type GraphAPIError struct {
StatusCode int // HTTP status code of the response.
Body string // Raw response body (never dropped).
Message string // error.message, when present.
Type string // error.type, when present.
Code int // error.code, when present.
Subcode int // error.error_subcode, when present.
FBTraceID string // error.fbtrace_id, for support/debugging.
}
GraphAPIError is returned when the Graph API responds with a non-2xx status. It carries the HTTP status, the raw response body, and the parsed fields from Meta's `{"error": {...}}` envelope when present. Callers can type-assert the error to inspect the status/code or decide on a retry.
func (*GraphAPIError) Error ¶ added in v0.8.0
func (e *GraphAPIError) Error() string
func (*GraphAPIError) IsRetryable ¶ added in v0.8.0
func (e *GraphAPIError) IsRetryable() bool
IsRetryable reports whether the error is worth retrying — rate limits (429) and transient server errors (>=500). Callers own any backoff policy.
type Options ¶ added in v0.8.1
type Options struct {
// HTTPClient is used for every request. Defaults to a shared client with
// dial/TLS/response-header timeouts (see DefaultResponseHeaderTimeout).
HTTPClient *http.Client
// ApiVersion is the Graph API version, e.g. "v21.0". Defaults to API_VERSION.
ApiVersion string
// BaseURL is the scheme and host of the Graph API, e.g.
// "https://graph.facebook.com". Mainly useful to point at an httptest
// server in tests. Defaults to REQUEST_PROTOCOL://BASE_URL.
BaseURL string
}
Options customises a RequestClient. Every field is optional; the zero value gives the historical defaults.
type RequestClient ¶
type RequestClient struct {
// contains filtered or unexported fields
}
RequestClient represents a client for making requests to a cloud API.
It is safe to copy and to use from multiple goroutines: all fields are read-only after construction and the *http.Client is shared.
func NewRequestClient ¶
func NewRequestClient(apiAccessToken string) *RequestClient
NewRequestClient creates a new instance of RequestClient.
func NewRequestClientWithOptions ¶ added in v0.8.1
func NewRequestClientWithOptions(apiAccessToken string, opts Options) *RequestClient
NewRequestClientWithOptions creates a RequestClient with custom options.
func (*RequestClient) ApiVersion ¶ added in v0.1.0
func (client *RequestClient) ApiVersion() string
func (*RequestClient) BaseUrl ¶ added in v0.1.0
func (client *RequestClient) BaseUrl() string
func (*RequestClient) NewApiRequest ¶
func (client *RequestClient) NewApiRequest(path, method string) *ApiRequest
func (*RequestClient) RequestMultipart ¶ added in v0.1.0
func (rc *RequestClient) RequestMultipart( method string, path string, body io.Reader, contentType string, ) (string, error)
RequestMultipart allows sending an arbitrary body with a custom Content-Type. This is needed for file uploads (multipart/form-data).
type RequestCloudApiParams ¶
type RequestCloudApiParams struct {
Body string
Path string
Method string
QueryParam map[string]string
}
RequestCloudApiParams represents the parameters for making a request to the cloud API.
type WhatsappApiType ¶
type WhatsappApiType string
const ( WhatsappApiTypeMessaging WhatsappApiType = "messaging" WhatsappApiTypeBusiness WhatsappApiType = "business" )