ruby_json_api_client 0.0.5 → 0.0.6

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: 57562295d40944d05a5a968202b18de928e2795d
4
- data.tar.gz: 2335779d94b2e907583e702ea7c20c9f6b66562a
3
+ metadata.gz: 5f4e6eb4c43b49c31d386896c2cb60215170ef95
4
+ data.tar.gz: a97568320d8f72ed8d8df21cbbab841cde5afe05
5
5
  SHA512:
6
- metadata.gz: b7919a394bebcd504e2ad00ed689bf8c85e2f25808eb4b8a77bd6ed0f6fdb7c14545328cc39b331c1e7b50208575d18c774a96d0590915e6eeeecf2ccfd4769d
7
- data.tar.gz: ca80f7170e0f192fbcad2dcc068ee55891a283d88d2a5d373254bf804726d5c90baafb9e3e9c956cf3409d31dd909f7886b9116a0cc02a07d58f03569fdd41c8
6
+ metadata.gz: 4ece60e0cdd009e363086a9853d936af57f76ed7c14b124b88c34ef9f27abd91a660842ef0ae91c042bd4a567869312021df9ea866acef8510900722a675ae1b
7
+ data.tar.gz: dd90e2e84644c5f5cffe5682fd204db7cafa8cad6e25f8092edbb1e6c0907cc116d8a48da1eae661abd699365846c528e8fc68812b7dcd710c0cb4891876ee74
@@ -61,6 +61,8 @@ module RubyJsonApiClient
61
61
 
62
62
  if status >= 200 && status <= 299
63
63
  body
64
+ elsif status == 404
65
+ nil
64
66
  else
65
67
  raise "Could not find #{klass.name} with id #{id}"
66
68
  end
@@ -1,9 +1,13 @@
1
1
  require 'active_model'
2
- require 'active_support'
2
+ require 'active_support/all'
3
3
 
4
4
  module RubyJsonApiClient
5
5
  class Base
6
- include ActiveModel::Model
6
+ extend ActiveModel::Naming
7
+ extend ActiveModel::Translation
8
+ include ActiveModel::Validations
9
+ include ActiveModel::Conversion
10
+
7
11
  include ActiveModel::AttributeMethods
8
12
  include ActiveModel::Serialization
9
13
 
@@ -11,6 +15,14 @@ module RubyJsonApiClient
11
15
  include ActiveModel::SerializerSupport
12
16
  end
13
17
 
18
+ def initialize(params={})
19
+ params.each do |attr, value|
20
+ self.public_send("#{attr}=", value)
21
+ end if params
22
+
23
+ super()
24
+ end
25
+
14
26
  def self.field(name, type = :string)
15
27
  fields << name
16
28
  attr_accessor name
@@ -84,6 +84,7 @@ module RubyJsonApiClient
84
84
  end
85
85
 
86
86
  def extract_single(klass, id, response)
87
+ return nil if response.nil?
87
88
  name = klass.to_s.underscore
88
89
  data = transform(response)
89
90
 
@@ -8,7 +8,7 @@ module RubyJsonApiClient
8
8
  # klass is options. autoamtically figure out klass and set options
9
9
  temp = klass || options
10
10
  class_name = name.to_s.camelize
11
- klass = Kernel.const_get("RubyJsonApiClient::#{class_name}Adapter")
11
+ klass = "RubyJsonApiClient::#{class_name}Adapter".constantize
12
12
  options = temp
13
13
  end
14
14
 
@@ -23,7 +23,7 @@ module RubyJsonApiClient
23
23
  # klass is options. autoamtically figure out klass and set options
24
24
  temp = klass || options
25
25
  class_name = name.to_s.camelize
26
- klass = Kernel.const_get("RubyJsonApiClient::#{class_name}Serializer")
26
+ klass = "RubyJsonApiClient::#{class_name}Serializer".constantize
27
27
  options = temp
28
28
  end
29
29
 
@@ -82,7 +82,7 @@ module RubyJsonApiClient
82
82
  serializer = serializer_for_class(klass)
83
83
 
84
84
  response = adapter.find(klass, id)
85
- serializer.extract_single(klass, id, response).tap do |model|
85
+ serializer.extract_single(klass, id, response).try(:tap) do |model|
86
86
  model.__origin__ = response
87
87
  end
88
88
  end
@@ -1,3 +1,3 @@
1
1
  module RubyJsonApiClient
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency 'faraday', '>= 0.9.0'
23
23
  spec.add_dependency 'faraday_middleware', '>= 0.9.0'
24
24
  spec.add_dependency 'addressable', '>= 2.3.6'
25
- spec.add_dependency 'activemodel', '>= 4.0'
26
- spec.add_dependency 'activesupport', '>= 4.0'
25
+ spec.add_dependency 'activemodel', '~> 3.2.0'
26
+ spec.add_dependency 'activesupport', '>= 3.2.0'
27
27
 
28
28
  spec.add_development_dependency "bundler", "~> 1.6"
29
29
  spec.add_development_dependency "rake"
@@ -42,5 +42,25 @@ describe "AMS find single" do
42
42
  its(:full_name) { should eq("ryan test") }
43
43
  end
44
44
  end
45
+ context "it does not exists" do
46
+ before(:each) do
47
+ response = {
48
+ }
49
+
50
+ json = response.to_json
51
+
52
+ stub_request(:get, "https://www.example.com/testing/people/404")
53
+ .to_return(
54
+ status: 404,
55
+ headers: { 'Content-Length' => json.size },
56
+ body: json,
57
+ )
58
+ end
59
+
60
+ context "returns nil" do
61
+ subject { Person.find(404) }
62
+ it { should be_nil }
63
+ end
64
+ end
45
65
  end
46
66
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_json_api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Toronto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-31 00:00:00.000000000 Z
11
+ date: 2014-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -70,30 +70,30 @@ dependencies:
70
70
  name: activemodel
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '4.0'
75
+ version: 3.2.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '4.0'
82
+ version: 3.2.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: activesupport
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '4.0'
89
+ version: 3.2.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '4.0'
96
+ version: 3.2.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: bundler
99
99
  requirement: !ruby/object:Gem::Requirement