shutl_resource 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -65,13 +65,25 @@ module Shutl::Resource
65
65
  end
66
66
 
67
67
  def parsed
68
- response.parsed_response
68
+ @parsed ||= response.body.with_indifferent_access
69
69
  end
70
70
 
71
71
  def status
72
72
  response.code
73
73
  end
74
74
 
75
+ def pagination
76
+ parsed[:pagination]
77
+ end
78
+
79
+ def next_resource
80
+ pagination[:next_resource] if pagination
81
+ end
82
+
83
+ def previous_resource
84
+ pagination[:previous_resource] if pagination
85
+ end
86
+
75
87
  attr_accessor :errors
76
88
 
77
89
  def valid?
@@ -1,5 +1,5 @@
1
1
  module Shutl
2
2
  module Resource
3
- VERSION = '1.1.1'
3
+ VERSION = '1.2.0'
4
4
  end
5
5
  end
@@ -44,6 +44,52 @@ describe Shutl::Resource::Rest do
44
44
  end
45
45
  end
46
46
 
47
+ context 'pagination' do
48
+ let(:body) do
49
+ {
50
+ test_rest: { a: "a", b: 2 },
51
+ pagination: pagination
52
+ }.to_json
53
+ end
54
+ let(:pagination) { {previous_resource: 1, next_resource: 3} }
55
+
56
+ before do
57
+ @request = stub_request(:get, 'http://host/test_rests/a').
58
+ to_return(:status => 200, :body => body, :headers => headers)
59
+ end
60
+
61
+ context 'both present' do
62
+ specify do
63
+ resource = TestRest.find('a', auth: "some auth")
64
+ resource.previous_resource.should == 1
65
+ resource.next_resource .should == 3
66
+ end
67
+ end
68
+
69
+ context 'one present' do
70
+ let(:pagination) { {next_resource: 3} }
71
+ specify do
72
+ resource = TestRest.find('a', auth: "some auth")
73
+ resource.previous_resource.should be_nil
74
+ resource.next_resource .should == 3
75
+ end
76
+ end
77
+
78
+ context 'none present' do
79
+ let(:body) do
80
+ {
81
+ test_rest: { a: "a", b: 2 }
82
+ }.to_json
83
+ end
84
+ specify do
85
+ resource = TestRest.find('a', auth: "some auth")
86
+ resource.pagination .should be_nil
87
+ resource.previous_resource.should be_nil
88
+ resource.next_resource .should be_nil
89
+ end
90
+ end
91
+ end
92
+
47
93
  context 'with no arguments' do
48
94
  let(:headers_with_auth) do
49
95
  headers.merge("Authorization" => "Bearer some auth")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shutl_resource
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-08-19 00:00:00.000000000 Z
14
+ date: 2013-08-21 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty
@@ -221,15 +221,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
221
221
  - - ! '>='
222
222
  - !ruby/object:Gem::Version
223
223
  version: '0'
224
+ segments:
225
+ - 0
226
+ hash: 4547288023567173599
224
227
  required_rubygems_version: !ruby/object:Gem::Requirement
225
228
  none: false
226
229
  requirements:
227
230
  - - ! '>='
228
231
  - !ruby/object:Gem::Version
229
232
  version: '0'
233
+ segments:
234
+ - 0
235
+ hash: 4547288023567173599
230
236
  requirements: []
231
237
  rubyforge_project:
232
- rubygems_version: 1.8.23
238
+ rubygems_version: 1.8.25
233
239
  signing_key:
234
240
  specification_version: 3
235
241
  summary: Manage Shutl Rest resource. Parse/Serialize JSON