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 +4 -4
- data/lib/ruby_json_api_client/adapters/rest_adapter.rb +2 -0
- data/lib/ruby_json_api_client/base.rb +14 -2
- data/lib/ruby_json_api_client/serializers/ams_serializer.rb +1 -0
- data/lib/ruby_json_api_client/store.rb +3 -3
- data/lib/ruby_json_api_client/version.rb +1 -1
- data/ruby_json_api_client.gemspec +2 -2
- data/spec/integration/ams/find_spec.rb +20 -0
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f4e6eb4c43b49c31d386896c2cb60215170ef95
|
4
|
+
data.tar.gz: a97568320d8f72ed8d8df21cbbab841cde5afe05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ece60e0cdd009e363086a9853d936af57f76ed7c14b124b88c34ef9f27abd91a660842ef0ae91c042bd4a567869312021df9ea866acef8510900722a675ae1b
|
7
|
+
data.tar.gz: dd90e2e84644c5f5cffe5682fd204db7cafa8cad6e25f8092edbb1e6c0907cc116d8a48da1eae661abd699365846c528e8fc68812b7dcd710c0cb4891876ee74
|
@@ -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
|
-
|
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
|
@@ -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 =
|
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 =
|
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
|
@@ -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', '
|
26
|
-
spec.add_dependency 'activesupport', '>=
|
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.
|
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-
|
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:
|
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:
|
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:
|
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:
|
96
|
+
version: 3.2.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: bundler
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|