Skip to content

Commit 3ed4e26

Browse files
Merge pull request #26 from goark/issue-25
Enable to get browse node Info #25
2 parents d2bce62 + c6f7f64 commit 3ed4e26

14 files changed

+296
-701
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,52 +15,44 @@ on:
1515
- cron: '0 20 * * 0'
1616

1717
jobs:
18-
analyze:
19-
name: Analyze
18+
CodeQL-Build:
19+
# CodeQL runs on ubuntu-latest, windows-latest, and macos-latest
2020
runs-on: ubuntu-latest
2121

22-
strategy:
23-
fail-fast: false
24-
matrix:
25-
# Override automatic language detection by changing the below list
26-
# Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python']
27-
language: ['go']
28-
# Learn more...
29-
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
22+
permissions:
23+
# required for all workflows
24+
security-events: write
3025

31-
steps:
32-
- name: Checkout repository
33-
uses: actions/checkout@v2
34-
with:
35-
# We must fetch at least the immediate parents so that if this is
36-
# a pull request then we can checkout the head.
37-
fetch-depth: 2
38-
39-
# Initializes the CodeQL tools for scanning.
40-
- name: Initialize CodeQL
41-
uses: github/codeql-action/init@v1
42-
with:
43-
languages: ${{ matrix.language }}
44-
# If you wish to specify custom queries, you can do so here or in a config file.
45-
# By default, queries listed here will override any specified in a config file.
46-
# Prefix the list here with "+" to use these queries and those in the config file.
47-
# queries: ./path/to/local/query, your-org/your-repo/queries@main
48-
49-
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
50-
# If this step fails, then you should remove it and run the build manually (see below)
51-
- name: Autobuild
52-
uses: github/codeql-action/autobuild@v1
53-
54-
# ℹ️ Command-line programs to run using the OS shell.
55-
# 📚 https://git.io/JvXDl
26+
# only required for workflows in private repositories
27+
actions: read
28+
contents: read
5629

57-
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
58-
# and modify them (or add more) to build your code if your project
59-
# uses a compiled language
60-
61-
#- run: |
62-
# make bootstrap
63-
# make release
64-
65-
- name: Perform CodeQL Analysis
66-
uses: github/codeql-action/analyze@v1
30+
steps:
31+
- name: Checkout repository
32+
uses: actions/checkout@v3
33+
34+
# Initializes the CodeQL tools for scanning.
35+
- name: Initialize CodeQL
36+
uses: github/codeql-action/init@v2
37+
# Override language selection by uncommenting this and choosing your languages
38+
with:
39+
languages: go
40+
41+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
42+
# If this step fails, then you should remove it and run the build manually (see below).
43+
- name: Autobuild
44+
uses: github/codeql-action/autobuild@v2
45+
46+
# ℹ️ Command-line programs to run using the OS shell.
47+
# 📚 https://git.io/JvXDl
48+
49+
# ✏️ If the Autobuild fails above, remove it and uncomment the following
50+
# three lines and modify them (or add more) to build your code if your
51+
# project uses a compiled language
52+
53+
#- run: |
54+
# make bootstrap
55+
# make release
56+
57+
- name: Perform CodeQL Analysis
58+
uses: github/codeql-action/analyze@v2

