Documentation
¶
Overview ¶
Package api is a thin, secret-safe client for the Seznam Webmaster REST API.
The API authenticates with a `key` query parameter, so the key is part of every request URL. This package therefore never lets a URL escape: transport errors are stripped of it, trace output is redacted, redirects are not followed and the base URL is restricted to the official host or loopback.
Index ¶
Constants ¶
const AllowAnyBaseURLEnv = "SZWM_INSECURE_ALLOW_ANY_BASE_URL"
AllowAnyBaseURLEnv opts out of the base URL host restriction.
const DefaultBaseURL = "https://reporter.seznam.cz/wm-api"
DefaultBaseURL is the production endpoint. The swagger.json `basePath` (/wm-api/wm-api) is wrong: the working prefix is a single /wm-api.
const KeyURL = "https://reporter.seznam.cz/wm/web/api-klic"
KeyURL is where a user finds the API key of the selected site.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode parses a JSON body keeping integers exact and unknown fields intact. szwm passes unknown fields through because the API already returns more than its schema documents.
func MissingKeyError ¶
MissingKeyError is the error for a call that needs a key but has none.
func ValidateBaseURL ¶
ValidateBaseURL allows only the official host or loopback. An agent tricked into passing another host would otherwise hand the API key to that host.
func ValidatePath ¶
ValidatePath keeps a caller-supplied path on the API host.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to the Webmaster API.
type Options ¶
type Options struct {
BaseURL string
Key string
Timeout time.Duration
Retries int
UserAgent string
Limiter Limiter
Trace io.Writer
HTTPClient *http.Client
// Sleep is replaceable so tests do not wait for real backoff.
Sleep func(ctx context.Context, d time.Duration) error
}
Options configure a Client.
type Request ¶
Request describes one API call. The API key is added automatically unless NoAuth is set.