paapi5

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

README

pa-api -- APIs for Amazon Product Advertising API v5 by Golang

Build Status GitHub license GitHub release

Example

package main

import (
    "fmt"

    paapi5 "github.com/spiegel-im-spiegel/pa-api"
    "github.com/spiegel-im-spiegel/pa-api/entity"
    "github.com/spiegel-im-spiegel/pa-api/query"
)

func main() {
    //Create client
    client := paapi5.DefaultClient("mytag-20", "AKIAIOSFODNN7EXAMPLE", "1234567890")

    //Make query
    q := query.NewGetItems(
        client.Marketplace(),
        client.PartnerTag(),
        client.PartnerType(),
    ).ASINs([]string{"B07YCM5K55"}).EnableImages(true).EnableParentASIN(true)

    //Requet and response
    body, err := client.Request(q)
    if err != nil {
        fmt.Printf("%+v\n", err)
        return
    }
    //io.Copy(os.Stdout, bytes.NewReader(body))

    //Decode JSON
    res, err := entity.DecodeResponse(body)
    if err != nil {
        fmt.Printf("%+v\n", err)
        return
    }
    fmt.Println(res.String())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is http.Client for Aozora API Server

func DefaultClient

func DefaultClient(associateTag, accessKey, secretKey string) *Client

DefaultClient returns new Client instance with default setting

func (*Client) Marketplace

func (c *Client) Marketplace() string

Marketplace returns name of Marketplace parameter for PA-API v5

func (*Client) PartnerTag

func (c *Client) PartnerTag() string

PartnerTag returns PartnerTag parameter for PA-API v5

func (*Client) PartnerType

func (c *Client) PartnerType() string

PartnerType returns PartnerType parameter for PA-API v5

func (*Client) Request

func (c *Client) Request(q Query) ([]byte, error)

type ClientOptFunc added in v0.2.0

type ClientOptFunc func(*Client)

ClientOptFunc is self-referential function for functional options pattern

func WithContext added in v0.2.0

func WithContext(ctx context.Context) ClientOptFunc

WithContext returns function for setting context.Context

func WithHttpCilent added in v0.2.0

func WithHttpCilent(client *http.Client) ClientOptFunc

WithHttpCilent returns function for setting http.Client

type Error

type Error int

Error is error codes for books-data

const (
	ErrNullPointer Error = iota + 1
	ErrHTTPStatus
	ErrNoData
)

func (Error) Error

func (e Error) Error() string

type Operation

type Operation int

Operation is represent PA-API operation

const (
	NullOperation Operation = iota
	GetVariations
	GetItems
	SearchItems
)

func (Operation) MarshalJSON

func (c Operation) MarshalJSON() ([]byte, error)

MarshalJSON returns time string with RFC3339 format

func (Operation) Path

func (c Operation) Path() string

Path returns URL path for PA-API command

func (Operation) String

func (c Operation) String() string

Stringer interface

func (Operation) Target

func (c Operation) Target() string

Target returns taget name for PA-API command

func (*Operation) UnmarshalJSON

func (c *Operation) UnmarshalJSON(b []byte) error

UnmarshalJSON returns result of Unmarshal for json.Unmarshal()

type Query

type Query interface {
	Operation() Operation
	Payload() ([]byte, error)
}

Query interface for Client type

type Server

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

Server is informations of Aozora API

func New

func New(opts ...ServerOptFunc) *Server

New returns new Server instance

func (*Server) AWS4Request

func (s *Server) AWS4Request() string

AWS4Request returns AWS4Request parameter for PA-API v5

func (*Server) Accept

func (s *Server) Accept() string

Accept returns Accept parameter for PA-API v5

func (*Server) AcceptLanguage

func (s *Server) AcceptLanguage() string

AcceptLanguage returns Accept-Language parameter for PA-API v5

func (*Server) ContentEncoding

func (s *Server) ContentEncoding() string

ContentEncoding returns Content-Encoding parameter for PA-API v5

func (*Server) ContentType

func (s *Server) ContentType() string

ContentType returns Content-Type parameter for PA-API v5

func (*Server) CreateClient

func (s *Server) CreateClient(associateTag, accessKey, secretKey string, opts ...ClientOptFunc) *Client

CreateClient returns new Client instance

func (*Server) HMACAlgorithm

func (s *Server) HMACAlgorithm() string

HMACAlgorithm returns HMAC-Algorithm parameter for PA-API v5

func (*Server) HostName

func (s *Server) HostName() string

HostName returns host name for PA-API v5

func (*Server) Marketplace

func (s *Server) Marketplace() string

Marketplace returns name of Marketplace parameter for PA-API v5

func (*Server) Region

func (s *Server) Region() string

Region returns Region parameter for PA-API v5

func (*Server) ServiceName

func (s *Server) ServiceName() string

ServiceName returns ServiceName parameter for PA-API v5

func (*Server) URL

func (s *Server) URL(path string) *url.URL

URL returns url.URL instance

type ServerOptFunc

type ServerOptFunc func(*Server)

ServerOptFunc is self-referential function for functional options pattern

func WithMarketplace

func WithMarketplace(marketplace string) ServerOptFunc

WithMarketplace returns function for setting hostname

type TimeStamp

type TimeStamp struct {
	time.Time
}

TimeStamp is wrapper class of time.Time

func NewTimeStamp

func NewTimeStamp(tm time.Time) TimeStamp

NewTimeStamp returns TimeStamp instance

func (TimeStamp) String

func (t TimeStamp) String() string

func (TimeStamp) StringDate

func (t TimeStamp) StringDate() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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