.github/workflows/lint.yml

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,43 @@ on:
44
branches:
55
- master
66
pull_request:
7+
8+
permissions:
9+
contents: read
10+
# Optional: allow read access to pull request. Use with `only-new-issues` option.
11+
# pull-requests: read
712
jobs:
813
golangci:
914
name: lint
1015
runs-on: ubuntu-latest
1116
steps:
12-
- uses: actions/checkout@v2
13-
- uses: actions/setup-go@v2
17+
- uses: actions/setup-go@v3
1418
with:
15-
go-version: ^1.17
19+
go-version: ^1.18
20+
- uses: actions/checkout@v3
1621
- name: golangci-lint
17-
uses: golangci/golangci-lint-action@v2
22+
uses: golangci/golangci-lint-action@v3
1823
with:
19-
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
24+
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
2025
version: latest
26+
27+
# Optional: working directory, useful for monorepos
28+
# working-directory: somedir
29+
2130
# Optional: golangci-lint command line arguments.
2231
args: --enable gosec
32+
33+
# Optional: show only new issues if it's a pull request. The default value is `false`.
34+
# only-new-issues: true
35+
36+
# Optional: if set to true then the all caching functionality will be complete disabled,
37+
# takes precedence over all other caching options.
38+
# skip-cache: true
39+
40+
# Optional: if set to true then the action don't cache or restore ~/go/pkg.
41+
# skip-pkg-cache: true
42+
43+
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build.
44+
# skip-build-cache: true
2345
- name: testing
2446
run: go test -shuffle on ./...

.github/workflows/vulns.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
name: vulns
22
on:
33
push:
4-
tags:
5-
- v*
64
branches:
75
- master
86
pull_request:
@@ -14,7 +12,7 @@ jobs:
1412
- uses: actions/checkout@v2
1513
- uses: actions/setup-go@v2
1614
with:
17-
go-version: ^1.17
15+
go-version: ^1.18
1816
- name: WriteGoList
1917
run: go list -json -m all > go.list
2018
- name: Nancy

Taskfile.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ tasks:
1111
cmds:
1212
- go mod verify
1313
- go test -shuffle on ./...
14-
- docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.44.2 golangci-lint run --enable gosec --timeout 3m0s ./...
14+
- docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.46.2 golangci-lint run --enable gosec --timeout 3m0s ./...
1515
sources:
1616
- ./go.mod
1717
- '**/*.go'
1818

1919
clean:
2020
desc: Initialize module and build cache, and remake go.sum file.
2121
cmds:
22-
- go mod tidy -v -go=1.17
22+
- go mod tidy -v -go=1.18

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/goark/pa-api
22

3-
go 1.17
3+
go 1.18
44

