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.
@@ -1,10 +1,23 @@
1
- rvm:
2
- - 1.8.7
3
- - 1.9.2
4
- - 1.9.3
5
- - jruby
6
- - ree
7
- gemfile:
8
- - gemfiles/Gemfile.net_http
9
- - gemfiles/Gemfile.typhoeus
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
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v2.5.0
4
+
5
+ * Add support for parallel requests. Yay! =)
6
+
3
7
  ## v2.4.0
4
8
 
5
9
  * Add support to multiple api entry points.
data/README.md CHANGED
@@ -177,7 +177,6 @@ end
177
177
  ## Mantainers
178
178
  [@plribeiro3000](https://github.com/plribeiro3000)
179
179
 
180
-
181
180
  ## Contributing
182
181
 
183
182
  1. Fork it
@@ -0,0 +1,6 @@
1
+ source :rubygems
2
+
3
+ gem 'activesupport', '>= 3.0', '< 4'
4
+ gem 'mime-types', '< 2.0'
5
+
6
+ gemspec :path => '../'
@@ -1,6 +1,6 @@
1
1
  source :rubygems
2
2
 
3
- gem 'typhoeus'
3
+ gem 'typhoeus', '>= 0.5.0'
4
4
 
5
5
  gem 'activesupport', '>= 3.0', '< 4'
6
6
 
@@ -0,0 +1,7 @@
1
+ source :rubygems
2
+
3
+ gem 'typhoeus', '>= 0.5.0'
4
+ gem 'mime-types', '< 2.0'
5
+ gem 'activesupport', '>= 3.0', '< 4'
6
+
7
+ gemspec :path => '../'
@@ -2,32 +2,44 @@
2
2
  class ApiClient::Collection < Array
3
3
  # Initialize a collection of objects based on attributes.
4
4
  #
5
- # @param [String] attributes the array of attributes.
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
- if attributes.instance_of?(Array)
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 [String] attributes the array of attributes.
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
@@ -1,5 +1,5 @@
1
1
  # High Level Namespace of the library ApiClient.
2
2
  module ApiClient
3
3
  # Version of the library.
4
- VERSION = '2.5.0'
4
+ VERSION = '2.6.0'
5
5
  end
@@ -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.5.0
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-09-16 00:00:00.000000000 Z
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: 4058944769664013271
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: 4058944769664013271
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