Test contextual location and add first integration test

This commit is contained in:
Jean-Baptiste Pinalie
2019-05-27 21:54:44 +02:00
parent 4b7e5a67c7
commit a63792e92f
7 changed files with 152 additions and 9 deletions
+11 -5
View File
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net/http"
"net/url"
)
// BrowseService handles communication with the Browse API
@@ -11,24 +12,29 @@ import (
// eBay API docs: https://developer.ebay.com/api-docs/buy/browse/overview.html
type BrowseService service
// OptContextualLocation adds the header containing contextualLocation.
// OptBrowseContextualLocation adds the header containing contextualLocation.
// It is strongly recommended that you use it when submitting Browse API methods.
//
// eBay API docs: https://developer.ebay.com/api-docs/buy/static/api-browse.html#Headers
func OptContextualLocation(country, zip string) func(*http.Request) {
func OptBrowseContextualLocation(country, zip string) func(*http.Request) {
return func(req *http.Request) {
// X-EBAY-C-ENDUSERCTX: contextualLocation=country=US,zip=19406
v := req.Header.Get(headerEndUserCtx)
if len(v) > 0 {
v += ","
}
v += "contextualLocation=" + url.QueryEscape(fmt.Sprintf("country=%s,zip=%s", country, zip))
req.Header.Set(headerEndUserCtx, v)
}
}
// Item represents a eBay item.
// Item represents an eBay item.
type Item struct{}
// GetItem retrieves the details of a specific item.
//
// eBay API docs: https://developer.ebay.com/api-docs/buy/browse/resources/item/methods/getItem
func (s *BrowseService) GetItem(ctx context.Context, itemID string, opts ...Opt) (Item, error) {
u := fmt.Sprintf("item/%s", itemID)
u := fmt.Sprintf("buy/browse/v1/item/%s", itemID)
req, err := s.client.NewRequest(http.MethodGet, u, opts...)
if err != nil {
return Item{}, err