55
require (
66
github.com/goark/errs v1.1.0

operation.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ var _ json.Marshaler = Operation(0) //Operation type is compatible with j
1414
var _ json.Unmarshaler = (*Operation)(nil) //Operation type is compatible with json.Unmarshaler interface
1515

1616
const (
17-
NullOperation Operation = iota //Unknown
18-
GetVariations //GetVariations
19-
GetItems //GetItems
20-
SearchItems //SearchItems
17+
NullOperation Operation = iota //Unknown
18+
GetVariations //GetVariations
19+
GetItems //GetItems
20+
SearchItems //SearchItems
21+
GetBrowseNodes //GetBrowseNodes
2122
)
2223

2324
var nameMap = map[Operation]string{
24-
GetVariations: "GetVariations",
25-
GetItems: "GetItems",
26-
SearchItems: "SearchItems",
25+
GetVariations: "GetVariations",
26+
GetItems: "GetItems",
27+
SearchItems: "SearchItems",
28+
GetBrowseNodes: "GetBrowseNodes",
2729
}
2830

2931
//String method is a implementation of fmt.Stringer interface.
@@ -71,7 +73,7 @@ func (c Operation) MarshalJSON() ([]byte, error) {
7173
return []byte(strconv.Quote(c.String())), nil
7274
}
7375

74-
/* Copyright 2019 Spiegel
76+
/* Copyright 2019-2022 Spiegel
7577
*
7678
* Licensed under the Apache License, Version 2.0 (the "License");
7779
* you may not use this file except in compliance with the License.

query/getbrowsenodes.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package query
2+
3+
import (
4+
paapi5 "github.com/goark/pa-api"
5+
)
6+
7+
//GetItems type is embedded Query for GetItems operation in PA-API v5
8+
type GetBrowseNodes struct {
9+
Query
10+
}
11+
12+
var _ paapi5.Query = (*GetItems)(nil) //GetItems is compatible with paapi5.Query interface
13+
14+
//New creates new GetBrowseNodes instance
15+
func NewGetBrowseNodes(marketplace, partnerTag, partnerType string) *GetBrowseNodes {
16+
q := &GetBrowseNodes{*(New(paapi5.GetBrowseNodes))}
17+
q.Request(Marketplace, marketplace).Request(PartnerTag, partnerTag).Request(PartnerType, partnerType)
18+
return q
19+
}
20+
21+
var requestsOfGetBrowseNodes = []RequestFilter{
22+
BrowseNodeIds,
23+
LanguagesOfPreference,
24+
Marketplace,
25+
PartnerTag,
26+
PartnerType,
27+
}
28+
29+
//RequestFilters adds RequestFilter to Query instance
30+
func (q *GetBrowseNodes) Request(request RequestFilter, value interface{}) *GetBrowseNodes {
31+
if request.findIn(requestsOfGetBrowseNodes) {
32+
q.With().RequestFilters(RequestMap{request: value})
33+
}
34+
return q
35+
}
36+
37+
//BrowseNodeIds sets ItemIds in GetItems instance
38+
func (q *GetBrowseNodes) BrowseNodeIds(itms []string) *GetBrowseNodes {
39+
return q.Request(BrowseNodeIds, itms)
40+
}
41+
42+
//EnableBrowseNodes sets the resource of EnableBrowseNodes
43+
func (q *GetBrowseNodes) EnableBrowseNodes() *GetBrowseNodes {
44+
q.With().BrowseNodes()
45+
return q
46+
}
47+
48+
/* Copyright 2022 Spiegel and contributors
49+
*
50+
* Licensed under the Apache License, Version 2.0 (the "License");
51+
* you may not use this file except in compliance with the License.
52+
* You may obtain a copy of the License at
53+
*
54+
* http://www.apache.org/licenses/LICENSE-2.0
55+
*
56+
* Unless required by applicable law or agreed to in writing, software
57+
* distributed under the License is distributed on an "AS IS" BASIS,
58+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59+
* See the License for the specific language governing permissions and
60+
* limitations under the License.
61+
*/

query/getbrowsenodes_test.go

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package query
2+
3+
import (
4+
"testing"
5+
)
6+
7+
func TestGetBrowseNodes(t *testing.T) {
8+
testCases := []struct {
9+
q *GetBrowseNodes
10+
str string
11+
}{
12+
{q: NewGetBrowseNodes("foo.bar", "mytag-20", "Associates"), str: `{"Operation":"GetBrowseNodes","Marketplace":"foo.bar","PartnerTag":"mytag-20","PartnerType":"Associates"}`},
13+
{q: NewGetBrowseNodes("foo.bar", "mytag-20", "Associates").BrowseNodeIds([]string{"123"}), str: `{"Operation":"GetBrowseNodes","BrowseNodeIds":["123"],"Marketplace":"foo.bar","PartnerTag":"mytag-20","PartnerType":"Associates"}`},
14+
}
15+
for _, tc := range testCases {
16+
if str := tc.q.String(); str != tc.str {
17+
t.Errorf("BrowseNodes.String() is \"%v\", want \"%v\"", str, tc.str)
18+
}
19+
}
20+
}
21+
22+
func TestRequestFiltersInGetBrowseNodes(t *testing.T) {
23+
testCases := []struct {
24+
q *GetBrowseNodes
25+
str string
26+
}{
27+
{q: NewGetBrowseNodes("", "", ""), str: `{"Operation":"GetBrowseNodes"}`},
28+
{q: NewGetBrowseNodes("", "", "").Request(Actor, "foo"), str: `{"Operation":"GetBrowseNodes"}`},
29+
{q: NewGetBrowseNodes("", "", "").Request(Artist, "foo"), str: `{"Operation":"GetBrowseNodes"}`},
30+
{q: NewGetBrowseNodes("", "", "").Request(Availability, "Available"), str: `{"Operation":"GetBrowseNodes"}`},
31+
{q: NewGetBrowseNodes("", "", "").Request(Author, "foo"), str: `{"Operation":"GetBrowseNodes"}`},
32+
{q: NewGetBrowseNodes("", "", "").Request(Brand, "foo"), str: `{"Operation":"GetBrowseNodes"}`},
33+
{q: NewGetBrowseNodes("", "", "").Request(BrowseNodeID, "123"), str: `{"Operation":"GetBrowseNodes"}`},
34+
{q: NewGetBrowseNodes("", "", "").Request(Condition, "foo"), str: `{"Operation":"GetBrowseNodes"}`},
35+
{q: NewGetBrowseNodes("", "", "").Request(Condition, "Any"), str: `{"Operation":"GetBrowseNodes"}`},
36+
{q: NewGetBrowseNodes("", "", "").Request(Condition, "New"), str: `{"Operation":"GetBrowseNodes"}`},
37+
{q: NewGetBrowseNodes("", "", "").Request(Condition, "Used"), str: `{"Operation":"GetBrowseNodes"}`},
38+
{q: NewGetBrowseNodes("", "", "").Request(Condition, "Collectible"), str: `{"Operation":"GetBrowseNodes"}`},
39+
{q: NewGetBrowseNodes("", "", "").Request(Condition, "Refurbished"), str: `{"Operation":"GetBrowseNodes"}`},
40+
{q: NewGetBrowseNodes("", "", "").Request(CurrencyOfPreference, "foo"), str: `{"Operation":"GetBrowseNodes"}`},
41+
{q: NewGetBrowseNodes("", "", "").Request(DeliveryFlags, "AmazonGlobal"), str: `{"Operation":"GetBrowseNodes"}`},
42+
{q: NewGetBrowseNodes("", "", "").Request(ItemIds, "4900900028"), str: `{"Operation":"GetBrowseNodes"}`},
43+
{q: NewGetBrowseNodes("", "", "").Request(ItemIdType, "ASIN"), str: `{"Operation":"GetBrowseNodes"}`},
44+
{q: NewGetBrowseNodes("", "", "").Request(ItemCount, 1), str: `{"Operation":"GetBrowseNodes"}`},
45+
{q: NewGetBrowseNodes("", "", "").Request(ItemPage, 1), str: `{"Operation":"GetBrowseNodes"}`},
46+
{q: NewGetBrowseNodes("", "", "").Request(ItemPage, 1), str: `{"Operation":"GetBrowseNodes"}`},
47+
{q: NewGetBrowseNodes("", "", "").Request(Keywords, "foo"), str: `{"Operation":"GetBrowseNodes"}`},
48+
{q: NewGetBrowseNodes("", "", "").Request(BrowseNodeIds, "123"), str: `{"Operation":"GetBrowseNodes","BrowseNodeIds":["123"]}`},
49+
{q: NewGetBrowseNodes("", "", "").Request(BrowseNodeIds, []string{"123", "456"}), str: `{"Operation":"GetBrowseNodes","BrowseNodeIds":["123","456"]}`},
50+
{q: NewGetBrowseNodes("", "", "").Request(LanguagesOfPreference, "foo"), str: `{"Operation":"GetBrowseNodes","LanguagesOfPreference":["foo"]}`},
51+
{q: NewGetBrowseNodes("", "", "").Request(LanguagesOfPreference, []string{"foo", "bar"}), str: `{"Operation":"GetBrowseNodes","LanguagesOfPreference":["foo","bar"]}`},
52+
{q: NewGetBrowseNodes("", "", "").Request(Marketplace, "foo.bar"), str: `{"Operation":"GetBrowseNodes","Marketplace":"foo.bar"}`},
53+
{q: NewGetBrowseNodes("", "", "").Request(MaxPrice, 1), str: `{"Operation":"GetBrowseNodes"}`},
54+
{q: NewGetBrowseNodes("", "", "").Request(Merchant, "foo"), str: `{"Operation":"GetBrowseNodes"}`},
55+
{q: NewGetBrowseNodes("", "", "").Request(Merchant, "All"), str: `{"Operation":"GetBrowseNodes"}`},
56+
{q: NewGetBrowseNodes("", "", "").Request(Merchant, "Amazon"), str: `{"Operation":"GetBrowseNodes"}`},
57+
{q: NewGetBrowseNodes("", "", "").Request(MinPrice, 1), str: `{"Operation":"GetBrowseNodes"}`},
58+
{q: NewGetBrowseNodes("", "", "").Request(MinReviewsRating, 1), str: `{"Operation":"GetBrowseNodes"}`},
59+
{q: NewGetBrowseNodes("", "", "").Request(MinSavingPercent, 1), str: `{"Operation":"GetBrowseNodes"}`},
60+
{q: NewGetBrowseNodes("", "", "").Request(OfferCount, -1), str: `{"Operation":"GetBrowseNodes"}`},
61+
{q: NewGetBrowseNodes("", "", "").Request(OfferCount, 0), str: `{"Operation":"GetBrowseNodes"}`},
62+
{q: NewGetBrowseNodes("", "", "").Request(OfferCount, 1), str: `{"Operation":"GetBrowseNodes"}`},
63+
{q: NewGetBrowseNodes("", "", "").Request(OfferCount, 123), str: `{"Operation":"GetBrowseNodes"}`},
64+
{q: NewGetBrowseNodes("", "", "").Request(PartnerTag, "foo"), str: `{"Operation":"GetBrowseNodes","PartnerTag":"foo"}`},
65+
{q: NewGetBrowseNodes("", "", "").Request(PartnerType, "foo"), str: `{"Operation":"GetBrowseNodes"}`},
66+
{q: NewGetBrowseNodes("", "", "").Request(PartnerType, "Associates"), str: `{"Operation":"GetBrowseNodes","PartnerType":"Associates"}`},
67+
{q: NewGetBrowseNodes("", "", "").Request(Properties, map[string]string{"foo": "bar"}), str: `{"Operation":"GetBrowseNodes"}`},
68+
{q: NewGetBrowseNodes("", "", "").Request(SearchIndex, "All"), str: `{"Operation":"GetBrowseNodes"}`},
69+
{q: NewGetBrowseNodes("", "", "").Request(SortBy, "AvgCustomerReviews"), str: `{"Operation":"GetBrowseNodes"}`},
70+
{q: NewGetBrowseNodes("", "", "").Request(Title, "foo"), str: `{"Operation":"GetBrowseNodes"}`},
71+
}
72+
73+
for _, tc := range testCases {
74+
if str := tc.q.String(); str != tc.str {
75+
t.Errorf("BrowseNodes.String() is \"%v\", want \"%v\"", str, tc.str)
76+
}
77+
}
78+
}
79+
80+
func TestResourcesInGetBrowseNodes(t *testing.T) {
81+
testCases := []struct {
82+
q *GetBrowseNodes
83+
str string
84+
}{
85+
{q: NewGetBrowseNodes("", "", "").EnableBrowseNodes(), str: `{"Operation":"GetBrowseNodes","Resources":["BrowseNodes.Ancestor","BrowseNodes.Children"]}`},
86+
}
87+
88+
for _, tc := range testCases {
89+
if str := tc.q.String(); str != tc.str {
90+
t.Errorf("Query.String() is \"%v\", want \"%v\"", str, tc.str)
91+
}
92+
}
93+
}
94+
95+
/* Copyright 2022 Spiegel and contributors
96+
*
97+
* Licensed under the Apache License, Version 2.0 (the "License");
98+
* you may not use this file except in compliance with the License.
99+
* You may obtain a copy of the License at
100+
*
101+
* http://www.apache.org/licenses/LICENSE-2.0
102+
*
103+
* Unless required by applicable law or agreed to in writing, software
104+
* distributed under the License is distributed on an "AS IS" BASIS,
105+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
106+
* See the License for the specific language governing permissions and
107+
* limitations under the License.
108+
*/

0 commit comments

Comments
 (0)