simple_jsonapi_client 0.2.2 → 0.2.4
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 +5 -5
- data/.travis.yml +1 -0
- data/Dockerfile +1 -0
- data/lib/simple_jsonapi_client/base.rb +20 -11
- data/lib/simple_jsonapi_client/errors/api_error.rb +1 -0
- data/lib/simple_jsonapi_client/redirection/fetch_all.rb +1 -1
- data/lib/simple_jsonapi_client/utils.rb +47 -0
- data/lib/simple_jsonapi_client/version.rb +1 -1
- data/simple_jsonapi_client.gemspec +1 -2
- metadata +6 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 77440c85cfcb332cb551cc83519593535a11311e2407b3b0bccaa73f685b8054
|
4
|
+
data.tar.gz: dd8c4bfc2423d80ecf755437ea3f5d1fd03f5df6351b4795f5b26a591b2cea5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca09436cd3d0b17591aa1b1538fd5052c8e525157a785bb2c000fa5e6d2cc59d5f35d325170352a5529e189d87be4239740ab5c2864375a081ceab5e2433b840
|
7
|
+
data.tar.gz: f15be7fd5273d834e47a86234c6f57df916df49de79c90f15e8c6b29d3686d2539c1540bdaecf2aa6c497972a66a7f621403fa758bd947ae85782c4bc5f84885
|
data/.travis.yml
CHANGED
data/Dockerfile
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'active_support/core_ext/hash/transform_values'
|
1
|
+
require 'simple_jsonapi_client/utils'
|
3
2
|
require 'simple_jsonapi_client/error'
|
4
3
|
require 'simple_jsonapi_client/relationships/relationship'
|
5
4
|
require 'simple_jsonapi_client/redirection/fetch_all'
|
@@ -208,12 +207,22 @@ module SimpleJSONAPIClient
|
|
208
207
|
def interpret_empty_response(response, connection)
|
209
208
|
end
|
210
209
|
|
211
|
-
|
212
|
-
relationships
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
210
|
+
if {}.respond_to?(:transform_values)
|
211
|
+
def interpreted_relationships(relationships)
|
212
|
+
relationships.transform_values { |value|
|
213
|
+
if (relationship = relationship_from(value))
|
214
|
+
{ data: relationship }
|
215
|
+
end
|
216
|
+
}
|
217
|
+
end
|
218
|
+
else
|
219
|
+
def interpreted_relationships(relationships)
|
220
|
+
Utils.transform_values(relationships) { |value|
|
221
|
+
if (relationship = relationship_from(value))
|
222
|
+
{ data: relationship }
|
223
|
+
end
|
224
|
+
}
|
225
|
+
end
|
217
226
|
end
|
218
227
|
|
219
228
|
def relationship_from(value)
|
@@ -238,12 +247,12 @@ module SimpleJSONAPIClient
|
|
238
247
|
attr_reader :id, :context
|
239
248
|
|
240
249
|
def initialize(meta: nil, id:, attributes: nil, relationships: nil, included: {}, connection:, context: nil)
|
241
|
-
@meta =
|
250
|
+
@meta = Utils.symbolize_keys(meta) if meta
|
242
251
|
@id = id
|
243
252
|
@included = included
|
244
253
|
@connection = connection
|
245
254
|
@context = context
|
246
|
-
@attributes =
|
255
|
+
@attributes = Utils.symbolize_keys(attributes) if attributes
|
247
256
|
@input_relationships = relationships
|
248
257
|
end
|
249
258
|
|
@@ -267,7 +276,7 @@ module SimpleJSONAPIClient
|
|
267
276
|
@relationships ||=
|
268
277
|
begin
|
269
278
|
if input_relationships
|
270
|
-
relationships_to_models(
|
279
|
+
relationships_to_models(Utils.symbolize_keys(input_relationships))
|
271
280
|
else
|
272
281
|
loaded_record.relationships
|
273
282
|
end
|
@@ -30,7 +30,7 @@ module SimpleJSONAPIClient
|
|
30
30
|
current_response['data'].each do |record|
|
31
31
|
yielder << record
|
32
32
|
end
|
33
|
-
break unless (next_link =
|
33
|
+
break unless (next_link = Utils.hash_dig(current_response, 'links', 'next'))
|
34
34
|
current_opts.merge!(url_opts: {}, url: next_link)
|
35
35
|
current_opts.delete(:page_opts)
|
36
36
|
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module SimpleJSONAPIClient
|
2
|
+
module Utils
|
3
|
+
class << self
|
4
|
+
# Implementation adapted from ActiveSupport
|
5
|
+
# Copyright (c) 2005-2019 David Heinemeier Hansson
|
6
|
+
# https://github.com/rails/rails/blob/b9ca94caea2ca6a6cc09abaffaad67b447134079/activesupport/lib/active_support/core_ext/hash/keys.rb
|
7
|
+
def symbolize_keys(hash)
|
8
|
+
result = {}
|
9
|
+
hash.each_key do |key|
|
10
|
+
result[(key.to_sym rescue key)] = hash[key]
|
11
|
+
end
|
12
|
+
result
|
13
|
+
end
|
14
|
+
|
15
|
+
def hash_dig(hash, *keys)
|
16
|
+
if hash.respond_to?(:dig)
|
17
|
+
hash.dig(*keys)
|
18
|
+
else
|
19
|
+
dig(hash, keys)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Implementation adapted from the hash_dig gem, Copyright (c) 2015 Colin Kelley, MIT License
|
26
|
+
# https://github.com/Invoca/ruby_dig/blob/19fa8c1d2cc7706d015a3004f028169a2ff83391/lib/ruby_dig.rb
|
27
|
+
def dig(hash, key, *rest)
|
28
|
+
value = hash[key]
|
29
|
+
if value.nil? || rest.empty?
|
30
|
+
value
|
31
|
+
elsif value.is_a?(Hash) || value.is_a?(Array)
|
32
|
+
dig(value, *rest)
|
33
|
+
else
|
34
|
+
fail TypeError, "#{value.class} does not work with #dig" # should not happen with our use of #dig
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def transform_values(hash)
|
39
|
+
result = {}
|
40
|
+
hash.each do |key, value|
|
41
|
+
result[key] = yield(value)
|
42
|
+
end
|
43
|
+
result
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -22,9 +22,8 @@ Gem::Specification.new do |spec|
|
|
22
22
|
|
23
23
|
spec.add_dependency "faraday", "~> 0.12"
|
24
24
|
spec.add_dependency "faraday_middleware", "~> 0.11"
|
25
|
-
spec.add_dependency "activesupport", ">= 3.1.12", "< 6"
|
26
25
|
|
27
|
-
spec.add_development_dependency "bundler", "~>
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.0.2"
|
28
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
29
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
30
29
|
spec.add_development_dependency "pry", "~> 0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_jsonapi_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ariel Caplan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -38,40 +38,20 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0.11'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: activesupport
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 3.1.12
|
48
|
-
- - "<"
|
49
|
-
- !ruby/object:Gem::Version
|
50
|
-
version: '6'
|
51
|
-
type: :runtime
|
52
|
-
prerelease: false
|
53
|
-
version_requirements: !ruby/object:Gem::Requirement
|
54
|
-
requirements:
|
55
|
-
- - ">="
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version: 3.1.12
|
58
|
-
- - "<"
|
59
|
-
- !ruby/object:Gem::Version
|
60
|
-
version: '6'
|
61
41
|
- !ruby/object:Gem::Dependency
|
62
42
|
name: bundler
|
63
43
|
requirement: !ruby/object:Gem::Requirement
|
64
44
|
requirements:
|
65
45
|
- - "~>"
|
66
46
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
47
|
+
version: 2.0.2
|
68
48
|
type: :development
|
69
49
|
prerelease: false
|
70
50
|
version_requirements: !ruby/object:Gem::Requirement
|
71
51
|
requirements:
|
72
52
|
- - "~>"
|
73
53
|
- !ruby/object:Gem::Version
|
74
|
-
version:
|
54
|
+
version: 2.0.2
|
75
55
|
- !ruby/object:Gem::Dependency
|
76
56
|
name: rake
|
77
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,6 +131,7 @@ files:
|
|
151
131
|
- lib/simple_jsonapi_client/relationships/relationship.rb
|
152
132
|
- lib/simple_jsonapi_client/relationships/singular_data_relationship.rb
|
153
133
|
- lib/simple_jsonapi_client/relationships/singular_link_relationship.rb
|
134
|
+
- lib/simple_jsonapi_client/utils.rb
|
154
135
|
- lib/simple_jsonapi_client/version.rb
|
155
136
|
- simple_jsonapi_client.gemspec
|
156
137
|
homepage: https://github.com/amcaplan/simple_jsonapi_client
|
@@ -173,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
154
|
version: '0'
|
174
155
|
requirements: []
|
175
156
|
rubyforge_project:
|
176
|
-
rubygems_version: 2.
|
157
|
+
rubygems_version: 2.7.8
|
177
158
|
signing_key:
|
178
159
|
specification_version: 4
|
179
160
|
summary: Framework for writing clients for JSONAPI APIs in Ruby.
|