api-client 2.5.0 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +22 -9
- data/CHANGELOG.md +4 -0
- data/README.md +0 -1
- data/gemfiles/Gemfile.net_http_mime-types +6 -0
- data/gemfiles/Gemfile.typhoeus +1 -1
- data/gemfiles/Gemfile.typhoeus_mime-types +7 -0
- data/lib/api-client/collection.rb +21 -9
- data/lib/api-client/version.rb +1 -1
- data/spec/api-client/collection_spec.rb +18 -0
- metadata +8 -4
data/.travis.yml
CHANGED
@@ -1,10 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
matrix:
|
2
|
+
include:
|
3
|
+
- rvm: 1.8.7
|
4
|
+
gemfile: gemfiles/Gemfile.net_http_mime-types
|
5
|
+
- rvm: 1.8.7
|
6
|
+
gemfile: gemfiles/Gemfile.typhoeus_mime-types
|
7
|
+
- rvm: 1.9.2
|
8
|
+
gemfile: gemfiles/Gemfile.net_http
|
9
|
+
- rvm: 1.9.2
|
10
|
+
gemfile: gemfiles/Gemfile.typhoeus
|
11
|
+
- rvm: 1.9.3
|
12
|
+
gemfile: gemfiles/Gemfile.net_http
|
13
|
+
- rvm: 1.9.3
|
14
|
+
gemfile: gemfiles/Gemfile.typhoeus
|
15
|
+
- rvm: jruby
|
16
|
+
gemfile: gemfiles/Gemfile.net_http
|
17
|
+
- rvm: jruby
|
18
|
+
gemfile: gemfiles/Gemfile.typhoeus
|
19
|
+
- rvm: ree
|
20
|
+
gemfile: gemfiles/Gemfile.net_http_mime-types
|
21
|
+
- rvm: ree
|
22
|
+
gemfile: gemfiles/Gemfile.typhoeus_mime-types
|
10
23
|
install: bundle install --without developer
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
data/gemfiles/Gemfile.typhoeus
CHANGED
@@ -2,32 +2,44 @@
|
|
2
2
|
class ApiClient::Collection < Array
|
3
3
|
# Initialize a collection of objects based on attributes.
|
4
4
|
#
|
5
|
-
# @param [
|
5
|
+
# @param [Hash/Array] the hash or array of attributes.
|
6
6
|
# @param [Class] klass The class to instantiate the objects.
|
7
7
|
# @return [Collection] the collection of objects.
|
8
8
|
def initialize(attributes, klass)
|
9
9
|
@klass = klass
|
10
|
-
|
11
|
-
attributes.each do |attr|
|
12
|
-
self << @klass.new(attr)
|
13
|
-
end
|
14
|
-
else
|
15
|
-
self << @klass.new(attributes)
|
16
|
-
end
|
10
|
+
update(attributes)
|
17
11
|
end
|
18
12
|
|
19
13
|
# Update the collection of objects based on the new attributes.
|
20
14
|
#
|
21
|
-
# @param [
|
15
|
+
# @param [Hash/Array] the hash or array of attributes.
|
22
16
|
# @return [Collection] the collection of objects.
|
23
17
|
def update(attributes)
|
24
18
|
self.clear
|
19
|
+
@response = attributes
|
25
20
|
if attributes.instance_of?(Array)
|
26
21
|
attributes.each do |attr|
|
27
22
|
self << @klass.new(attr)
|
28
23
|
end
|
24
|
+
elsif attributes[@klass.name.pluralize.downcase].instance_of?(Array)
|
25
|
+
attributes = pagination_attributes(attributes)
|
26
|
+
attributes[@klass.name.pluralize.downcase].each do |attr|
|
27
|
+
self << @klass.new(attr)
|
28
|
+
end
|
29
29
|
else
|
30
30
|
self << @klass.new(attributes)
|
31
31
|
end
|
32
32
|
end
|
33
|
+
|
34
|
+
# Initialize some variables based on attributes.
|
35
|
+
#
|
36
|
+
# @param [Hash] the hash of attributes.
|
37
|
+
# @return [Hash] the hash of attributes without pagination attributes.
|
38
|
+
def pagination_attributes(attributes)
|
39
|
+
@total = attributes.delete("total")
|
40
|
+
@total_pages = attributes.delete("total_pages")
|
41
|
+
@offset = attributes.delete("offset")
|
42
|
+
@_links = attributes.delete("_links")
|
43
|
+
attributes
|
44
|
+
end
|
33
45
|
end
|
data/lib/api-client/version.rb
CHANGED
@@ -8,6 +8,17 @@ describe ApiClient::Collection do
|
|
8
8
|
ApiClient::Collection.new([], User).instance_variable_get('@klass').should == User
|
9
9
|
end
|
10
10
|
|
11
|
+
context 'with a hash of attributes' do
|
12
|
+
before :each do
|
13
|
+
attributes = { 'users' => [ { :user => { :a => 'a' } }, { :user => { :b => 'b' } } ] }
|
14
|
+
@collection = ApiClient::Collection.new(attributes, User)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should initialize a collection of objects' do
|
18
|
+
@collection.size.should == 2
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
11
22
|
context 'with a collection of attributes' do
|
12
23
|
before :each do
|
13
24
|
attributes = [ { :user => { :a => 'a' } }, { :user => { :b => 'b' } } ]
|
@@ -36,6 +47,13 @@ describe ApiClient::Collection do
|
|
36
47
|
attributes = [ { :user => { :a => 'a' } }, { :user => { :b => 'b' } } ]
|
37
48
|
@collection = ApiClient::Collection.new(attributes, User)
|
38
49
|
end
|
50
|
+
|
51
|
+
context 'with a hash of attributes' do
|
52
|
+
it 'Should update the collection with new objects based on the attributes' do
|
53
|
+
@collection.update({ 'users' => [ { :user => { :a => 'a' } }, { :user => { :b => 'b' } } ] }).size.should == 2
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
39
57
|
context 'with a collection of attributes' do
|
40
58
|
it 'Should update the collection with new objects based on the attributes' do
|
41
59
|
@collection.update([ { :user => { :a => 'a' } }, { :user => { :b => 'b' } } ]).size.should == 2
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-11-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -151,7 +151,9 @@ files:
|
|
151
151
|
- examples/models/user.rb
|
152
152
|
- examples/scripts/example.rb
|
153
153
|
- gemfiles/Gemfile.net_http
|
154
|
+
- gemfiles/Gemfile.net_http_mime-types
|
154
155
|
- gemfiles/Gemfile.typhoeus
|
156
|
+
- gemfiles/Gemfile.typhoeus_mime-types
|
155
157
|
- lib/api-client.rb
|
156
158
|
- lib/api-client/base.rb
|
157
159
|
- lib/api-client/class_methods.rb
|
@@ -202,7 +204,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
202
204
|
version: '0'
|
203
205
|
segments:
|
204
206
|
- 0
|
205
|
-
hash:
|
207
|
+
hash: 2568135155809841734
|
206
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
209
|
none: false
|
208
210
|
requirements:
|
@@ -211,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
213
|
version: '0'
|
212
214
|
segments:
|
213
215
|
- 0
|
214
|
-
hash:
|
216
|
+
hash: 2568135155809841734
|
215
217
|
requirements: []
|
216
218
|
rubyforge_project:
|
217
219
|
rubygems_version: 1.8.25
|
@@ -230,7 +232,9 @@ test_files:
|
|
230
232
|
- examples/models/user.rb
|
231
233
|
- examples/scripts/example.rb
|
232
234
|
- gemfiles/Gemfile.net_http
|
235
|
+
- gemfiles/Gemfile.net_http_mime-types
|
233
236
|
- gemfiles/Gemfile.typhoeus
|
237
|
+
- gemfiles/Gemfile.typhoeus_mime-types
|
234
238
|
- spec/api-client/base_spec.rb
|
235
239
|
- spec/api-client/class_methods_spec.rb
|
236
240
|
- spec/api-client/collection_spec.rb
|