customerapi

package
v0.1.7-alpha.6 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package customerapi provides an authenticated HTTP client for the XenForo Customer API.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAPIError indicates the API returned an error response.
	ErrAPIError = errors.New("API error")

	// ErrAuthExpired indicates the authentication token has expired.
	ErrAuthExpired = errors.New("authentication expired")
)

Functions

func CheckResponse

func CheckResponse(resp *http.Response) error

CheckResponse checks if an HTTP response indicates an error and returns a formatted error.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is an authenticated HTTP client for the XenForo Customer API.

func NewClient

func NewClient() (*Client, error)

NewClient creates a new API client with authentication.

func (*Client) Do

func (c *Client) Do(ctx context.Context, method, path string, body io.Reader) (*http.Response, error)

Do sends an HTTP request and returns the response.

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string) (*http.Response, error)

Get sends a GET request.

func (*Client) GetAccessToken

func (c *Client) GetAccessToken() (string, error)

GetAccessToken retrieves the current access token.

func (*Client) GetDownloadInfo

func (c *Client) GetDownloadInfo(ctx context.Context, licenseKey string, downloadID string, versionID int) (*DownloadInfo, error)

GetDownloadInfo retrieves download information for a specific version.

func (*Client) GetDownloadURL

func (c *Client) GetDownloadURL(licenseKey string, downloadID string, versionID int) string

GetDownloadURL returns the URL to download a specific version.

func (*Client) GetJSON

func (c *Client) GetJSON(ctx context.Context, path string, result any) error

GetJSON performs a GET request and decodes the JSON response into result.

func (*Client) GetLicenseDownloadables

func (c *Client) GetLicenseDownloadables(ctx context.Context, licenseKey string) (*LicenseDownloadables, error)

GetLicenseDownloadables retrieves the downloadable products for a license.

func (*Client) GetLicenseVersions

func (c *Client) GetLicenseVersions(ctx context.Context, licenseKey string, downloadID string) (*LicenseVersions, error)

GetLicenseVersions retrieves the available versions for a product.

func (*Client) GetLicenses

func (c *Client) GetLicenses(ctx context.Context) ([]License, error)

GetLicenses retrieves all licenses for the authenticated user.

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, body io.Reader) (*http.Response, error)

Post sends a POST request.

func (*Client) PostJSON

func (c *Client) PostJSON(ctx context.Context, path string, body []byte) (*http.Response, error)

PostJSON sends a POST request with JSON body.

type DownloadInfo

type DownloadInfo struct {
	LicenseKey    string `json:"license_key"`
	DownloadID    string `json:"download_id"`
	VersionID     int    `json:"version_id"`
	VersionString string `json:"version_string"`
	Filename      string `json:"filename"`
	DownloadURL   string `json:"download_url"`
}

DownloadInfo represents information about a downloadable file.

type DownloadInfoResponse

type DownloadInfoResponse struct {
	Download DownloadInfo `json:"download"`
}

DownloadInfoResponse is the API response for download information.

type Downloadable

type Downloadable struct {
	DownloadID string `json:"download_id"`
	Title      string `json:"title"`
}

Downloadable represents a downloadable product associated with a license.

type Error

type Error struct {
	Code    string         `json:"code"`
	Message string         `json:"message"`
	Params  map[string]any `json:"params,omitempty"`
}

Error represents an error response from the API.

type ErrorResponse

type ErrorResponse struct {
	Errors []Error `json:"errors"`
}

ErrorResponse represents the error response structure from XenForo API.

func ParseError

func ParseError(body []byte) (*ErrorResponse, error)

ParseError parses an API error response.

type License

type License struct {
	LicenseID      int            `json:"license_id"`
	LicenseKey     string         `json:"license_key"`
	ProductID      string         `json:"product_id"`
	ProductTitle   string         `json:"product_title"`
	IsValid        bool           `json:"is_valid"`
	IsActive       bool           `json:"is_active"`
	StartDate      UnixTime       `json:"start_date"`
	ExpirationDate UnixTime       `json:"expiration_date"`
	SiteURL        string         `json:"site_url,omitempty"`
	SiteTitle      string         `json:"site_title,omitempty"`
	CanDownload    bool           `json:"can_download"`
	Extras         []LicenseExtra `json:"extras,omitempty"`
}

License represents a XenForo customer license.

type LicenseDownloadables

type LicenseDownloadables struct {
	LicenseKey    string         `json:"license_key"`
	Downloadables []Downloadable `json:"downloadables"`
}

LicenseDownloadables represents the downloadables available for a license.

type LicenseExtra

type LicenseExtra struct {
	ExtraID        string   `json:"extra_id"`
	Name           string   `json:"name"`
	StartDate      UnixTime `json:"start_date"`
	IsDownloadable bool     `json:"is_downloadable"`
}

LicenseExtra represents an extra (add-on product) associated with a license.

type LicenseVersions

type LicenseVersions struct {
	LicenseKey string    `json:"license_key"`
	DownloadID string    `json:"download_id"`
	Versions   []Version `json:"versions"`
}

LicenseVersions represents the versions available for a license/download.

type LicensesResponse

type LicensesResponse struct {
	Licenses []License `json:"licenses"`
}

LicensesResponse represents the API response for listing licenses.

type UnixTime

type UnixTime struct {
	time.Time
}

UnixTime is a time.Time that unmarshals from Unix timestamps.

func (*UnixTime) UnmarshalJSON

func (t *UnixTime) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals a Unix timestamp or RFC3339 string into a UnixTime.

type Version

type Version struct {
	VersionID   int      `json:"version_id"`
	VersionStr  string   `json:"version_string"`
	ReleaseDate UnixTime `json:"release_date"`
	Stable      bool     `json:"stable"`
}

Version represents a downloadable version.

Jump to

Keyboard shortcuts

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