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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1dd9f08ace2ce5f98f28b96a2d844abb3e2f152f
4
- data.tar.gz: b3ceb6ac205b0d431bc9f0eb504e6a3700812891
3
+ metadata.gz: e259a4e6312026b1c4660963c4173c44a90b328c
4
+ data.tar.gz: 997286ec7075c92a64c4c84b59059fd4c981f4b7
5
5
  SHA512:
6
- metadata.gz: 2db51f310649d9a5881ed495879d8eb074bb1bc5dcebb15356d24062c7d1330ee69ac04a6a73ccabadeffc34fe606d5d54026b79945011785312882f2f207140
7
- data.tar.gz: fe6900a5666f4ea39bf4957297c7d9045f19712e22cded574e3bef974676e81c550f8e9d4f529cf0519572b6aad705c4345577e358f44be3e8d315d9470d6b7f
6
+ metadata.gz: 661fdb1f33a9de6f8a5105673c5dac3efb30e4ba44dddb277394d3837b6fd9f6fc38891b8b2b3968b9eee412fa2553dc66104cd19be94be1325609b7df843c2e
7
+ data.tar.gz: 9889e8f69ec3b9c081487ece8fb8fad05fd9b41cb487ff5c12dbd33ebbcbd0d6ea680ee5fafbb5fe06053b0db7497348acc37b869f86db8cc072dd82a0e3b23d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- zanoxrb (0.2)
4
+ zanoxrb (0.3)
5
5
  httparty (~> 0.13)
6
6
 
7
7
  GEM
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
@@ -26,8 +26,9 @@ module Zanox
26
26
  class Response
27
27
  attr_reader :response
28
28
 
29
- def initialize(response)
30
- @response = 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 response
43
- @response.parsed_response
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
@@ -23,5 +23,5 @@
23
23
  #++
24
24
 
25
25
  module Zanox
26
- VERSION = '0.2'
26
+ VERSION = '0.3'
27
27
  end
@@ -1,11 +1,11 @@
1
1
  describe Zanox::API do
2
2
  describe '#request' do
3
- context 'products' do
4
- let(:products) { Zanox::API.request('products', q: 'nike', programs: 7408) }
3
+ before :each do
4
+ Zanox::API::Session.connect_id = '43EEF0445509C7205827'
5
+ end
5
6
 
6
- before :each do
7
- Zanox::API::Session.connect_id = '43EEF0445509C7205827'
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 with given keyword and program' do
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zanoxrb
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.2'
4
+ version: '0.3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giovanni Capuano