api-client 2.0.1 → 2.0.2

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.
@@ -109,14 +109,19 @@ module ApiClient
109
109
  @attributes
110
110
  end
111
111
 
112
- # Return an array with all instance variables setted through attr_accessor and its currently values.
112
+ # Return a hash with all instance variables setted through attr_accessor and its currently values.
113
113
  #
114
114
  # @return [Hash] instance variables and its values.
115
115
  def attributes
116
116
  self.class.instance_variable_get('@attributes').inject({}) { |hash, attribute| hash.merge(attribute.to_sym => self.send("#{attribute}")) }
117
117
  end
118
118
 
119
- alias_method :to_hash, :attributes
119
+ # Return a hash with a root node and all instance variables setted through attr_accessor and its currently values.
120
+ #
121
+ # @return [Hash] instance variables and its values.
122
+ def to_hash
123
+ { self.class.root_node.to_sym => attributes }
124
+ end
120
125
 
121
126
  # Initialize a collection of objects. The collection will be an ApiClient::Collection object.
122
127
  # The objects in the collection will be all instances of this (ApiClient::Base) class.
@@ -23,21 +23,21 @@ module ApiClient
23
23
 
24
24
  def post(header = {})
25
25
  url = "#{ApiClient.config.path}#{self.class.resource_path}"
26
- response = ApiClient::Dispatcher.post(url, self.attributes, header)
26
+ response = ApiClient::Dispatcher.post(url, self.to_hash, header)
27
27
  attributes = ApiClient::Parser.response(response, url)
28
28
  update_attributes(attributes)
29
29
  end
30
30
 
31
31
  def put(header = {})
32
32
  url = "#{ApiClient.config.path}#{self.class.resource_path}/#{id}"
33
- response = ApiClient::Dispatcher.put(url, self.attributes, header)
33
+ response = ApiClient::Dispatcher.put(url, self.to_hash, header)
34
34
  attributes = ApiClient::Parser.response(response, url)
35
35
  update_attributes(attributes)
36
36
  end
37
37
 
38
38
  def patch(header = {})
39
39
  url = "#{ApiClient.config.path}#{self.class.resource_path}/#{id}"
40
- response = ApiClient::Dispatcher.post(url, self.attributes, header)
40
+ response = ApiClient::Dispatcher.post(url, self.to_hash, header)
41
41
  attributes = ApiClient::Parser.response(response, url)
42
42
  update_attributes(attributes)
43
43
  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.0.1'
4
+ VERSION = '2.0.2'
5
5
  end
@@ -140,6 +140,12 @@ describe ApiClient::Base do
140
140
  end
141
141
  end
142
142
 
143
+ describe '#to_hash' do
144
+ it 'should return a hash with root node and the attributes and its currently values' do
145
+ User.new.to_hash.should == { :user => { :a => nil, :b => nil } }
146
+ end
147
+ end
148
+
143
149
  describe '.collection' do
144
150
  before :each do
145
151
  ApiClient::Collection.stub(:new).with(User, 'users').and_return(collection)
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.0.1
4
+ version: 2.0.2
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-06-13 00:00:00.000000000 Z
12
+ date: 2013-06-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -194,7 +194,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
194
194
  version: '0'
195
195
  segments:
196
196
  - 0
197
- hash: 4514506961521743435
197
+ hash: 725018755031888977
198
198
  required_rubygems_version: !ruby/object:Gem::Requirement
199
199
  none: false
200
200
  requirements:
@@ -203,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
203
  version: '0'
204
204
  segments:
205
205
  - 0
206
- hash: 4514506961521743435
206
+ hash: 725018755031888977
207
207
  requirements: []
208
208
  rubyforge_project:
209
209
  rubygems_version: 1.8.25