appleads

package
v1.260716.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const BaseURL = "https://api.searchads.apple.com/api/"

Variables

This section is empty.

Functions

func GenerateClientSecret

func GenerateClientSecret(keyID, teamID, clientID string, privateKey *ecdsa.PrivateKey, now time.Time, lifetime time.Duration) (string, error)

GenerateClientSecret creates an Apple Ads OAuth client secret JWT.

func MaxPageLimit

func MaxPageLimit(spec EndpointSpec) int

MaxPageLimit returns the endpoint-specific maximum page size.

func RemoveAllCredentials

func RemoveAllCredentials() error

RemoveAllCredentials removes all Apple Ads credentials.

func RemoveCredentials

func RemoveCredentials(name string) error

RemoveCredentials removes one Apple Ads credential.

func SetDefaultCredentials

func SetDefaultCredentials(name string) error

SetDefaultCredentials switches the default Apple Ads profile.

func ShouldBypassKeychain

func ShouldBypassKeychain() bool

ShouldBypassKeychain reports whether Apple Ads keychain usage is disabled.

func StoreCredentials

func StoreCredentials(name string, credentials Credentials) error

StoreCredentials stores Apple Ads credentials in keychain when available.

func StoreCredentialsConfig

func StoreCredentialsConfig(name string, credentials Credentials) error

StoreCredentialsConfig stores Apple Ads credentials in the active config file.

func StoreCredentialsConfigAt

func StoreCredentialsConfigAt(name string, credentials Credentials, path string) error

StoreCredentialsConfigAt stores Apple Ads credentials in a specific config file.

Types

type APIError

type APIError struct {
	StatusCode  int
	Field       string
	Message     string
	MessageCode string
	Detail      string
}

APIError describes an Apple Ads API error response.

func (*APIError) Error

func (e *APIError) Error() string

func (*APIError) HTTPStatusCode added in v1.260713.0

func (e *APIError) HTTPStatusCode() int

type BodyKind

type BodyKind string

BodyKind describes the JSON body shape accepted by an Apple Ads endpoint.

const (
	BodyNone   BodyKind = ""
	BodyObject BodyKind = "object"
	BodyArray  BodyKind = "array"
)

type Client

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

Client is an Apple Ads Campaign Management API client.

func NewClient

func NewClient(credentials Credentials, opts ...ClientOption) (*Client, error)

NewClient constructs an Apple Ads API client.

func (*Client) AccessToken

func (c *Client) AccessToken(ctx context.Context) (string, error)

AccessToken returns a bearer token for diagnostics and auth token commands.

func (*Client) Do

func (c *Client) Do(ctx context.Context, spec EndpointSpec, pathParams map[string]string, query url.Values, body json.RawMessage) (RawResponse, error)

Do executes a documented Apple Ads endpoint.

func (*Client) PaginateAll

func (c *Client) PaginateAll(ctx context.Context, spec EndpointSpec, pathParams map[string]string, query url.Values, startOffset, pageSize int, body json.RawMessage) (RawResponse, error)

PaginateAll fetches all pages for an offset-paginated endpoint.

func (*Client) Request

func (c *Client) Request(ctx context.Context, method, path string, query url.Values, body json.RawMessage, requiresOrg bool) (RawResponse, error)

Request executes an Apple Ads API request for a relative v5 path.

type ClientOption

type ClientOption func(*Client)

ClientOption configures a Client.

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL configures the Apple Ads API base URL.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient configures the HTTP client.

func WithNow

func WithNow(now func() time.Time) ClientOption

WithNow configures the clock used by token caching.

func WithTokenURL

func WithTokenURL(tokenURL string) ClientOption

WithTokenURL configures the OAuth token URL.

type Credentials

type Credentials struct {
	ClientID       string
	TeamID         string
	KeyID          string
	PrivateKeyPath string
	PrivateKeyPEM  string
	AccessToken    string
	OrgID          string
	Profile        string
}

Credentials contains resolved Apple Ads authentication inputs.

func GetCredentialsWithSource

func GetCredentialsWithSource(profile string) (Credentials, string, error)

GetCredentialsWithSource resolves Apple Ads credentials by profile.

type EndpointSpec

type EndpointSpec struct {
	Name             string
	Method           string
	Path             string
	CommandPath      []string
	BodyKind         BodyKind
	BodyType         string
	ResponseType     string
	RequiresOrg      bool
	RequiresConfirm  bool
	PathParams       []ParamSpec
	QueryParams      []ParamSpec
	SupportsPaginate bool
	DefaultListAlias bool
}

EndpointSpec is the single source of truth for the Apple Ads command and client surface.

func EndpointByCommandPath

func EndpointByCommandPath(path ...string) (EndpointSpec, bool)

EndpointByCommandPath returns a spec by command path.

func EndpointSpecs

func EndpointSpecs() []EndpointSpec

EndpointSpecs returns the current Apple Ads Campaign Management API v5 surface.

type PageDetail

type PageDetail struct {
	ItemsPerPage int `json:"itemsPerPage"`
	StartIndex   int `json:"startIndex"`
	TotalResults int `json:"totalResults"`
}

PageDetail is the Apple Ads offset pagination envelope.

type ParamSpec

type ParamSpec struct {
	Name     string
	Flag     string
	Type     ParamType
	Required bool
	Max      int
	Allowed  []string
}

ParamSpec describes a documented Apple Ads path or query parameter.

type ParamType

type ParamType string

ParamType describes the primitive type of a path or query parameter.

const (
	ParamString ParamType = "string"
	ParamInt    ParamType = "int"
	ParamBool   ParamType = "bool"
)

type RawResponse

type RawResponse json.RawMessage

RawResponse preserves the Apple Ads response envelope.

func (RawResponse) MarshalJSON

func (r RawResponse) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler.

type StoredCredential

type StoredCredential struct {
	Credentials
	Name       string
	IsDefault  bool
	Source     string
	SourcePath string
}

StoredCredential is an Apple Ads credential with storage metadata.

func ListCredentials

func ListCredentials() ([]StoredCredential, error)

ListCredentials lists Apple Ads credentials.

Jump to

Keyboard shortcuts

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