rest-api-client 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 827704749a537c472c97a42f83e3feafdf49bcfc
4
- data.tar.gz: bd7ba4f50e0015d3ee78615b096d0543c87ceaf0
3
+ metadata.gz: 59133c4029009610c9c5723b460742ad133c8f5d
4
+ data.tar.gz: 1c2fdf79a75dffbfb13aeb05adc7864878ce01a4
5
5
  SHA512:
6
- metadata.gz: d6b4f54b9fef9368390c6700458e37f33e10f50b13e48277af0c7009a86669897a529c7350420010bfa7cf76bd6c8eb4385b2a5cb14b5a8623c83959390b38cd
7
- data.tar.gz: fb87647b9dc66eaa109c9ee296023d22792449f63291ecdd56e3aecf2c478cace64c02451c790e97b615c91384d1ebb3fc2f2fd49015c925b3e8487b75bf8ec0
6
+ metadata.gz: 273f0902c798dd6beda3f49fa8674df4f2d96d2ecd7383e8e706ce26543f7bf5b939f1121a692588c932e9d7cb9a5950a1f99035cc7b0b200729d3c9211e2af2
7
+ data.tar.gz: f3fdd1c5fb7288efee765521c96e7a8c0a3a6efd7ab0e284eee7b304eabb5997043981d937168dbf158882e5b0215d168a39016e096955b2932421f7c3f90377
data/.gitignore CHANGED
File without changes
data/.rspec CHANGED
File without changes
data/.travis.yml CHANGED
File without changes
data/Gemfile CHANGED
File without changes
data/LICENSE.txt CHANGED
File without changes
data/README.md CHANGED
File without changes
data/Rakefile CHANGED
File without changes
data/bin/console CHANGED
File without changes
data/bin/setup CHANGED
File without changes
File without changes
File without changes
@@ -14,11 +14,11 @@ module RestApiClient
14
14
  end
15
15
 
16
16
  if json_data.kind_of?(Array)
17
- return json_data.map { |data| data_type.new data } if data_type
17
+ return json_data.map { |data| self.build_instance data_type, data } if data_type
18
18
  return json_data unless json_data.empty?
19
19
 
20
20
  elsif json_data.kind_of?(Hash)
21
- return data_type.new json_data if data_type
21
+ return self.build_instance data_type, json_data if data_type
22
22
  return json_data unless json_data.empty?
23
23
 
24
24
  else
@@ -31,4 +31,33 @@ module RestApiClient
31
31
  end
32
32
  end
33
33
 
34
+ private
35
+
36
+ # Set the instance attributes values.
37
+ # If the instance have associations, the value of these associations will be an empty object, or an object with his id
38
+ # when the instance data contains a "object_id" key
39
+ def self.build_instance(data_type, instance_data)
40
+ instance = data_type.new
41
+ instance_data.each do |key, value|
42
+
43
+ begin
44
+ if key.end_with? '_id'
45
+ key_without_id = key.gsub('_id', '')
46
+ if instance.respond_to?(key_without_id)
47
+ key = key_without_id
48
+ value = Object::const_get("#{data_type.parent}::" + key_without_id.camelize).new(:id => value)
49
+ end
50
+ end
51
+
52
+ if value.is_a?(Hash)
53
+ value = Object::const_get("#{data_type.parent}::" + key.camelize).new(value)
54
+ end
55
+ rescue Exception => e
56
+ # ignored
57
+ end
58
+
59
+ instance.instance_variable_set("@#{key}", value)
60
+ end
61
+ instance
62
+ end
34
63
  end
File without changes
File without changes
@@ -1,3 +1,3 @@
1
1
  module RestApiClient
2
- VERSION = '0.1.9'
2
+ VERSION = '0.1.10'
3
3
  end
File without changes
File without changes
File without changes
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.9
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2015-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -210,8 +210,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  version: '0'
211
211
  requirements: []
212
212
  rubyforge_project:
213
- rubygems_version: 2.2.2
213
+ rubygems_version: 2.4.8
214
214
  signing_key:
215
215
  specification_version: 4
216
216
  summary: rest-api-client
217
217
  test_files: []
218
+ has_rdoc: