flexirest 1.8.7 → 1.8.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/CHANGELOG.md +7 -0
- data/lib/flexirest/connection.rb +1 -1
- data/lib/flexirest/json_api_proxy.rb +9 -4
- data/lib/flexirest/version.rb +1 -1
- data/spec/lib/connection_spec.rb +1 -1
- data/spec/lib/json_api_spec.rb +30 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 034246a4c82d512ced039ae0265091d40688183c762e1094c12f0dca31439a55
|
4
|
+
data.tar.gz: 65545b4903a74eae1140866589f97be1bf664b2df052bc515a243e29844ab543
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fa7bd3620f69ec7ba0ba6493d86bae8aef4c889e5f3ed536d2bd801c6b62a8f9248bd80338901eff4b0435a2aa26589672ea03ddd6e81a4c1bc99cb66387651b
|
7
|
+
data.tar.gz: e73ba209c5dd7e98a370e8ac2fab285f98cb948b81f56a3cc23f63ad9f3035ba385de0292546943f1ca63d8eca30e9f0795f1ee3f60268b1b8a9bfe2c0a69deb
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 1.8.8
|
4
|
+
|
5
|
+
Fix:
|
6
|
+
|
7
|
+
- Use custom type and name for JSON-API fields (thanks to François Ferrandis for the PR).
|
8
|
+
- Fix Faraday error classes to match current ones in Faraday (thanks to François Ferrandis for the PR).
|
9
|
+
|
3
10
|
## 1.8.7
|
4
11
|
|
5
12
|
Fix:
|
data/lib/flexirest/connection.rb
CHANGED
@@ -24,7 +24,7 @@ module Flexirest
|
|
24
24
|
|
25
25
|
def make_safe_request(path, &block)
|
26
26
|
block.call
|
27
|
-
rescue Faraday::
|
27
|
+
rescue Faraday::TimeoutError
|
28
28
|
raise Flexirest::TimeoutException.new("Timed out getting #{full_url(path)}")
|
29
29
|
rescue Faraday::ConnectionFailed => e1
|
30
30
|
if e1.respond_to?(:cause) && e1.cause.is_a?(Net::OpenTimeout)
|
@@ -292,12 +292,14 @@ module Flexirest
|
|
292
292
|
|
293
293
|
# Retrieve the linked resource id and its pluralized type name
|
294
294
|
rel_id = relationships[name]['data']['id']
|
295
|
-
|
295
|
+
|
296
|
+
type_name = relationships[name]['data']['type']
|
297
|
+
plural_type_name = type_name.pluralize
|
296
298
|
|
297
299
|
# Traverse through the included object, and find the included
|
298
300
|
# linked resource, based on the given id and pluralized type name
|
299
301
|
linked_resource = included.select do |i|
|
300
|
-
i['id'] == rel_id && i['type'] ==
|
302
|
+
i['id'] == rel_id && i['type'] == plural_type_name
|
301
303
|
end
|
302
304
|
|
303
305
|
return linked_resource, rel_id, true
|
@@ -313,12 +315,15 @@ module Flexirest
|
|
313
315
|
|
314
316
|
# Retrieve the linked resources ids
|
315
317
|
rel_ids = relationships[name]['data'].map { |r| r['id'] }
|
316
|
-
|
318
|
+
|
319
|
+
# Index the linked resources' id and types that we need to
|
320
|
+
# retrieve from the included resources
|
321
|
+
relations_to_include = relationships[name]['data'].map { |r| [r['id'], r['type']] }.to_set
|
317
322
|
|
318
323
|
# Traverse through the included object, and find the included
|
319
324
|
# linked resources, based on the given ids and type name
|
320
325
|
linked_resources = included.select do |i|
|
321
|
-
|
326
|
+
relations_to_include.include?([i['id'], i['type']])
|
322
327
|
end
|
323
328
|
|
324
329
|
return linked_resources, rel_ids, true
|
data/lib/flexirest/version.rb
CHANGED
data/spec/lib/connection_spec.rb
CHANGED
@@ -186,7 +186,7 @@ describe Flexirest::Connection do
|
|
186
186
|
end
|
187
187
|
|
188
188
|
it "should retry once in the event of a connection failed" do
|
189
|
-
stub_request(:get, "www.example.com/foo").to_raise(Faraday::
|
189
|
+
stub_request(:get, "www.example.com/foo").to_raise(Faraday::ConnectionFailed.new("Foo"))
|
190
190
|
expect { @connection.get("/foo") }.to raise_error(Flexirest::BaseException)
|
191
191
|
end
|
192
192
|
|
data/spec/lib/json_api_spec.rb
CHANGED
@@ -15,7 +15,9 @@ end
|
|
15
15
|
class JsonAPIExampleArticle < Flexirest::Base
|
16
16
|
proxy :json_api
|
17
17
|
has_many :tags, JsonAPIAssociationExampleTag
|
18
|
+
has_one :main_theme, JsonAPIAssociationExampleTag
|
18
19
|
has_one :author, JsonAPIAssociationExampleAuthor
|
20
|
+
has_many :co_authors, JsonAPIAssociationExampleAuthor
|
19
21
|
|
20
22
|
faker1 = {
|
21
23
|
data: {
|
@@ -74,7 +76,7 @@ class JsonAPIExampleArticle < Flexirest::Base
|
|
74
76
|
},
|
75
77
|
included: [
|
76
78
|
{ id: 1, type: 'tags', attributes: { item: 'item three' },
|
77
|
-
relationships: { 'authors' => { data: [{ id: 1, type: '
|
79
|
+
relationships: { 'authors' => { data: [{ id: 1, type: 'authors' }] } } },
|
78
80
|
{ id: 1, type: 'authors', attributes: { item: 'item two' } }
|
79
81
|
]
|
80
82
|
}
|
@@ -102,6 +104,20 @@ class JsonAPIExampleArticle < Flexirest::Base
|
|
102
104
|
{ id: 2, type: 'tags', attributes: { item: 'item three' } }
|
103
105
|
]
|
104
106
|
}
|
107
|
+
faker8 = {
|
108
|
+
data: {
|
109
|
+
id: 1, type: 'articles', attributes: { item: 'item one' },
|
110
|
+
relationships: {
|
111
|
+
'main_theme' => { data: { id: 1, type: 'tags' } },
|
112
|
+
'co_authors' => { data: [{ id: 1, type: 'authors' }, { id: 2, type: 'authors' }] },
|
113
|
+
}
|
114
|
+
},
|
115
|
+
included: [
|
116
|
+
{ id: 1, type: 'tags', attributes: { item: 'item one' } },
|
117
|
+
{ id: 1, type: 'authors', attributes: { item: 'item one' } },
|
118
|
+
{ id: 2, type: 'authors', attributes: { item: 'item two' } },
|
119
|
+
]
|
120
|
+
}
|
105
121
|
|
106
122
|
get(
|
107
123
|
:find,
|
@@ -151,6 +167,13 @@ class JsonAPIExampleArticle < Flexirest::Base
|
|
151
167
|
fake: faker7.to_json,
|
152
168
|
fake_content_type: 'application/vnd.api+json'
|
153
169
|
)
|
170
|
+
|
171
|
+
get(
|
172
|
+
:custom_relationship_name,
|
173
|
+
'/articles/:id',
|
174
|
+
fake: faker8.to_json,
|
175
|
+
fake_content_type: 'application/vnd.api+json'
|
176
|
+
)
|
154
177
|
end
|
155
178
|
|
156
179
|
module JsonAPIExample
|
@@ -324,6 +347,12 @@ describe 'JSON API' do
|
|
324
347
|
it 'should retrieve empty array if the plural relationship type is empty' do
|
325
348
|
expect(subject.includes(:tags).no_assocs(1).tags).to be_empty
|
326
349
|
end
|
350
|
+
|
351
|
+
it 'should retrieve associations that have a name that differs from their type name' do
|
352
|
+
parsed = subject.includes(:main_theme, :co_authors).custom_relationship_name(1)
|
353
|
+
expect(parsed.main_theme).to be_an_instance_of(JsonAPIAssociationExampleTag)
|
354
|
+
expect(parsed.co_authors).to be_an_instance_of(Flexirest::ResultIterator)
|
355
|
+
end
|
327
356
|
end
|
328
357
|
|
329
358
|
context 'lazy loading' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flexirest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.8.
|
4
|
+
version: 1.8.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Jeffries
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|