Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var EndPoints = map[string]string{
"A2EUQ1WTGCTBG2": "mws.amazonservices.ca",
"ATVPDKIKX0DER": "mws.amazonservices.com",
"A1PA6795UKMFR9": "mws-eu.amazonservices.com",
"A1RKKUPIHCS9HS": "mws-eu.amazonservices.com",
"A13V1IB3VIYZZH": "mws-eu.amazonservices.com",
"A21TJRUUN4KGV": "mws.amazonservices.in",
"APJ6JRA9NG5V4": "mws-eu.amazonservices.com",
"A1F83G8C2ARO7P": "mws-eu.amazonservices.com",
"A1VC38T7YXB528": "mws.amazonservices.jp",
"AAHKV2X7AFYLW": "mws.amazonservices.com.cn",
}
EndPoints a list of API endpoints by marketpalceID
var MarketPlaceIds = map[string]string{
"CA": "A2EUQ1WTGCTBG2",
"US": "ATVPDKIKX0DER",
"DE": "A1PA6795UKMFR9",
"ES": "A1RKKUPIHCS9HS",
"FR": "A13V1IB3VIYZZH",
"IN": "A21TJRUUN4KGV",
"IT": "APJ6JRA9NG5V4",
"UK": "A1F83G8C2ARO7P",
"JP": "A1VC38T7YXB528",
"CN": "AAHKV2X7AFYLW",
}
MarketPlaceIds a list of marketplace by region
Functions ¶
Types ¶
type APIClient ¶
type APIClient interface { Version() string Name() string NewClient(config Config) (APIClient, error) GetServiceStatus() (*Response, error) }
APIClient the interface for API clients.
type Client ¶
type Client struct { // The api host for the region. Host string // Region of the marketplace in two character. Region string // Marketplace identitier for the region. MarketPlaceId string // The API version. Version string // The API name. Name string // Seller's Amazon id. SellerId string // Auth token for developer to use the API. AuthToken string *http.Client // contains filtered or unexported fields }
Client the basic client handle request send to API endpoint.
func NewClient ¶
NewClient create a new mws base client. Config is the configuration struct.
Contains value for: SellerId, AuthToken, Region, and optional credential.
If region is not set in config, will be default to US.
func (Client) EndPoint ¶
EndPoint generate the endpoint for the request by combinding the host and path.
func (Client) SendRequest ¶
func (base Client) SendRequest(structuredParams Parameters) (*Response, error)
SendRequest accept a structured params and send the request to the API.
func (Client) SignatureMethod ¶
SignatureMethod return the HmacSHA256 signature method string.
func (Client) SignatureVersion ¶
SignatureVersion return version 2.
type Config ¶
type Config struct { SellerId string AuthToken string Region string AccessKey string SecretKey string }
Config is configuraton to create the gomws base. AccessKey and SecretKey are optional, bette to set them in evn variables.
func (Config) Credential ¶
func (config Config) Credential() Credential
Credential return credential either from value set in config or load from env variables.
type Credential ¶
Credential the credential to access the API.
func GetCredential ¶
func GetCredential() Credential
GetCredential get the credential from evn variables.
type Error ¶
type Error struct { // Error type. Values: Sender, Server. Type string `json:"Type"` // Amazon error code. Code string `json:"Code"` // Text explain the error. Message string `json:"Message"` // Detail about the error. Detail string `json:"Detail"` }
Error represents the error message from the API.
type MarketPlace ¶
MarketPlace contains region, id, and enpoint for the marketpalce.
func NewMarketPlace ¶
func NewMarketPlace(region string) (*MarketPlace, error)
NewMarketPlace create a new marketplace base on the region.
func (*MarketPlace) MarketPlaceEndPoint ¶
func (mp *MarketPlace) MarketPlaceEndPoint() (string, error)
MarketPlaceEndPoint get the MWS end point for the region.
func (*MarketPlace) MarketPlaceId ¶
func (mp *MarketPlace) MarketPlaceId() (string, error)
MarketPlaceId get the marketpalce id for the region.
type MarketPlaceError ¶
type MarketPlaceError struct {
// contains filtered or unexported fields
}
MarketPlaceError for marketplace. There are two type of errors: marketplace id error and region error.
func (MarketPlaceError) Error ¶
func (e MarketPlaceError) Error() string
type Parameters ¶
type Parameters map[string]interface{}
Parameters is the parameters pass to the gomws API.
func OptionalParams ¶
func OptionalParams(acceptKeys []string, ops []Parameters) Parameters
OptionalParams get the values from the pass in parameters. Only values for keys that are accepted will be returned.
Note: The keys returned will be in title case.
If the key appear in mulit parameters, later one will override the previous. Ex:
ps := []Parameters{ {"key1": "value1", "key2": "value2"}, {"key1": "newValue1", "key3": "value3"}, } acceptKeys := []string{"key1", "key2"} resultParams := OptionalParams(acceptKeys, ps)
result:
resultParams -> {"Key1": "newValue1", "Key2": "value2"}
func (Parameters) Merge ¶
func (params Parameters) Merge(parameters Parameters) Parameters
Merge merge the target Parameters to current Parameters.
func (Parameters) Normalize ¶
func (params Parameters) Normalize() (Values, error)
Normalize convert all the values to string, if a value can't not convert to string, an error will be returned. Float will round to 2 decimal precision.
func (Parameters) StructureKeys ¶
func (params Parameters) StructureKeys(baseKey string, keys ...string) Parameters
StructureKeys structure the keys for the parameters. The basekey is the key for the current parameters. keys are the string to augument the base key.
If the value is a slice, then additonal index will be used to augument the keys. Ex:
p := Parameters{ "slice": []string{"a", "b"}, } p.StructureKeys("slice", "fields")
result:
Parameters{ "slice.fields.1": "a", "slice.fields.2": "a", }
If the value is another Parameters, the Parameters' keys will used to augument. the keys Ex:
p := Parameters{ "params": Parameters{"a": 1, "b": 2}, } p.StructureKeys("params", "fields")
result:
Parameters{ "params.fields.a": 1, "params.fields.b": 2, }
If the value is other type, other keys will be used to structure the keys.
type Response ¶
Response a custom http response with additional helper methods.
func NewResponse ¶
NewResponse return a new mws response.
func (*Response) Close ¶
func (resp *Response) Close()
Close make sure the body drained, and then close the connection to make the connection can be resue.
func (*Response) ResultParser ¶
func (resp *Response) ResultParser() (*ResultParser, error)
ResultParser create a new node parser for response body.
type ResultParser ¶
ResultParser a wrapper of xml parser to add some helper methods.
func NewResultParser ¶
func NewResultParser(data []byte) (*ResultParser, error)
NewResultParser create a new result parser.
func (*ResultParser) GetMWSErrors ¶
func (rp *ResultParser) GetMWSErrors() ([]Error, error)
GetMWSErrors will return an array of Error struct from the xml node tree.
func (*ResultParser) HasErrorNodes ¶
func (rp *ResultParser) HasErrorNodes() bool
HasErrorNodes will check whether or not the xml node tree has any erorr node. If it contains errors, true will be returned.