zanoxrb 0.2 → 0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +3 -0
- data/lib/zanox/api.rb +1 -2
- data/lib/zanox/response.rb +15 -4
- data/lib/zanox/version.rb +1 -1
- data/specs/products_spec.rb +43 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e259a4e6312026b1c4660963c4173c44a90b328c
|
4
|
+
data.tar.gz: 997286ec7075c92a64c4c84b59059fd4c981f4b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 661fdb1f33a9de6f8a5105673c5dac3efb30e4ba44dddb277394d3837b6fd9f6fc38891b8b2b3968b9eee412fa2553dc66104cd19be94be1325609b7df843c2e
|
7
|
+
data.tar.gz: 9889e8f69ec3b9c081487ece8fb8fad05fd9b41cb487ff5c12dbd33ebbcbd0d6ea680ee5fafbb5fe06053b0db7497348acc37b869f86db8cc072dd82a0e3b23d
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -19,4 +19,7 @@ To make requests to the APIs, call `Zanox::API#request` passing the endpoint of
|
|
19
19
|
|
20
20
|
Every call will return a native Ruby hash or an array reflecting the original documentation provided by Zanox (I plan to also wrap every response inside a class that allows to get every value following the Ruby-way, btw).
|
21
21
|
|
22
|
+
Note also that the pagination in Zanox APIs is 0-indexed. For example, if you want to get the second page of the requested products list you have to pass `page: 1` to the optional params, otherwise you'll get, of course, the first page that actually is referrable as `page: 0`.
|
23
|
+
Consider using `Zanox::Response#next_page` and `Zanox::Response#previous_page` to navigate through the pages.
|
24
|
+
|
22
25
|
For debugging purpose, consider also to enable info logs by executing `Zanox::API.debug!`.
|
data/lib/zanox/api.rb
CHANGED
@@ -58,8 +58,7 @@ module Zanox
|
|
58
58
|
logger.info "Params: #{options.inspect}"
|
59
59
|
logger.info "Headers: #{headers.inspect}"
|
60
60
|
response = get("/json/2011-03-01/#{method}", query: options, headers: headers)
|
61
|
-
Response.new(response)
|
62
|
-
end
|
61
|
+
Response.new(response, [method, options, headers]) end
|
63
62
|
end
|
64
63
|
end
|
65
64
|
end
|
data/lib/zanox/response.rb
CHANGED
@@ -26,8 +26,9 @@ module Zanox
|
|
26
26
|
class Response
|
27
27
|
attr_reader :response
|
28
28
|
|
29
|
-
def initialize(response)
|
30
|
-
@response
|
29
|
+
def initialize(response, original_params = [])
|
30
|
+
@response = response
|
31
|
+
@original_params = original_params
|
31
32
|
|
32
33
|
status_code = @response.parsed_response['code']
|
33
34
|
if status_code
|
@@ -39,8 +40,18 @@ module Zanox
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
|
-
def
|
43
|
-
@
|
43
|
+
def previous_page
|
44
|
+
if @original_params.length == 3
|
45
|
+
@original_params[1].merge!({ page: page - 1 })
|
46
|
+
API.request(*@original_params)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def next_page
|
51
|
+
if @original_params.length == 3
|
52
|
+
@original_params[1].merge!({ page: page + 1 })
|
53
|
+
API.request(*@original_params)
|
54
|
+
end
|
44
55
|
end
|
45
56
|
|
46
57
|
def inspect
|
data/lib/zanox/version.rb
CHANGED
data/specs/products_spec.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
describe Zanox::API do
|
2
2
|
describe '#request' do
|
3
|
-
|
4
|
-
|
3
|
+
before :each do
|
4
|
+
Zanox::API::Session.connect_id = '43EEF0445509C7205827'
|
5
|
+
end
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
end
|
7
|
+
context 'products with given keyword and programID' do
|
8
|
+
let(:products) { Zanox::API.request('products', q: 'nike', programs: 7408) }
|
9
9
|
|
10
10
|
it 'returns pagination infos' do
|
11
11
|
expect(products.page).to be 0
|
@@ -14,7 +14,7 @@ describe Zanox::API do
|
|
14
14
|
expect(products.query).to eq('nike')
|
15
15
|
end
|
16
16
|
|
17
|
-
it 'returns a list of products
|
17
|
+
it 'returns a list of products' do
|
18
18
|
items = products.product_items
|
19
19
|
|
20
20
|
expect(items).to be_an(Array)
|
@@ -24,5 +24,42 @@ describe Zanox::API do
|
|
24
24
|
expect(items.all? { |i| i['program']['@id'].to_i == 7408 }).to be_truthy
|
25
25
|
end
|
26
26
|
end
|
27
|
+
|
28
|
+
context 'products with given keyword and number of requested items per page' do
|
29
|
+
let(:products) { Zanox::API.request('products', q: 'nike', items: 50) }
|
30
|
+
|
31
|
+
it 'returns pagination infos' do
|
32
|
+
expect(products.page).to be 0
|
33
|
+
expect(products.items).to be 50
|
34
|
+
expect(products.total).to be > 100
|
35
|
+
expect(products.query).to eq('nike')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
# context 'products#next_page!' do
|
40
|
+
# let(:products) { Zanox::API.request('products', q: 'iPod', items: 50) }
|
41
|
+
#
|
42
|
+
# it 'move the paginator to the second page of the products list' do
|
43
|
+
# expect { products.next_page! }.to change { products.page }.from(0).to(1)
|
44
|
+
# end
|
45
|
+
# end
|
46
|
+
|
47
|
+
context 'products#next_page' do
|
48
|
+
let(:products) { Zanox::API.request('products', q: 'iPod', items: 50) }
|
49
|
+
|
50
|
+
it 'returns a new response containing the second page of the products list' do
|
51
|
+
expect(products.page).to be 0
|
52
|
+
expect(products.next_page.page).to be 1
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'products#previous_page' do
|
57
|
+
let(:products) { Zanox::API.request('products', q: 'nike', page: 3) }
|
58
|
+
|
59
|
+
it 'returns a new response containing the second page of the products list' do
|
60
|
+
expect(products.page).to be 3
|
61
|
+
expect(products.previous_page.page).to be 2
|
62
|
+
end
|
63
|
+
end
|
27
64
|
end
|
28
65
|
end
|