Skip to content

Commit

Permalink
Merge pull request #13 from hackmac89/feature/add-undocumented-custom…
Browse files Browse the repository at this point in the history
…er-rating-feature

Added undocumented Customer Rating to API
  • Loading branch information
spiegel-im-spiegel committed Jun 30, 2020
2 parents ed58b21 + 64dd6ff commit ce8577a
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 4 deletions.
10 changes: 8 additions & 2 deletions entity/entity.go
Expand Up @@ -67,8 +67,14 @@ type GenPriceInfo struct {
}

type Item struct {
ASIN string
DetailPageURL string
ASIN string
DetailPageURL string
CustomerReviews *struct {
Count *int `json:",omitempty"`
StarRating *struct {
Value *float64 `json:",omitempty"`
} `json:",omitempty"`
} `json:",omitempty"`
BrowseNodeInfo *struct {
BrowseNodes []struct {
Id string
Expand Down
8 changes: 7 additions & 1 deletion query/getitems.go
Expand Up @@ -50,7 +50,7 @@ func (q *GetItems) EnableBrowseNodeInfo() *GetItems {
return q
}

//Images sets the resource of Images
//EnableImages sets the resource of Images
func (q *GetItems) EnableImages() *GetItems {
q.With().Images()
return q
Expand All @@ -74,6 +74,12 @@ func (q *GetItems) EnableParentASIN() *GetItems {
return q
}

//EnableCustomerReviews sets the resource of CustomerReviews
func (q *GetItems) EnableCustomerReviews() *GetItems {
q.With().CustomerReviews()
return q
}

/* Copyright 2019 Spiegel and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions query/getitems_test.go
Expand Up @@ -85,6 +85,7 @@ func TestResourcesInGetItems(t *testing.T) {
{q: NewGetItems("", "", "").EnableItemInfo(), str: `{"Operation":"GetItems","Resources":["ItemInfo.ByLineInfo","ItemInfo.ContentInfo","ItemInfo.ContentRating","ItemInfo.Classifications","ItemInfo.ExternalIds","ItemInfo.Features","ItemInfo.ManufactureInfo","ItemInfo.ProductInfo","ItemInfo.TechnicalInfo","ItemInfo.Title","ItemInfo.TradeInInfo"]}`},
{q: NewGetItems("", "", "").EnableOffers(), str: `{"Operation":"GetItems","Resources":["Offers.Listings.Availability.MaxOrderQuantity","Offers.Listings.Availability.Message","Offers.Listings.Availability.MinOrderQuantity","Offers.Listings.Availability.Type","Offers.Listings.Condition","Offers.Listings.Condition.SubCondition","Offers.Listings.DeliveryInfo.IsAmazonFulfilled","Offers.Listings.DeliveryInfo.IsFreeShippingEligible","Offers.Listings.DeliveryInfo.IsPrimeEligible","Offers.Listings.DeliveryInfo.ShippingCharges","Offers.Listings.IsBuyBoxWinner","Offers.Listings.LoyaltyPoints.Points","Offers.Listings.MerchantInfo","Offers.Listings.Price","Offers.Listings.ProgramEligibility.IsPrimeExclusive","Offers.Listings.ProgramEligibility.IsPrimePantry","Offers.Listings.Promotions","Offers.Listings.SavingBasis","Offers.Summaries.HighestPrice","Offers.Summaries.LowestPrice","Offers.Summaries.OfferCount"]}`},
{q: NewGetItems("", "", "").EnableParentASIN(), str: `{"Operation":"GetItems","Resources":["ParentASIN"]}`},
{q: NewGetItems("", "", "").EnableCustomerReviews(), str: `{"Operation":"GetItems","Resources":["CustomerReviews.Count","CustomerReviews.StarRating"]}`},
}

for _, tc := range testCases {
Expand Down
6 changes: 6 additions & 0 deletions query/query.go
Expand Up @@ -111,6 +111,12 @@ func (q *Query) ParentASIN() *Query {
return q
}

//CustomerReviews sets the resource of CustomerReviews resource
func (q *Query) CustomerReviews() *Query {
q.enableResources[resourceCustomerReviews] = true
return q
}

/* Copyright 2019 Spiegel and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
7 changes: 7 additions & 0 deletions query/resources.go
Expand Up @@ -9,6 +9,7 @@ const (
resourceOffers //Offers resource
resourceSearchRefinements //SearchRefinements resource
resourceParentASIN //ParentASIN resource
resourceCustomerReviews //CustomerReviews resource
)

var (
Expand Down Expand Up @@ -74,13 +75,19 @@ var (
resourcesParentASIN = []string{
"ParentASIN",
}
//CustomerReviews resource
resourcesCustomerReviews = []string{
"CustomerReviews.Count",
"CustomerReviews.StarRating",
}
resourcesMap = map[resource][]string{
resourceBrowseNodeInfo: resourcesBrowseNodeInfo, //BrowseNodeInfo resource
resourceImages: resourcesImages, //Images resource
resourceItemInfo: resourcesItemInfo, //ItemInfo resource
resourceOffers: resourcesOffers, //Offers resource
resourceSearchRefinements: resourcesSearchRefinements, //SearchRefinements resource
resourceParentASIN: resourcesParentASIN, //ParentASIN resource
resourceCustomerReviews: resourcesCustomerReviews, //CustomerReviews resource
}
)

Expand Down
8 changes: 7 additions & 1 deletion query/searchitems.go
Expand Up @@ -50,7 +50,7 @@ var (
searchTypes = []RequestFilter{Actor, Artist, Author, Brand, Keywords, Title}
)

//RequestFilters adds RequestFilter to Query instance
//Request adds RequestFilter to Query instance
func (q *SearchItems) Request(request RequestFilter, value interface{}) *SearchItems {
if request.findIn(requestsOfSearchItems) {
q.With().RequestFilters(RequestMap{request: value})
Expand Down Expand Up @@ -102,6 +102,12 @@ func (q *SearchItems) EnableParentASIN() *SearchItems {
return q
}

//EnableCustomerReviews sets the enableCustomerReviews flag in SearchItems instance
func (q *SearchItems) EnableCustomerReviews() *SearchItems {
q.With().CustomerReviews()
return q
}

/* Copyright 2019 Spiegel and contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down
1 change: 1 addition & 0 deletions query/searchitems_test.go
Expand Up @@ -172,6 +172,7 @@ func TestResourcesInSearchItems(t *testing.T) {
{q: NewSearchItems("", "", "").EnableOffers(), str: `{"Operation":"SearchItems","Resources":["Offers.Listings.Availability.MaxOrderQuantity","Offers.Listings.Availability.Message","Offers.Listings.Availability.MinOrderQuantity","Offers.Listings.Availability.Type","Offers.Listings.Condition","Offers.Listings.Condition.SubCondition","Offers.Listings.DeliveryInfo.IsAmazonFulfilled","Offers.Listings.DeliveryInfo.IsFreeShippingEligible","Offers.Listings.DeliveryInfo.IsPrimeEligible","Offers.Listings.DeliveryInfo.ShippingCharges","Offers.Listings.IsBuyBoxWinner","Offers.Listings.LoyaltyPoints.Points","Offers.Listings.MerchantInfo","Offers.Listings.Price","Offers.Listings.ProgramEligibility.IsPrimeExclusive","Offers.Listings.ProgramEligibility.IsPrimePantry","Offers.Listings.Promotions","Offers.Listings.SavingBasis","Offers.Summaries.HighestPrice","Offers.Summaries.LowestPrice","Offers.Summaries.OfferCount"]}`},
{q: NewSearchItems("", "", "").EnableSearchRefinements(), str: `{"Operation":"SearchItems","Resources":["SearchRefinements"]}`},
{q: NewSearchItems("", "", "").EnableParentASIN(), str: `{"Operation":"SearchItems","Resources":["ParentASIN"]}`},
{q: NewSearchItems("", "", "").EnableCustomerReviews(), str: `{"Operation":"SearchItems","Resources":["CustomerReviews.Count","CustomerReviews.StarRating"]}`},
}

for _, tc := range testCases {
Expand Down

0 comments on commit ce8577a

Please sign in to comment.