-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from goark/issue-25
Enable to get browse node Info #25
- Loading branch information
Showing
14 changed files
with
296 additions
and
701 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/goark/pa-api | ||
|
||
go 1.17 | ||
go 1.18 | ||
|
||
require ( | ||
github.com/goark/errs v1.1.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package query | ||
|
||
import ( | ||
paapi5 "github.com/goark/pa-api" | ||
) | ||
|
||
//GetItems type is embedded Query for GetItems operation in PA-API v5 | ||
type GetBrowseNodes struct { | ||
Query | ||
} | ||
|
||
var _ paapi5.Query = (*GetItems)(nil) //GetItems is compatible with paapi5.Query interface | ||
|
||
//New creates new GetBrowseNodes instance | ||
func NewGetBrowseNodes(marketplace, partnerTag, partnerType string) *GetBrowseNodes { | ||
q := &GetBrowseNodes{*(New(paapi5.GetBrowseNodes))} | ||
q.Request(Marketplace, marketplace).Request(PartnerTag, partnerTag).Request(PartnerType, partnerType) | ||
return q | ||
} | ||
|
||
var requestsOfGetBrowseNodes = []RequestFilter{ | ||
BrowseNodeIds, | ||
LanguagesOfPreference, | ||
Marketplace, | ||
PartnerTag, | ||
PartnerType, | ||
} | ||
|
||
//RequestFilters adds RequestFilter to Query instance | ||
func (q *GetBrowseNodes) Request(request RequestFilter, value interface{}) *GetBrowseNodes { | ||
if request.findIn(requestsOfGetBrowseNodes) { | ||
q.With().RequestFilters(RequestMap{request: value}) | ||
} | ||
return q | ||
} | ||
|
||
//BrowseNodeIds sets ItemIds in GetItems instance | ||
func (q *GetBrowseNodes) BrowseNodeIds(itms []string) *GetBrowseNodes { | ||
return q.Request(BrowseNodeIds, itms) | ||
} | ||
|
||
//EnableBrowseNodes sets the resource of EnableBrowseNodes | ||
func (q *GetBrowseNodes) EnableBrowseNodes() *GetBrowseNodes { | ||
q.With().BrowseNodes() | ||
return q | ||
} | ||
|
||
/* Copyright 2022 Spiegel and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package query | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestGetBrowseNodes(t *testing.T) { | ||
testCases := []struct { | ||
q *GetBrowseNodes | ||
str string | ||
}{ | ||
{q: NewGetBrowseNodes("foo.bar", "mytag-20", "Associates"), str: `{"Operation":"GetBrowseNodes","Marketplace":"foo.bar","PartnerTag":"mytag-20","PartnerType":"Associates"}`}, | ||
{q: NewGetBrowseNodes("foo.bar", "mytag-20", "Associates").BrowseNodeIds([]string{"123"}), str: `{"Operation":"GetBrowseNodes","BrowseNodeIds":["123"],"Marketplace":"foo.bar","PartnerTag":"mytag-20","PartnerType":"Associates"}`}, | ||
} | ||
for _, tc := range testCases { | ||
if str := tc.q.String(); str != tc.str { | ||
t.Errorf("BrowseNodes.String() is \"%v\", want \"%v\"", str, tc.str) | ||
} | ||
} | ||
} | ||
|
||
func TestRequestFiltersInGetBrowseNodes(t *testing.T) { | ||
testCases := []struct { | ||
q *GetBrowseNodes | ||
str string | ||
}{ | ||
{q: NewGetBrowseNodes("", "", ""), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Actor, "foo"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Artist, "foo"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Availability, "Available"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Author, "foo"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Brand, "foo"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(BrowseNodeID, "123"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Condition, "foo"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Condition, "Any"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Condition, "New"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Condition, "Used"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Condition, "Collectible"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Condition, "Refurbished"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(CurrencyOfPreference, "foo"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(DeliveryFlags, "AmazonGlobal"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(ItemIds, "4900900028"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(ItemIdType, "ASIN"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(ItemCount, 1), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(ItemPage, 1), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(ItemPage, 1), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Keywords, "foo"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(BrowseNodeIds, "123"), str: `{"Operation":"GetBrowseNodes","BrowseNodeIds":["123"]}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(BrowseNodeIds, []string{"123", "456"}), str: `{"Operation":"GetBrowseNodes","BrowseNodeIds":["123","456"]}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(LanguagesOfPreference, "foo"), str: `{"Operation":"GetBrowseNodes","LanguagesOfPreference":["foo"]}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(LanguagesOfPreference, []string{"foo", "bar"}), str: `{"Operation":"GetBrowseNodes","LanguagesOfPreference":["foo","bar"]}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Marketplace, "foo.bar"), str: `{"Operation":"GetBrowseNodes","Marketplace":"foo.bar"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(MaxPrice, 1), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Merchant, "foo"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Merchant, "All"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Merchant, "Amazon"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(MinPrice, 1), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(MinReviewsRating, 1), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(MinSavingPercent, 1), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(OfferCount, -1), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(OfferCount, 0), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(OfferCount, 1), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(OfferCount, 123), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(PartnerTag, "foo"), str: `{"Operation":"GetBrowseNodes","PartnerTag":"foo"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(PartnerType, "foo"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(PartnerType, "Associates"), str: `{"Operation":"GetBrowseNodes","PartnerType":"Associates"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Properties, map[string]string{"foo": "bar"}), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(SearchIndex, "All"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(SortBy, "AvgCustomerReviews"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
{q: NewGetBrowseNodes("", "", "").Request(Title, "foo"), str: `{"Operation":"GetBrowseNodes"}`}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
if str := tc.q.String(); str != tc.str { | ||
t.Errorf("BrowseNodes.String() is \"%v\", want \"%v\"", str, tc.str) | ||
} | ||
} | ||
} | ||
|
||
func TestResourcesInGetBrowseNodes(t *testing.T) { | ||
testCases := []struct { | ||
q *GetBrowseNodes | ||
str string | ||
}{ | ||
{q: NewGetBrowseNodes("", "", "").EnableBrowseNodes(), str: `{"Operation":"GetBrowseNodes","Resources":["BrowseNodes.Ancestor","BrowseNodes.Children"]}`}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
if str := tc.q.String(); str != tc.str { | ||
t.Errorf("Query.String() is \"%v\", want \"%v\"", str, tc.str) | ||
} | ||
} | ||
} | ||
|
||
/* Copyright 2022 Spiegel and contributors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ |
Oops, something went wrong.