client

package
v0.0.0-...-e6ecba1 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package client provides an HTTP client for the Fizzy API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParsePage

func ParsePage(nextURL string) string

ParsePage extracts page number from a URL query string.

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

type APIResponse struct {
	StatusCode int
	Body       []byte
	Location   string
	LinkNext   string
	Data       any
}

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 New

func New(baseURL, token, account string) *Client

New creates a new API client.

func (*Client) Delete

func (c *Client) Delete(path string) (*APIResponse, error)

Delete performs a DELETE request.

func (*Client) DownloadFile

func (c *Client) DownloadFile(urlPath string, destPath string) error

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.

Jump to

Keyboard shortcuts

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