Documentation
¶
Overview ¶
Package paapi5 APIs for Amazon Product Advertising API v5 client
Index ¶
- Constants
- func AuthEndpointFor(version string) string
- type Client
- type ClientOptFunc
- type Error
- type Marketplace
- type MarketplaceEnum
- type Operation
- type Query
- type Server
- func (s *Server) AWS4Request() stringdeprecated
- func (s *Server) Accept() string
- func (s *Server) AcceptLanguage() string
- func (s *Server) AuthEndpoint() string
- func (s *Server) ContentEncoding() stringdeprecated
- func (s *Server) ContentType() string
- func (s *Server) CreateClient(associateTag, credentialID, credentialSecret string, opts ...ClientOptFunc) Client
- func (s *Server) CredentialVersion() string
- func (s *Server) HMACAlgorithm() stringdeprecated
- func (s *Server) HostName() string
- func (s *Server) Marketplace() string
- func (s *Server) Region() stringdeprecated
- func (s *Server) ServiceName() stringdeprecated
- func (s *Server) URL(path string) *url.URL
- type ServerOptFunc
- type TimeStamp
Examples ¶
Constants ¶
const ( CredentialVersionNA = "2.1" // North America — Cognito pool (legacy) CredentialVersionEU = "2.2" // Europe / Middle East / India — Cognito CredentialVersionFE = "2.3" // Far East — Cognito CredentialVersionNAv3 = "3.1" // North America — Login with Amazon CredentialVersionEUv3 = "3.2" // Europe / Middle East / India — LwA CredentialVersionFEv3 = "3.3" // Far East — LwA )
Credential version codes for the Amazon Creators API.
v2.x values select the regional Cognito (`…amazoncognito.com/oauth2/token`) token endpoint and require `Authorization: Bearer <token>, Version <v>` on catalog requests.
v3.x values select the regional Login with Amazon (`api.amazon…/auth/o2/token`) endpoint; tokens are obtained with HTTP Basic auth and scope `creatorsapi::default`, and catalog requests use `Authorization: Bearer <token>` without a Version suffix.
Variables ¶
This section is empty.
Functions ¶
func AuthEndpointFor ¶ added in v0.16.0
AuthEndpointFor returns the default OAuth2 token endpoint URL for the given credential version. Returns the empty string for unknown versions.
Types ¶
type Client ¶
type Client interface {
Marketplace() string
PartnerTag() string
PartnerType() string
Request(Query) ([]byte, error)
RequestContext(context.Context, Query) ([]byte, error)
}
Client interface
Example ¶
package main
import (
"context"
"fmt"
"net/http"
paapi5 "github.com/goark/pa-api"
)
func main() {
//Create client for Japan marketplace
client := paapi5.New(
paapi5.WithMarketplace(paapi5.LocaleJapan),
).CreateClient(
"mytag-20",
"CRED-ID",
"CRED-SECRET",
paapi5.WithContext(context.Background()),
paapi5.WithHttpClient(http.DefaultClient),
)
fmt.Println("Marketplace:", client.Marketplace())
}
Output: Marketplace: www.amazon.co.jp
func DefaultClient ¶
DefaultClient function returns a default Client instance using the supplied associate tag and Creators API credential pair.
Example ¶
package main
import (
"fmt"
paapi5 "github.com/goark/pa-api"
)
func main() {
client := paapi5.DefaultClient("mytag-20", "CRED-ID", "CRED-SECRET") //Create default client
fmt.Println("Marketplace:", client.Marketplace())
}
Output: Marketplace: www.amazon.com
type ClientOptFunc ¶
type ClientOptFunc func(*client)
ClientOptFunc type is self-referential function type for Server.CreateClient method. (functional options pattern)
func WithAuthEndpoint ¶ added in v0.16.0
func WithAuthEndpoint(endpoint string) ClientOptFunc
WithAuthEndpoint overrides the OAuth2 token endpoint. Defaults to the token endpoint resolved from the credential version (or LWA for v3.x).
func WithContext
deprecated
func WithContext(ctx context.Context) ClientOptFunc
WithContext is retained as a no-op for backward compatibility. Pass a context to RequestContext instead.
Deprecated: this option does nothing.
func WithCredentialVersion ¶ added in v0.16.0
func WithCredentialVersion(version string) ClientOptFunc
WithCredentialVersion overrides the credential version derived from the marketplace. Use this when your Creators API credential set was issued for a different region than the configured marketplace would imply.
func WithHttpClient ¶
func WithHttpClient(hc *http.Client) ClientOptFunc
WithHttpClient function returns a ClientOptFunc that configures the underlying http.Client used for both API and OAuth2 token requests.
type Marketplace ¶
Marketplace is the interface implemented by locale providers.
Note: this interface is deliberately kept compatible with the pre-Creators API contract. The Creators API credential version is reported via the optional credentialVersioner type-assertion (satisfied by MarketplaceEnum) rather than added to this interface, so external implementations of Marketplace continue to compile unchanged.
func MarketplaceOf ¶
func MarketplaceOf(s string) Marketplace
MarketplaceOf function returns Marketplace instance from service domain.
type MarketplaceEnum ¶
type MarketplaceEnum int
MarketplaceEnum is enumeration of locale information.
const ( LocaleUnknown MarketplaceEnum = iota //Unknown local LocaleAustralia //Australia LocaleBrazil //Brazil LocaleCanada //Canada LocaleEgypt //Egypt LocaleFrance //France LocaleGermany //Germany LocaleIndia //India LocaleIreland //Ireland LocaleItaly //Italy LocaleJapan //Japan LocaleMexico //Mexico LocaleNetherlands //Netherlands LocalePoland //Poland LocaleSingapore //Singapore LocaleSaudiArabia //SaudiArabia LocaleSpain //Spain LocaleSweden //Sweden LocaleTurkey //Turkey LocaleUnitedArabEmirates //United Arab Emirates LocaleUnitedKingdom //United Kingdom LocaleUnitedStates //United States DefaultMarketplace = LocaleUnitedStates )
func (MarketplaceEnum) CredentialVersion ¶ added in v0.16.0
func (m MarketplaceEnum) CredentialVersion() string
CredentialVersion returns the Creators API credential version code that must be paired with credentials used to call this marketplace.
func (MarketplaceEnum) HostName ¶
func (m MarketplaceEnum) HostName() string
HostName returns the Creators API service host. The host is the same for every marketplace; the marketplace itself is communicated via the `x-marketplace` request header.
func (MarketplaceEnum) Language ¶
func (m MarketplaceEnum) Language() string
Language returns language name of Marketplace.
func (MarketplaceEnum) Region
deprecated
func (m MarketplaceEnum) Region() string
Region returns the historical AWS region associated with this marketplace.
Deprecated: the Creators API does not use AWS SigV4 signing; this value is no longer used for request construction. Use CredentialVersion() to choose the right Creators API credential set instead.
func (MarketplaceEnum) String ¶
func (m MarketplaceEnum) String() string
String returns marketplace name of Marketplace.
type Operation ¶
type Operation int
Operation is enumeration of Creators API operations.
func (Operation) MarshalJSON ¶
MarshalJSON method implements the json.Marshaler interface.
func (Operation) Target
deprecated
Target returns the value historically used for the X-Amz-Target header under PA-API v5 SigV4 signing.
Deprecated: the Creators API does not use the X-Amz-Target header (the operation is selected via URL path; see Path). This method returns the historical PA-API v5 value for back-compat callers only and will be removed in a future major version.
func (*Operation) UnmarshalJSON ¶
UnmarshalJSON method implements json.Unmarshaler interface.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server type is a configuration of the Amazon Creators API service.
Example ¶
package main
import (
"fmt"
paapi5 "github.com/goark/pa-api"
)
func main() {
sv := paapi5.New() //Create default server
fmt.Println("Marketplace:", sv.Marketplace())
fmt.Println("Region:", sv.Region())
fmt.Println("AcceptLanguage:", sv.AcceptLanguage())
fmt.Println("CredentialVersion:", sv.CredentialVersion())
fmt.Println("URL:", sv.URL(paapi5.GetItems.Path()))
}
Output: Marketplace: www.amazon.com Region: us-east-1 AcceptLanguage: en_US CredentialVersion: 3.1 URL: https://creatorsapi.amazon/catalog/v1/getItems
func New ¶
func New(opts ...ServerOptFunc) *Server
New function returns a Server instance with options.
Example ¶
package main
import (
"fmt"
paapi5 "github.com/goark/pa-api"
)
func main() {
sv := paapi5.New(paapi5.WithMarketplace(paapi5.LocaleJapan)) //Create server in Japan region
fmt.Println("Marketplace:", sv.Marketplace())
fmt.Println("Region:", sv.Region())
fmt.Println("AcceptLanguage:", sv.AcceptLanguage())
fmt.Println("CredentialVersion:", sv.CredentialVersion())
fmt.Println("URL:", sv.URL(paapi5.GetItems.Path()))
}
Output: Marketplace: www.amazon.co.jp Region: us-west-2 AcceptLanguage: ja_JP CredentialVersion: 3.3 URL: https://creatorsapi.amazon/catalog/v1/getItems
func (*Server) AWS4Request
deprecated
AWS4Request returns the AWS4 request token used by PA-API v5's SigV4 signing.
Deprecated: the Creators API does not use AWS SigV4 signing. This method returns the historical PA-API v5 value for back-compat callers only and will be removed in a future major version.
func (*Server) AcceptLanguage ¶
AcceptLanguage method returns the Accept-Language parameter for API calls.
func (*Server) AuthEndpoint ¶ added in v0.16.0
AuthEndpoint returns the configured (or version-derived) OAuth2 token endpoint URL.
func (*Server) ContentEncoding
deprecated
ContentEncoding returns the Content-Encoding header value used by PA-API v5.
Deprecated: the Creators API does not use a Content-Encoding header. This method returns the historical PA-API v5 value for back-compat callers only and will be removed in a future major version.
func (*Server) ContentType ¶
ContentType method returns the Content-Type header value for API calls.
func (*Server) CreateClient ¶
func (s *Server) CreateClient(associateTag, credentialID, credentialSecret string, opts ...ClientOptFunc) Client
CreateClient method returns a Client instance with the supplied associate (partner) tag and Amazon Creators API credential pair.
credentialID and credentialSecret correspond to the Credential ID and Credential Secret issued in Associates Central > Tools > Creators API.
func (*Server) CredentialVersion ¶ added in v0.16.0
CredentialVersion returns the Creators API credential version that matches the configured marketplace's region group. When the configured Marketplace implementation does not expose CredentialVersion(), the default North America version is returned.
func (*Server) HMACAlgorithm
deprecated
HMACAlgorithm returns the HMAC algorithm string used by PA-API v5's SigV4 signing.
Deprecated: the Creators API does not use AWS SigV4 signing. This method returns the historical PA-API v5 value for back-compat callers only and will be removed in a future major version.
func (*Server) Marketplace ¶
Marketplace method returns the marketplace name.
func (*Server) ServiceName
deprecated
ServiceName returns the AWS service name used by PA-API v5's SigV4 signing.
Deprecated: the Creators API does not use AWS SigV4 signing. This method returns the historical PA-API v5 value for back-compat callers only and will be removed in a future major version.
type ServerOptFunc ¶
type ServerOptFunc func(*Server)
ServerOptFunc type is self-referential function type for New functions. (functional options pattern)
func WithLanguage ¶
func WithLanguage(language string) ServerOptFunc
WithLanguage function returns a ServerOptFunc that sets the desired response language. The Creators API does not honour an Accept-Language header; the value is forwarded for back-compat but callers should also use the LanguagesOfPreference body field for the same purpose.
func WithMarketplace ¶
func WithMarketplace(marketplace Marketplace) ServerOptFunc
WithMarketplace function returns a ServerOptFunc that sets the Marketplace.
func WithServerAuthEndpoint ¶ added in v0.16.0
func WithServerAuthEndpoint(endpoint string) ServerOptFunc
WithServerAuthEndpoint overrides the OAuth2 token endpoint resolved from the credential version. Primarily useful for tests.
func WithServerHost ¶ added in v0.16.0
func WithServerHost(host string) ServerOptFunc
WithServerHost overrides the API service host. Useful for tests pointing at httptest.Server. Pass an empty string to fall back to the default.
func WithServerScheme ¶ added in v0.16.0
func WithServerScheme(scheme string) ServerOptFunc
WithServerScheme overrides the URL scheme used by the API host. Useful for tests that need plain HTTP.
type TimeStamp ¶
TimeStamp is wrapper class of time.Time
func NewTimeStamp ¶
NewTimeStamp returns TimeStamp instance