shutl_resource 0.9.1 → 0.9.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.
- data/.gitignore +1 -0
- data/.travis.yml +0 -2
- data/lib/shutl/resource/rest_class_methods.rb +24 -1
- data/lib/shutl/resource/version.rb +1 -1
- data/spec/rest_resource_spec.rb +12 -1
- metadata +5 -5
data/.travis.yml
CHANGED
@@ -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)
|
data/spec/rest_resource_spec.rb
CHANGED
@@ -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 =>
|
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.
|
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-
|
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:
|
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:
|
183
|
+
hash: 2302729883022750132
|
184
184
|
requirements: []
|
185
185
|
rubyforge_project:
|
186
|
-
rubygems_version: 1.8.
|
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
|