gopaapi5

package module
v1.3.3 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2020 License: BSD-3-Clause Imports: 15 Imported by: 6

README

gopaapi5

Build Status Go Report Card GoDoc Coverage Status

gopaapi5 is a Go client library for accessing the Amazon Product Advertising API 5.0.

Usage

Install package:

go get -u github.com/utekaravinash/gopaapi5

Here's an example for GetBrowseNodes operation:

package main

import (
	"fmt"
	"os"

	"github.com/utekaravinash/gopaapi5"
	"github.com/utekaravinash/gopaapi5/api"
)

const tmpl = `Id: %s
Name: %s
-----------------------------
`

func main() {

	// Get Access Key, Secret Key and Associate Tag from the environment variables
	accessKey := os.Getenv("PA_ACCESS_KEY")
	secretKey := os.Getenv("PA_SECRET_KEY")
	associateTag := os.Getenv("PA_ASSOCIATE_TAG")

	// Initiate gopaapi5 Client
	client, err := gopaapi5.NewClient(accessKey, secretKey, associateTag, api.UnitedStates)
	if err != nil {
		panic(err)
	}

	// Construct request parameters for GetBrowseNodes operation
	params := api.GetBrowseNodesParams{
		BrowseNodeIds: []string{
			"6960520011",
			"281407",
		},
		Resources: []api.Resource{
			api.BrowseNodesAncestor,
			api.BrowseNodesChildren,
		},
		LanguagesOfPreference: []api.Language{api.EnglishUnitedStates},
	}

	// Call GetBrowseNodes operation
	response, err := client.GetBrowseNodes(context.Background(), &params)
	if err != nil {
		panic(err)
	}

	// Loop over browse nodes in response
	for _, node := range response.BrowseNodesResult.BrowseNodes {
		fmt.Printf(tmpl, node.Id, node.DisplayName)
	}
}

This client library exposes these operations for Amazon Product Advertising API 5.0 (click on links for their examples):

Use SetHttpClient() method of Client struct to set a custom HTTP client.

Author

Avinash Utekar

License

BSD 3-Clause

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyAccessKey is thrown when access key is empty
	ErrEmptyAccessKey = errors.New("Empty access key")
	// ErrEmptySecretKey is thrown when secret key is empty
	ErrEmptySecretKey = errors.New("Empty secret key")
	// ErrEmptyAssociateTag is thrown when associate tag is empty
	ErrEmptyAssociateTag = errors.New("Empty associate tag")
	// ErrInvalidLocale is thrown when locale is invalid
	ErrInvalidLocale = errors.New("Invalid locale")
	// ErrNilHttpClient is thrown when locale is invalid
	ErrNilHttpClient = errors.New("Nil http client")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	AccessKey    string
	SecretKey    string
	AssociateTag string
	Locale       api.Locale
	// contains filtered or unexported fields
}

Client stores AccessKey, SecretKey, and, AssociateTag; and exposes GetBrowseNodes, GetItems, GetVariations, and SearchItems operations.

func NewClient

func NewClient(accessKey, secretKey, associateTag string, locale api.Locale) (*Client, error)

NewClient accepts Access Key, Secrete Key, Associate Tag, Locale and returns a new client

func (*Client) GetBrowseNodes

func (c *Client) GetBrowseNodes(ctx context.Context, params *api.GetBrowseNodesParams) (*api.GetBrowseNodesResponse, error)

GetBrowseNodes gets information for Browse Nodes

func (*Client) GetItems

func (c *Client) GetItems(ctx context.Context, params *api.GetItemsParams) (*api.GetItemsResponse, error)

GetItems gets information for items

func (*Client) GetVariations

func (c *Client) GetVariations(ctx context.Context, params *api.GetVariationsParams) (*api.GetVariationsResponse, error)

GetVariations gets information for variations

func (*Client) SearchItems

func (c *Client) SearchItems(ctx context.Context, params *api.SearchItemsParams) (*api.SearchItemsResponse, error)

SearchItems searches for items on Amazon

func (*Client) SetHttpClient added in v1.3.0

func (c *Client) SetHttpClient(httpClient *http.Client) error

SetHttpClient allows you to change the default http client used by gopaapi5 client

Directories

Path Synopsis
_examples

Jump to

Keyboard shortcuts

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