json_api_client 1.0.0.beta3 → 1.0.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/json_api_client/helpers/associable.rb +4 -8
- data/lib/json_api_client/helpers/dynamic_attributes.rb +0 -1
- data/lib/json_api_client/helpers/initializable.rb +2 -2
- data/lib/json_api_client/helpers/linkable.rb +2 -2
- data/lib/json_api_client/helpers/paginatable.rb +1 -1
- data/lib/json_api_client/helpers/parsable.rb +1 -1
- data/lib/json_api_client/helpers/queryable.rb +1 -1
- data/lib/json_api_client/helpers/relatable.rb +2 -2
- data/lib/json_api_client/helpers/requestable.rb +1 -1
- data/lib/json_api_client/helpers/serializable.rb +11 -13
- data/lib/json_api_client/included_data.rb +1 -1
- data/lib/json_api_client/query/builder.rb +10 -2
- data/lib/json_api_client/query/requestor.rb +2 -2
- data/lib/json_api_client/relationships/relations.rb +6 -0
- data/lib/json_api_client/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6a4cf7888d664d4668f98705059cdffcead9c2b7
|
4
|
+
data.tar.gz: 454e3c488bbcfe07799ecdbb7bb721a6c62801e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb67e1ab20c2cd63d2aeaa72a2b2ff7682d9d34fd82303a9acbe62c1ad535a5606cbacf0e35c8503a7e89c9726f13681c38b5603ad77f174c8e4ea587aae4311
|
7
|
+
data.tar.gz: 609d93e6f8c0b63fb04bd4215a1e996085e8ecada6b4620a3591f764e75c47493e1fb483a15f6e8b582518b408aa2d80196084c7cc5e669bcdc17a9ba974df77
|
@@ -4,7 +4,7 @@ module JsonApiClient
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
class_attribute :associations
|
7
|
+
class_attribute :associations, instance_accessor: false
|
8
8
|
self.associations = []
|
9
9
|
|
10
10
|
include Associations::BelongsTo
|
@@ -30,12 +30,8 @@ module JsonApiClient
|
|
30
30
|
def path(params = nil)
|
31
31
|
parts = [table_name]
|
32
32
|
if params
|
33
|
-
|
34
|
-
|
35
|
-
prefix_params.each do |param|
|
36
|
-
filters.delete(param)
|
37
|
-
end
|
38
|
-
parts.unshift(prefix_path % slurp.symbolize_keys)
|
33
|
+
path_params = params.delete(:path) || params
|
34
|
+
parts.unshift(prefix_path % path_params.symbolize_keys)
|
39
35
|
else
|
40
36
|
parts.unshift(prefix_path)
|
41
37
|
end
|
@@ -49,7 +45,7 @@ module JsonApiClient
|
|
49
45
|
protected
|
50
46
|
|
51
47
|
def load_associations(params)
|
52
|
-
associations.each do |association|
|
48
|
+
self.class.associations.each do |association|
|
53
49
|
if params.has_key?(association.attr_name.to_s)
|
54
50
|
set_attribute(association.attr_name, association.parse(params[association.attr_name.to_s]))
|
55
51
|
end
|
@@ -4,7 +4,7 @@ module JsonApiClient
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
class_attribute :initializers
|
7
|
+
class_attribute :initializers, instance_accessor: false
|
8
8
|
self.initializers = []
|
9
9
|
end
|
10
10
|
|
@@ -15,7 +15,7 @@ module JsonApiClient
|
|
15
15
|
end
|
16
16
|
|
17
17
|
def initialize(params = {})
|
18
|
-
initializers.each do |initializer|
|
18
|
+
self.class.initializers.each do |initializer|
|
19
19
|
if initializer.respond_to?(:call)
|
20
20
|
initializer.call(self, params)
|
21
21
|
else
|
@@ -4,7 +4,7 @@ module JsonApiClient
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
class_attribute :linker
|
7
|
+
class_attribute :linker, instance_accessor: false
|
8
8
|
self.linker = Linking::Links
|
9
9
|
|
10
10
|
# the links for this resource
|
@@ -13,7 +13,7 @@ module JsonApiClient
|
|
13
13
|
initializer do |obj, params|
|
14
14
|
links = params && params.delete("links")
|
15
15
|
links ||= {}
|
16
|
-
obj.links = obj.linker.new(links)
|
16
|
+
obj.links = obj.class.linker.new(links)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -8,7 +8,7 @@ module JsonApiClient
|
|
8
8
|
extend Forwardable
|
9
9
|
def_delegators :new_scope, :where, :order, :includes, :select, :all, :paginate, :page, :first, :find
|
10
10
|
end
|
11
|
-
class_attribute :connection_class, :connection_object, :connection_options, :query_builder
|
11
|
+
class_attribute :connection_class, :connection_object, :connection_options, :query_builder, instance_accessor: false
|
12
12
|
self.connection_class = Connection
|
13
13
|
self.connection_options = {}
|
14
14
|
self.query_builder = Query::Builder
|
@@ -4,7 +4,7 @@ module JsonApiClient
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
included do
|
7
|
-
class_attribute :relationship_linker
|
7
|
+
class_attribute :relationship_linker, instance_accessor: false
|
8
8
|
self.relationship_linker = Relationships::Relations
|
9
9
|
|
10
10
|
# the relationships for this resource
|
@@ -13,7 +13,7 @@ module JsonApiClient
|
|
13
13
|
initializer do |obj, params|
|
14
14
|
relationships = params && params.delete("relationships")
|
15
15
|
relationships ||= {}
|
16
|
-
obj.relationships = obj.relationship_linker.new(relationships)
|
16
|
+
obj.relationships = obj.class.relationship_linker.new(relationships)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -1,22 +1,20 @@
|
|
1
1
|
module JsonApiClient
|
2
2
|
module Helpers
|
3
3
|
module Serializable
|
4
|
-
|
4
|
+
extend ActiveSupport::Concern
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# end
|
10
|
-
# end
|
11
|
-
|
12
|
-
def data
|
13
|
-
attributes.slice(*RESERVED).tap do |h|
|
14
|
-
h['attributes'] = serialized_attributes
|
15
|
-
end
|
6
|
+
included do
|
7
|
+
class_attribute :read_only_attributes, instance_accessor: false
|
8
|
+
self.read_only_attributes = ['id', 'type', 'links', 'meta', 'relationships']
|
16
9
|
end
|
17
10
|
|
18
|
-
def
|
19
|
-
attributes.
|
11
|
+
def serializable_hash
|
12
|
+
attributes.slice('id', 'type').tap do |h|
|
13
|
+
relationships.serializable_hash.tap do |r|
|
14
|
+
h['relationships'] = r unless r.empty?
|
15
|
+
end
|
16
|
+
h['attributes'] = attributes.except(*self.class.read_only_attributes)
|
17
|
+
end
|
20
18
|
end
|
21
19
|
|
22
20
|
end
|
@@ -9,7 +9,7 @@ module JsonApiClient
|
|
9
9
|
klass = Utils.compute_type(record_class, type.singularize.classify)
|
10
10
|
h[type] = records.map do |datum|
|
11
11
|
params = klass.parser.parameters_from_resource(datum)
|
12
|
-
resource = klass.
|
12
|
+
resource = klass.load(params)
|
13
13
|
resource.result_set = result_set
|
14
14
|
resource
|
15
15
|
end.index_by(&:id)
|
@@ -2,12 +2,13 @@ module JsonApiClient
|
|
2
2
|
module Query
|
3
3
|
class Builder
|
4
4
|
|
5
|
-
attr_reader :klass
|
5
|
+
attr_reader :klass, :path_params
|
6
6
|
|
7
7
|
def initialize(klass)
|
8
8
|
@klass = klass
|
9
9
|
@primary_key = nil
|
10
10
|
@pagination_params = {}
|
11
|
+
@path_params = {}
|
11
12
|
@filters = {}
|
12
13
|
@includes = []
|
13
14
|
@orders = []
|
@@ -15,7 +16,9 @@ module JsonApiClient
|
|
15
16
|
end
|
16
17
|
|
17
18
|
def where(conditions = {})
|
18
|
-
|
19
|
+
# pull out any path params here
|
20
|
+
@path_params.merge!(conditions.slice(*klass.prefix_params))
|
21
|
+
@filters.merge!(conditions.except(*klass.prefix_params))
|
19
22
|
self
|
20
23
|
end
|
21
24
|
|
@@ -66,6 +69,7 @@ module JsonApiClient
|
|
66
69
|
.merge(order_params)
|
67
70
|
.merge(select_params)
|
68
71
|
.merge(primary_key_params)
|
72
|
+
.merge(path_params)
|
69
73
|
end
|
70
74
|
|
71
75
|
def to_a
|
@@ -90,6 +94,10 @@ module JsonApiClient
|
|
90
94
|
|
91
95
|
private
|
92
96
|
|
97
|
+
def path_params
|
98
|
+
@path_params.empty? ? {} : {path: @path_params}
|
99
|
+
end
|
100
|
+
|
93
101
|
def primary_key_params
|
94
102
|
return {} unless @primary_key
|
95
103
|
|
@@ -10,13 +10,13 @@ module JsonApiClient
|
|
10
10
|
# expects a record
|
11
11
|
def create(record)
|
12
12
|
request(:post, klass.path(record.attributes), {
|
13
|
-
data: record.
|
13
|
+
data: record.serializable_hash
|
14
14
|
})
|
15
15
|
end
|
16
16
|
|
17
17
|
def update(record)
|
18
18
|
request(:patch, resource_path(record.attributes), {
|
19
|
-
data: record.
|
19
|
+
data: record.serializable_hash
|
20
20
|
})
|
21
21
|
end
|
22
22
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.
|
4
|
+
version: 1.0.0.beta4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Ching
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -171,9 +171,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
171
171
|
version: 1.3.1
|
172
172
|
requirements: []
|
173
173
|
rubyforge_project:
|
174
|
-
rubygems_version: 2.
|
174
|
+
rubygems_version: 2.4.5
|
175
175
|
signing_key:
|
176
176
|
specification_version: 4
|
177
177
|
summary: Build client libraries compliant with specification defined by jsonapi.org
|
178
178
|
test_files: []
|
179
|
-
has_rdoc:
|