json_api_client 1.23.0 → 1.24.0
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.
- checksums.yaml +4 -4
- data/LICENSE +20 -20
- data/README.md +723 -705
- data/Rakefile +32 -32
- data/lib/json_api_client/associations/base_association.rb +33 -33
- data/lib/json_api_client/associations/belongs_to.rb +31 -31
- data/lib/json_api_client/associations/has_many.rb +7 -7
- data/lib/json_api_client/associations/has_one.rb +16 -16
- data/lib/json_api_client/associations.rb +7 -7
- data/lib/json_api_client/connection.rb +41 -41
- data/lib/json_api_client/error_collector.rb +91 -91
- data/lib/json_api_client/errors.rb +125 -125
- data/lib/json_api_client/formatter.rb +145 -145
- data/lib/json_api_client/helpers/associatable.rb +88 -88
- data/lib/json_api_client/helpers/callbacks.rb +27 -27
- data/lib/json_api_client/helpers/dirty.rb +75 -75
- data/lib/json_api_client/helpers/dynamic_attributes.rb +78 -78
- data/lib/json_api_client/helpers/uri.rb +9 -9
- data/lib/json_api_client/helpers.rb +9 -9
- data/lib/json_api_client/implementation.rb +11 -11
- data/lib/json_api_client/included_data.rb +58 -58
- data/lib/json_api_client/linking/links.rb +21 -21
- data/lib/json_api_client/linking/top_level_links.rb +39 -39
- data/lib/json_api_client/linking.rb +5 -5
- data/lib/json_api_client/meta_data.rb +19 -19
- data/lib/json_api_client/middleware/json_request.rb +26 -26
- data/lib/json_api_client/middleware/status.rb +67 -67
- data/lib/json_api_client/middleware.rb +6 -6
- data/lib/json_api_client/paginating/nested_param_paginator.rb +140 -140
- data/lib/json_api_client/paginating/paginator.rb +89 -89
- data/lib/json_api_client/paginating.rb +6 -6
- data/lib/json_api_client/parsers/parser.rb +102 -102
- data/lib/json_api_client/parsers.rb +4 -4
- data/lib/json_api_client/query/builder.rb +239 -239
- data/lib/json_api_client/query/requestor.rb +73 -73
- data/lib/json_api_client/query.rb +5 -5
- data/lib/json_api_client/relationships/relations.rb +55 -55
- data/lib/json_api_client/relationships/top_level_relations.rb +30 -30
- data/lib/json_api_client/relationships.rb +5 -5
- data/lib/json_api_client/request_params.rb +57 -57
- data/lib/json_api_client/resource.rb +671 -671
- data/lib/json_api_client/result_set.rb +25 -25
- data/lib/json_api_client/schema.rb +154 -154
- data/lib/json_api_client/utils.rb +53 -53
- data/lib/json_api_client/version.rb +3 -3
- data/lib/json_api_client.rb +30 -30
- metadata +55 -30
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
module JsonApiClient
|
|
2
|
-
module Relationships
|
|
3
|
-
class Relations
|
|
4
|
-
include Helpers::DynamicAttributes
|
|
5
|
-
include Helpers::Dirty
|
|
6
|
-
include ActiveModel::Serialization
|
|
7
|
-
|
|
8
|
-
attr_reader :record_class
|
|
9
|
-
delegate :key_formatter, to: :record_class
|
|
10
|
-
|
|
11
|
-
def initialize(record_class, relations)
|
|
12
|
-
@record_class = record_class
|
|
13
|
-
self.attributes = relations
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def present?
|
|
17
|
-
attributes.present?
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def as_json_api
|
|
21
|
-
Hash[attributes_for_serialization.map do |k, v|
|
|
22
|
-
[k, v.slice("data")] if v.has_key?("data")
|
|
23
|
-
end.compact]
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def as_json
|
|
27
|
-
Hash[attributes.map do |k, v|
|
|
28
|
-
[k, v.slice("data")] if v.has_key?("data")
|
|
29
|
-
end.compact]
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def attributes_for_serialization
|
|
33
|
-
attributes.slice(*changed)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
protected
|
|
37
|
-
|
|
38
|
-
def set_attribute(name, value)
|
|
39
|
-
value = case value
|
|
40
|
-
when JsonApiClient::Resource
|
|
41
|
-
{data: value.as_relation}
|
|
42
|
-
when Array
|
|
43
|
-
{data: value.map(&:as_relation)}
|
|
44
|
-
when NilClass
|
|
45
|
-
{data: nil}
|
|
46
|
-
else
|
|
47
|
-
value
|
|
48
|
-
end
|
|
49
|
-
attribute_will_change!(name) if value != attributes[name]
|
|
50
|
-
attributes[name] = value
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
end
|
|
1
|
+
module JsonApiClient
|
|
2
|
+
module Relationships
|
|
3
|
+
class Relations
|
|
4
|
+
include Helpers::DynamicAttributes
|
|
5
|
+
include Helpers::Dirty
|
|
6
|
+
include ActiveModel::Serialization
|
|
7
|
+
|
|
8
|
+
attr_reader :record_class
|
|
9
|
+
delegate :key_formatter, to: :record_class
|
|
10
|
+
|
|
11
|
+
def initialize(record_class, relations)
|
|
12
|
+
@record_class = record_class
|
|
13
|
+
self.attributes = relations
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def present?
|
|
17
|
+
attributes.present?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def as_json_api
|
|
21
|
+
Hash[attributes_for_serialization.map do |k, v|
|
|
22
|
+
[k, v.slice("data")] if v.has_key?("data")
|
|
23
|
+
end.compact]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def as_json
|
|
27
|
+
Hash[attributes.map do |k, v|
|
|
28
|
+
[k, v.slice("data")] if v.has_key?("data")
|
|
29
|
+
end.compact]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def attributes_for_serialization
|
|
33
|
+
attributes.slice(*changed)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
protected
|
|
37
|
+
|
|
38
|
+
def set_attribute(name, value)
|
|
39
|
+
value = case value
|
|
40
|
+
when JsonApiClient::Resource
|
|
41
|
+
{data: value.as_relation}
|
|
42
|
+
when Array
|
|
43
|
+
{data: value.map(&:as_relation)}
|
|
44
|
+
when NilClass
|
|
45
|
+
{data: nil}
|
|
46
|
+
else
|
|
47
|
+
value
|
|
48
|
+
end
|
|
49
|
+
attribute_will_change!(name) if value != attributes[name]
|
|
50
|
+
attributes[name] = value
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
module JsonApiClient
|
|
2
|
-
module Relationships
|
|
3
|
-
class TopLevelRelations
|
|
4
|
-
|
|
5
|
-
attr_reader :relations, :record_class
|
|
6
|
-
|
|
7
|
-
def initialize(record_class, relations)
|
|
8
|
-
@relations = relations
|
|
9
|
-
@record_class = record_class
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def respond_to_missing?(method, include_private = false)
|
|
13
|
-
relations.has_key?(method.to_s) || super
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def method_missing(method, *args)
|
|
17
|
-
if respond_to_missing?(method)
|
|
18
|
-
fetch_relation(method)
|
|
19
|
-
else
|
|
20
|
-
super
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def fetch_relation(relation_name)
|
|
25
|
-
link_definition = relations.fetch(relation_name.to_s)
|
|
26
|
-
record_class.requestor.linked(link_definition)
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
1
|
+
module JsonApiClient
|
|
2
|
+
module Relationships
|
|
3
|
+
class TopLevelRelations
|
|
4
|
+
|
|
5
|
+
attr_reader :relations, :record_class
|
|
6
|
+
|
|
7
|
+
def initialize(record_class, relations)
|
|
8
|
+
@relations = relations
|
|
9
|
+
@record_class = record_class
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def respond_to_missing?(method, include_private = false)
|
|
13
|
+
relations.has_key?(method.to_s) || super
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def method_missing(method, *args)
|
|
17
|
+
if respond_to_missing?(method)
|
|
18
|
+
fetch_relation(method)
|
|
19
|
+
else
|
|
20
|
+
super
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def fetch_relation(relation_name)
|
|
25
|
+
link_definition = relations.fetch(relation_name.to_s)
|
|
26
|
+
record_class.requestor.linked(link_definition)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
module JsonApiClient
|
|
2
|
-
module Relationships
|
|
3
|
-
autoload :Relations, "json_api_client/relationships/relations"
|
|
4
|
-
autoload :TopLevelRelations, "json_api_client/relationships/top_level_relations"
|
|
5
|
-
end
|
|
1
|
+
module JsonApiClient
|
|
2
|
+
module Relationships
|
|
3
|
+
autoload :Relations, "json_api_client/relationships/relations"
|
|
4
|
+
autoload :TopLevelRelations, "json_api_client/relationships/top_level_relations"
|
|
5
|
+
end
|
|
6
6
|
end
|
|
@@ -1,57 +1,57 @@
|
|
|
1
|
-
module JsonApiClient
|
|
2
|
-
class RequestParams
|
|
3
|
-
attr_reader :klass, :includes, :fields
|
|
4
|
-
|
|
5
|
-
def initialize(klass, includes: [], fields: {})
|
|
6
|
-
@klass = klass
|
|
7
|
-
@includes = includes
|
|
8
|
-
@fields = fields
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def add_includes(includes)
|
|
12
|
-
Utils.parse_includes(klass, *includes).each do |name|
|
|
13
|
-
name = name.to_sym
|
|
14
|
-
self.includes.push(name) unless self.includes.include?(name)
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
def reset_includes!
|
|
19
|
-
@includes = []
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def set_fields(type, field_names)
|
|
23
|
-
self.fields[type.to_sym] = field_names.map(&:to_sym)
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def remove_fields(type)
|
|
27
|
-
self.fields.delete(type.to_sym)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def field_types
|
|
31
|
-
self.fields.keys
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def clear
|
|
35
|
-
reset_includes!
|
|
36
|
-
@fields = {}
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def to_params
|
|
40
|
-
return nil if field_types.empty? && includes.empty?
|
|
41
|
-
parsed_fields.merge(parsed_includes)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
private
|
|
45
|
-
|
|
46
|
-
def parsed_includes
|
|
47
|
-
return {} if includes.empty?
|
|
48
|
-
{include: includes.join(",")}
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def parsed_fields
|
|
52
|
-
return {} if field_types.empty?
|
|
53
|
-
{fields: fields.map { |type, names| [type, names.join(",")] }.to_h}
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
end
|
|
57
|
-
end
|
|
1
|
+
module JsonApiClient
|
|
2
|
+
class RequestParams
|
|
3
|
+
attr_reader :klass, :includes, :fields
|
|
4
|
+
|
|
5
|
+
def initialize(klass, includes: [], fields: {})
|
|
6
|
+
@klass = klass
|
|
7
|
+
@includes = includes
|
|
8
|
+
@fields = fields
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def add_includes(includes)
|
|
12
|
+
Utils.parse_includes(klass, *includes).each do |name|
|
|
13
|
+
name = name.to_sym
|
|
14
|
+
self.includes.push(name) unless self.includes.include?(name)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def reset_includes!
|
|
19
|
+
@includes = []
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def set_fields(type, field_names)
|
|
23
|
+
self.fields[type.to_sym] = field_names.map(&:to_sym)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def remove_fields(type)
|
|
27
|
+
self.fields.delete(type.to_sym)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def field_types
|
|
31
|
+
self.fields.keys
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def clear
|
|
35
|
+
reset_includes!
|
|
36
|
+
@fields = {}
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def to_params
|
|
40
|
+
return nil if field_types.empty? && includes.empty?
|
|
41
|
+
parsed_fields.merge(parsed_includes)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def parsed_includes
|
|
47
|
+
return {} if includes.empty?
|
|
48
|
+
{include: includes.join(",")}
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def parsed_fields
|
|
52
|
+
return {} if field_types.empty?
|
|
53
|
+
{fields: fields.map { |type, names| [type, names.join(",")] }.to_h}
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|