json_api_client 1.5.2 → 1.5.3
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/README.md +10 -0
- data/lib/json_api_client/error_collector.rb +19 -10
- data/lib/json_api_client/middleware/json_request.rb +16 -1
- data/lib/json_api_client/query/builder.rb +2 -2
- data/lib/json_api_client/resource.rb +15 -13
- data/lib/json_api_client/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce135d371a55b1a0114e61714e16f1ba25b27e73
|
4
|
+
data.tar.gz: aa8ef8446aba3641569ceced0810cba716cdffbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3db5715ed8267149d9c7fcffd41fc3cd6c8a830585ae6cf80d5208972f2370bce819e4e9f00dbd606d535a7e879255ca423787dd6d1c3500d86d1b91c8a35554
|
7
|
+
data.tar.gz: 53a8c4c8481e60322a961e1fd7bc8ee202062b196c7695f501b1dfdacdb4e7c09de45b04efa9bf8d1ce7971f4cd558003270a2e7c4f913f279d88047e764e621
|
data/README.md
CHANGED
@@ -502,6 +502,16 @@ end
|
|
502
502
|
|
503
503
|
```
|
504
504
|
|
505
|
+
## Contributing
|
506
|
+
|
507
|
+
Contributions are welcome! Please fork this repo and send a pull request. Your pull request should have:
|
508
|
+
|
509
|
+
* a description about what's broken or what the desired functionality is
|
510
|
+
* a test illustrating the bug or new feature
|
511
|
+
* the code to fix the bug
|
512
|
+
|
513
|
+
Ideally, the PR has 2 commits - the first showing the failed test and the second with the fix - although this is not
|
514
|
+
required. The commits will be squashed into master once accepted.
|
505
515
|
|
506
516
|
## Changelog
|
507
517
|
|
@@ -33,18 +33,27 @@ module JsonApiClient
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def source_parameter
|
36
|
-
source
|
37
|
-
source[:pointer] ?
|
38
|
-
source[:pointer].split("/").last :
|
39
|
-
nil
|
40
|
-
end
|
36
|
+
source[:parameter]
|
41
37
|
end
|
42
38
|
|
43
39
|
def source_pointer
|
44
|
-
source
|
45
|
-
|
46
|
-
|
47
|
-
|
40
|
+
source[:pointer]
|
41
|
+
end
|
42
|
+
|
43
|
+
def error_key
|
44
|
+
if source_pointer && source_pointer != "/data"
|
45
|
+
source_pointer.split("/").last
|
46
|
+
else
|
47
|
+
"base"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def error_msg
|
52
|
+
msg = title || detail || "invalid"
|
53
|
+
if source_parameter
|
54
|
+
"#{source_parameter} #{msg}"
|
55
|
+
else
|
56
|
+
msg
|
48
57
|
end
|
49
58
|
end
|
50
59
|
|
@@ -74,7 +83,7 @@ module JsonApiClient
|
|
74
83
|
|
75
84
|
def [](source)
|
76
85
|
map do |error|
|
77
|
-
error.
|
86
|
+
error.error_key == source
|
78
87
|
end
|
79
88
|
end
|
80
89
|
|
@@ -2,10 +2,25 @@ module JsonApiClient
|
|
2
2
|
module Middleware
|
3
3
|
class JsonRequest < Faraday::Middleware
|
4
4
|
def call(environment)
|
5
|
+
accept_header = update_accept_header(environment[:request_headers])
|
6
|
+
|
5
7
|
environment[:request_headers]["Content-Type"] = 'application/vnd.api+json'
|
6
|
-
environment[:request_headers]["Accept"] =
|
8
|
+
environment[:request_headers]["Accept"] = accept_header
|
7
9
|
@app.call(environment)
|
8
10
|
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def update_accept_header(headers)
|
15
|
+
return 'application/vnd.api+json' if headers["Accept"].nil?
|
16
|
+
accept_params = headers["Accept"].split(",")
|
17
|
+
|
18
|
+
unless accept_params.include?('application/vnd.api+json')
|
19
|
+
accept_params.unshift('application/vnd.api+json')
|
20
|
+
end
|
21
|
+
|
22
|
+
accept_params.join(",")
|
23
|
+
end
|
9
24
|
end
|
10
25
|
end
|
11
26
|
end
|
@@ -47,12 +47,12 @@ module JsonApiClient
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def page(number)
|
50
|
-
@pagination_params[
|
50
|
+
@pagination_params[ klass.paginator.page_param ] = number
|
51
51
|
self
|
52
52
|
end
|
53
53
|
|
54
54
|
def per(size)
|
55
|
-
@pagination_params[
|
55
|
+
@pagination_params[ klass.paginator.per_page_param ] = size
|
56
56
|
self
|
57
57
|
end
|
58
58
|
|
@@ -167,7 +167,7 @@ module JsonApiClient
|
|
167
167
|
end
|
168
168
|
|
169
169
|
# Default attributes that every instance of this resource should be
|
170
|
-
#
|
170
|
+
# initialized with. Optionally, override this method in a subclass.
|
171
171
|
#
|
172
172
|
# @return [Hash] Default attributes
|
173
173
|
def default_attributes
|
@@ -272,7 +272,7 @@ module JsonApiClient
|
|
272
272
|
|
273
273
|
def _set_prefix_path(attrs)
|
274
274
|
paths = _belongs_to_associations.map do |a|
|
275
|
-
a.set_prefix_path(attrs, route_formatter)
|
275
|
+
a.set_prefix_path(attrs, route_formatter)
|
276
276
|
end
|
277
277
|
|
278
278
|
paths.join("/")
|
@@ -305,7 +305,7 @@ module JsonApiClient
|
|
305
305
|
@persisted = nil
|
306
306
|
self.links = self.class.linker.new(params.delete("links") || {})
|
307
307
|
self.relationships = self.class.relationship_linker.new(self.class, params.delete("relationships") || {})
|
308
|
-
self.attributes =
|
308
|
+
self.attributes = self.class.default_attributes.merge(params)
|
309
309
|
|
310
310
|
self.class.schema.each_property do |property|
|
311
311
|
attributes[property.name] = property.default unless attributes.has_key?(property.name) || property.default.nil?
|
@@ -410,13 +410,7 @@ module JsonApiClient
|
|
410
410
|
end
|
411
411
|
|
412
412
|
if last_result_set.has_errors?
|
413
|
-
|
414
|
-
if error.source_parameter
|
415
|
-
errors.add(self.class.key_formatter.unformat(error.source_parameter), error.title || error.detail)
|
416
|
-
else
|
417
|
-
errors.add(:base, error.title || error.detail)
|
418
|
-
end
|
419
|
-
end
|
413
|
+
fill_errors
|
420
414
|
false
|
421
415
|
else
|
422
416
|
self.errors.clear if self.errors
|
@@ -436,11 +430,12 @@ module JsonApiClient
|
|
436
430
|
# @return [Boolean] Whether or not the destroy succeeded
|
437
431
|
def destroy
|
438
432
|
self.last_result_set = self.class.requestor.destroy(self)
|
439
|
-
if
|
433
|
+
if last_result_set.has_errors?
|
434
|
+
fill_errors
|
435
|
+
false
|
436
|
+
else
|
440
437
|
self.attributes.clear
|
441
438
|
true
|
442
|
-
else
|
443
|
-
false
|
444
439
|
end
|
445
440
|
end
|
446
441
|
|
@@ -504,5 +499,12 @@ module JsonApiClient
|
|
504
499
|
def relationships_for_serialization
|
505
500
|
relationships.as_json_api
|
506
501
|
end
|
502
|
+
|
503
|
+
def fill_errors
|
504
|
+
last_result_set.errors.each do |error|
|
505
|
+
key = self.class.key_formatter.unformat(error.error_key)
|
506
|
+
errors.add(key, error.error_msg)
|
507
|
+
end
|
508
|
+
end
|
507
509
|
end
|
508
510
|
end
|
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.5.
|
4
|
+
version: 1.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Ching
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -177,7 +177,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
177
177
|
version: '0'
|
178
178
|
requirements: []
|
179
179
|
rubyforge_project:
|
180
|
-
rubygems_version: 2.
|
180
|
+
rubygems_version: 2.6.8
|
181
181
|
signing_key:
|
182
182
|
specification_version: 4
|
183
183
|
summary: Build client libraries compliant with specification defined by jsonapi.org
|