mws

package
v0.0.0-...-ecb25c3 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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",
	"A1AM78C64UM0Y8": "mws.amazonservices.com.mx",
	"A2VIGQ35RCS4UG": "mws.amazonservices.ae",
	"A1805IZSGTT6HS": "mws-eu.amazonservices.com",
	"A19VAU5U5O7RUS": "mws-fe.amazonservices.com",
	"A39IBJ37TRP1C6": "mws.amazonservices.com.au",
	"A17E79C6D8DWNP": "mws-eu.amazonservices.com",
	"A2NODRKZP88ZB9": "mws-eu.amazonservices.com",
	"A1C3SOZRARQ6R3": "mws-eu.amazonservices.com",
}

EndPoints a list of API endpoints by marketpalceID

View Source
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",
	"MX": "A1AM78C64UM0Y8",
	"AE": "A2VIGQ35RCS4UG",
	"NL": "A1805IZSGTT6HS",
	"SG": "A19VAU5U5O7RUS",
	"AU": "A39IBJ37TRP1C6",
	"SA": "A17E79C6D8DWNP",
	"SE": "A2NODRKZP88ZB9",
	"PL": "A1C3SOZRARQ6R3",
}

MarketPlaceIds a list of marketplace by region

Functions

func Base64EncodeStr

func Base64EncodeStr(src string) string

func Encoding

func Encoding(region string) string

Encoding get the ecoding for file upload and parsing TODO add encoding for JP.

func Inspect

func Inspect(value interface{})

Inspect print out the value in a user friendly way.

func Md5V

func Md5V(str string) string

func Md5V2

func Md5V2(str string) string

func SignV2

func SignV2(stringToSign string, secret string) string

SignV2 sign the message with the key by using hmac256.

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

func NewClient(config Config, version, name string) (*Client, error)

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

func (base Client) EndPoint() string

EndPoint generate the endpoint for the request by combinding the host and path.

func (Client) Path

func (base Client) Path() string

Path generate the url path for the api endpoint.

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

func (base Client) SignatureMethod() string

SignatureMethod return the HmacSHA256 signature method string.

func (Client) SignatureVersion

func (base Client) SignatureVersion() string

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

type Credential struct {
	AccessKey string
	SecretKey string
}

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

type MarketPlace struct {
	Region   string
	Id       string
	EndPoint string
}

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

type Response struct {
	*http.Response

	Error error
}

Response a custom http response with additional helper methods.

func NewResponse

func NewResponse(resp *http.Response) *Response

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) ExportTo

func (resp *Response) ExportTo(path string) error

ExportTo export the body to a file with path.

func (*Response) ResultParser

func (resp *Response) ResultParser() (*ResultParser, error)

ResultParser create a new node parser for response body.

func (*Response) WriteBodyTo

func (resp *Response) WriteBodyTo(out io.Writer) error

WriteBodyTo write the response body to the destination output.

type ResultParser

type ResultParser struct {
	*xmlParser.XMLNode
}

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.

type Values

type Values struct {
	url.Values
}

Values is a url.Values for custom encoding.

func NewValues

func NewValues() Values

NewValues initilize the Values struct with default value.

func (Values) Encode

func (params Values) Encode() string

Encode encode the parameters and replace '+' by '%20'.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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