json_api_client 1.7.0 → 1.8.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed66b4d235079e662896ac7076427c21c716706c
|
4
|
+
data.tar.gz: c70ff83b6e97b0671d584e68fc6958b41bd75246
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 57f163489d42ceff20dc4ab15de433c5d30af28daa0332d9bef2a990dc398de3b92d9f8b2d1e6b947943d88f8b031b533bb55fcfb406f79fde020d1b1517e42d
|
7
|
+
data.tar.gz: 5b431c9c1e10f1197bff2558d776f92ff9ecec69cb484a6c603e07d47ef1ae03bc00a2511b9f7849a17d7ba5e9fb85617ed72fe82ace564a78ec9fdbb9a641f5
|
@@ -2,7 +2,8 @@ module JsonApiClient
|
|
2
2
|
module Errors
|
3
3
|
class ApiError < StandardError
|
4
4
|
attr_reader :env
|
5
|
-
def initialize(env)
|
5
|
+
def initialize(env, msg = nil)
|
6
|
+
super msg
|
6
7
|
@env = env
|
7
8
|
end
|
8
9
|
end
|
@@ -20,14 +21,14 @@ module JsonApiClient
|
|
20
21
|
end
|
21
22
|
|
22
23
|
class ServerError < ApiError
|
23
|
-
def
|
24
|
-
|
24
|
+
def initialize(env, msg = 'Internal server error')
|
25
|
+
super env, msg
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
29
|
class Conflict < ServerError
|
29
|
-
def
|
30
|
-
|
30
|
+
def initialize(env, msg = 'Resource already exists')
|
31
|
+
super env, msg
|
31
32
|
end
|
32
33
|
end
|
33
34
|
|
@@ -51,6 +52,5 @@ module JsonApiClient
|
|
51
52
|
"Unexpected response status: #{code} from: #{uri.to_s}"
|
52
53
|
end
|
53
54
|
end
|
54
|
-
|
55
55
|
end
|
56
56
|
end
|
@@ -4,15 +4,18 @@ module JsonApiClient
|
|
4
4
|
|
5
5
|
def initialize(result_set, data)
|
6
6
|
record_class = result_set.record_class
|
7
|
-
|
8
|
-
|
7
|
+
included_set = data.map do |datum|
|
8
|
+
type = datum["type"]
|
9
9
|
klass = Utils.compute_type(record_class, record_class.key_formatter.unformat(type).singularize.classify)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
params = klass.parser.parameters_from_resource(datum)
|
11
|
+
resource = klass.load(params)
|
12
|
+
resource.last_result_set = result_set
|
13
|
+
resource
|
14
|
+
end
|
15
|
+
|
16
|
+
included_set.concat(result_set) if record_class.search_included_in_result_set
|
17
|
+
@data = included_set.group_by(&:type).inject({}) do |h, (type, resources)|
|
18
|
+
h[type] = resources.index_by(&:id)
|
16
19
|
h
|
17
20
|
end
|
18
21
|
end
|
@@ -11,8 +11,8 @@ module JsonApiClient
|
|
11
11
|
handle_status(code, env)
|
12
12
|
end
|
13
13
|
end
|
14
|
-
rescue Faraday::ConnectionFailed, Faraday::TimeoutError
|
15
|
-
raise Errors::ConnectionError,
|
14
|
+
rescue Faraday::ConnectionFailed, Faraday::TimeoutError => e
|
15
|
+
raise Errors::ConnectionError.new environment, e.to_s
|
16
16
|
end
|
17
17
|
|
18
18
|
protected
|
@@ -34,6 +34,7 @@ module JsonApiClient
|
|
34
34
|
:route_format,
|
35
35
|
:request_params_class,
|
36
36
|
:keep_request_params,
|
37
|
+
:search_included_in_result_set,
|
37
38
|
instance_accessor: false
|
38
39
|
class_attribute :add_defaults_to_changes,
|
39
40
|
instance_writer: false
|
@@ -50,6 +51,7 @@ module JsonApiClient
|
|
50
51
|
self.request_params_class = RequestParams
|
51
52
|
self.keep_request_params = false
|
52
53
|
self.add_defaults_to_changes = false
|
54
|
+
self.search_included_in_result_set = false
|
53
55
|
|
54
56
|
#:underscored_key, :camelized_key, :dasherized_key, or custom
|
55
57
|
self.json_key_format = :underscored_key
|
@@ -584,10 +586,14 @@ module JsonApiClient
|
|
584
586
|
relationships.as_json_api
|
585
587
|
end
|
586
588
|
|
589
|
+
def error_message_for(error)
|
590
|
+
error.error_msg
|
591
|
+
end
|
592
|
+
|
587
593
|
def fill_errors
|
588
594
|
last_result_set.errors.each do |error|
|
589
595
|
key = self.class.key_formatter.unformat(error.error_key)
|
590
|
-
errors.add(key, error
|
596
|
+
errors.add(key, error_message_for(error))
|
591
597
|
end
|
592
598
|
end
|
593
599
|
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.
|
4
|
+
version: 1.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Ching
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|