Documentation
¶
Overview ¶
Package client provides an HTTP client for the Fizzy API.
Index ¶
- func ParsePage(nextURL string) string
- type API
- type APIResponse
- type Client
- func (c *Client) Delete(path string) (*APIResponse, error)
- func (c *Client) DownloadFile(urlPath string, destPath string) error
- func (c *Client) FollowLocation(location string) (*APIResponse, error)
- func (c *Client) Get(path string) (*APIResponse, error)
- func (c *Client) GetWithPagination(path string, fetchAll bool) (*APIResponse, error)
- func (c *Client) Patch(path string, body any) (*APIResponse, error)
- func (c *Client) PatchMultipart(path, fileField, filePath string, fields map[string]string) (*APIResponse, error)
- func (c *Client) Post(path string, body any) (*APIResponse, error)
- func (c *Client) Put(path string, body any) (*APIResponse, error)
- func (c *Client) UploadFile(filePath string) (*APIResponse, error)
- func (c *Client) UploadFileMultipart(path, fieldName, filePath string, extraFields map[string]string) (*APIResponse, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type API ¶
type API interface {
Get(path string) (*APIResponse, error)
Post(path string, body any) (*APIResponse, error)
Patch(path string, body any) (*APIResponse, error)
PatchMultipart(path, fileField, filePath string, fields map[string]string) (*APIResponse, error)
Put(path string, body any) (*APIResponse, error)
Delete(path string) (*APIResponse, error)
GetWithPagination(path string, fetchAll bool) (*APIResponse, error)
FollowLocation(location string) (*APIResponse, error)
UploadFile(filePath string) (*APIResponse, error)
DownloadFile(urlPath string, destPath string) error
}
API defines the interface for API operations. This allows for mocking in tests.
type APIResponse ¶
APIResponse represents a response from the API.
type Client ¶
type Client struct {
BaseURL string
Token string
Account string
HTTPClient *http.Client
Verbose bool
// Sleeper is called for retry delays. Defaults to time.Sleep.
// Override in tests with a no-op or recording function.
Sleeper func(time.Duration)
}
Client is an HTTP client for the Fizzy API.
func (*Client) Delete ¶
func (c *Client) Delete(path string) (*APIResponse, error)
Delete performs a DELETE request.
func (*Client) DownloadFile ¶
DownloadFile downloads a file from a URL (following redirects) and saves it to the specified path. The URL should be a relative path like /6085671/rails/active_storage/blobs/redirect/...
func (*Client) FollowLocation ¶
func (c *Client) FollowLocation(location string) (*APIResponse, error)
FollowLocation fetches the resource at the Location header.
func (*Client) Get ¶
func (c *Client) Get(path string) (*APIResponse, error)
Get performs a GET request.
func (*Client) GetWithPagination ¶
func (c *Client) GetWithPagination(path string, fetchAll bool) (*APIResponse, error)
GetWithPagination fetches all pages of a paginated endpoint.
func (*Client) Patch ¶
func (c *Client) Patch(path string, body any) (*APIResponse, error)
Patch performs a PATCH request with JSON body.
func (*Client) PatchMultipart ¶
func (c *Client) PatchMultipart(path, fileField, filePath string, fields map[string]string) (*APIResponse, error)
PatchMultipart performs a PATCH request with multipart form data.
func (*Client) Post ¶
func (c *Client) Post(path string, body any) (*APIResponse, error)
Post performs a POST request with JSON body.
func (*Client) Put ¶
func (c *Client) Put(path string, body any) (*APIResponse, error)
Put performs a PUT request with JSON body.
func (*Client) UploadFile ¶
func (c *Client) UploadFile(filePath string) (*APIResponse, error)
UploadFile uploads a file using the direct upload flow.
func (*Client) UploadFileMultipart ¶
func (c *Client) UploadFileMultipart(path, fieldName, filePath string, extraFields map[string]string) (*APIResponse, error)
UploadFileMultipart uploads a file using multipart form data.