shutl_resource 0.9.1 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  .pkg
7
7
 
8
8
  .vendor
9
+ .idea
9
10
 
10
11
  vendor
11
12
 
data/.travis.yml CHANGED
@@ -3,7 +3,6 @@ language: ruby
3
3
  rvm:
4
4
  - 1.9.2
5
5
  - 1.9.3
6
- - jruby-18mode
7
6
  - jruby-19mode
8
7
 
9
8
  jdk:
@@ -12,6 +11,5 @@ jdk:
12
11
 
13
12
  matrix:
14
13
  allow_failures:
15
- - rvm: jruby-18mode
16
14
  - rvm: jruby-19mode
17
15
 
@@ -76,9 +76,32 @@ module Shutl::Resource
76
76
 
77
77
  check_fail response, "Failed to find all #{name.downcase.pluralize}"
78
78
 
79
- response.parsed_response[@resource_name.pluralize].map do |h|
79
+ response_object = response.parsed_response[@resource_name.pluralize].map do |h|
80
80
  new_object(args.merge(h), response)
81
81
  end
82
+ RestCollection.new(response_object, response.parsed_response['pagination'])
83
+ end
84
+
85
+ class RestCollection
86
+ include Enumerable
87
+
88
+ attr_reader :collection
89
+
90
+ def initialize(collection, pagination)
91
+ @collection = collection
92
+ @pagination = pagination
93
+ end
94
+
95
+ delegate :each, to: :collection
96
+
97
+ class Pagination < Struct.new(:page, :size, :total); end
98
+
99
+ def pagination
100
+ return unless @pagination
101
+ Pagination.new(@pagination['page'],
102
+ @pagination['size'],
103
+ @pagination['total'])
104
+ end
82
105
  end
83
106
 
84
107
  def resource_name(name)
@@ -1,5 +1,5 @@
1
1
  module Shutl
2
2
  module Resource
3
- VERSION = '0.9.1'
3
+ VERSION = '0.9.3'
4
4
  end
5
5
  end
@@ -110,8 +110,12 @@ describe Shutl::Resource::Rest do
110
110
 
111
111
  context 'with no arguments' do
112
112
  before do
113
+ body = '{
114
+ "test_rests": [{ "a": "a", "b": 2 }],
115
+ "pagination":{"page": 0,"size": 1,"total": 3}
116
+ }'
113
117
  @request = stub_request(:get, 'http://host/test_rests').
114
- to_return(:status => 200, :body => '{"test_rests": [{ "a": "a", "b": 2 }]}', :headers => headers)
118
+ to_return(:status => 200, :body => body, :headers => headers)
115
119
  end
116
120
 
117
121
  it 'should query the endpoint' do
@@ -133,6 +137,13 @@ describe Shutl::Resource::Rest do
133
137
  resource.first.instance_variable_get('@b').should == 2
134
138
  end
135
139
 
140
+ it 'should provide accessor to pagination' do
141
+ resource = TestRest.all
142
+ resource.pagination.page .should == 0
143
+ resource.pagination.size .should == 1
144
+ resource.pagination.total.should == 3
145
+ end
146
+
136
147
  it 'should raise an error of the request fails' do
137
148
  stub_request(:get, 'http://host/test_rests').
138
149
  to_return(:status => 403)
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: 0.9.1
4
+ version: 0.9.3
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-06-06 00:00:00.000000000 Z
14
+ date: 2013-06-12 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: httparty
@@ -171,7 +171,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
171
171
  version: '0'
172
172
  segments:
173
173
  - 0
174
- hash: -2342184030793928483
174
+ hash: 2302729883022750132
175
175
  required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  none: false
177
177
  requirements:
@@ -180,10 +180,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  version: '0'
181
181
  segments:
182
182
  - 0
183
- hash: -2342184030793928483
183
+ hash: 2302729883022750132
184
184
  requirements: []
185
185
  rubyforge_project:
186
- rubygems_version: 1.8.23
186
+ rubygems_version: 1.8.24
187
187
  signing_key:
188
188
  specification_version: 3
189
189
  summary: Manage Shutl Rest resource. Parse/Serialize JSON