Help us shape the future of Go! Take the 2026 Go Developer Survey

gopaapi5

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 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(&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 Client instance's SetTimeout() method to set a time limit for the above operations. If not used, the operations wait until API service either completes or times out.

Note: You can also pass context to the Ctx suffixed methods mentioned above. viz. GetBrowseNodesCtx, GetItemsCtx, GetVariationsCtx, and SearchItemsCtx

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

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(params *api.GetBrowseNodesParams) (*api.GetBrowseNodesResponse, error)

GetBrowseNodes gets information for Browse Nodes

func (*Client) GetBrowseNodesCtx added in v1.2.0

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

GetBrowseNodesCtx gets information for Browse Nodes, also accepts context.Context

func (*Client) GetItems

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

GetItems gets information for items

func (*Client) GetItemsCtx added in v1.2.0

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

GetItemsCtx gets information for items, also accepts context.Context

func (*Client) GetVariations

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

GetVariations gets information for variations

func (*Client) GetVariationsCtx added in v1.2.0

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

GetVariationsCtx gets information for variations, also accepts context.Context

func (*Client) SearchItems

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

SearchItems searches for items on Amazon

func (*Client) SearchItemsCtx added in v1.2.0

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

SearchItemsCtx searches for items on Amazon, also accepts context.Context

func (*Client) SetTimeout added in v1.1.0

func (c *Client) SetTimeout(duration time.Duration)

SetTimeout sets a time limit for the operations made by the Client.

Directories

Path Synopsis
_examples
get_items command
get_variations command
search_items command

Jump to

Keyboard shortcuts

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