lhs 9.0.0 → 9.0.1
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/lib/lhs/concerns/record/endpoints.rb +10 -1
- data/lib/lhs/concerns/record/request.rb +2 -2
- data/lib/lhs/version.rb +1 -1
- data/spec/record/endpoints_spec.rb +19 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5c5dde69a8e71e9f37d3b769c04b865ec6d97cf
|
4
|
+
data.tar.gz: ceaf6a4a5c87d83448c317522d06b475aaf411ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d2adc8b42d6f832313537ae26e2c5228a77dbfa9f917b338e365f972e21a198c5b79f703ac0c7c14bc0282aa59d73499d322f4100861c31461c8dc8e0aae151
|
7
|
+
data.tar.gz: 32a78f36ab5f8903386631cd84f005231f90453a0045f1d90045cb7a81e941cb2e49fbd8dbb85c14475582ac3db85998ff7854d2faf4d1116e5ce4832d9979c5
|
@@ -36,8 +36,10 @@ class LHS::Record
|
|
36
36
|
# Find an endpoint based on the provided parameters.
|
37
37
|
# If no parameters are provided it finds the base endpoint
|
38
38
|
# otherwise it finds the endpoint that matches the parameters best.
|
39
|
-
def find_endpoint(params = {})
|
39
|
+
def find_endpoint(params = {}, url = nil)
|
40
40
|
endpoint = find_best_endpoint(params) if params && params.keys.count > 0
|
41
|
+
endpoint ||= find_endpoint_by_url(url) if url.present?
|
42
|
+
endpoint ||= LHC::Endpoint.new(url) if url.present?
|
41
43
|
endpoint ||= find_base_endpoint
|
42
44
|
endpoint
|
43
45
|
end
|
@@ -80,6 +82,13 @@ class LHS::Record
|
|
80
82
|
end
|
81
83
|
end
|
82
84
|
|
85
|
+
# Find endpoint by given URL
|
86
|
+
def find_endpoint_by_url(url)
|
87
|
+
sorted_endpoints.find do |endpoint|
|
88
|
+
LHC::Endpoint.match?(url, endpoint.url)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
83
92
|
# Sort endpoints by number of placeholders, heighest first
|
84
93
|
def sorted_endpoints
|
85
94
|
endpoints.sort { |a, b| b.placeholders.count <=> a.placeholders.count }
|
@@ -292,7 +292,7 @@ class LHS::Record
|
|
292
292
|
def multiple_requests(options)
|
293
293
|
options = options.map do |option|
|
294
294
|
next unless option.present?
|
295
|
-
process_options(option, find_endpoint(option[:params]))
|
295
|
+
process_options(option, find_endpoint(option[:params], option.fetch(:url, nil)))
|
296
296
|
end
|
297
297
|
data = LHC.request(options.compact).map do |response|
|
298
298
|
LHS::Data.new(response.body, nil, self, response.request)
|
@@ -395,7 +395,7 @@ class LHS::Record
|
|
395
395
|
options = options.dup
|
396
396
|
including = options.delete(:including)
|
397
397
|
referencing = options.delete(:referencing)
|
398
|
-
endpoint = find_endpoint(options[:params])
|
398
|
+
endpoint = find_endpoint(options[:params], options.fetch(:url, nil))
|
399
399
|
apply_limit!(options) if options[:all]
|
400
400
|
response = LHC.request(process_options(options, endpoint))
|
401
401
|
data = LHS::Data.new(response.body, nil, self, response.request, endpoint)
|
data/lib/lhs/version.rb
CHANGED
@@ -69,5 +69,24 @@ describe LHS::Record do
|
|
69
69
|
AnotherRecord.where(campaign_id: 123, entry_id: 123)
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
73
|
+
context 'includes data without considering base endpoint of parent record if url is present' do
|
74
|
+
before(:each) do
|
75
|
+
class Contract < LHS::Record
|
76
|
+
endpoint ':datastore/contracts/:id'
|
77
|
+
endpoint ':datastore/entry/:entry_id/contracts'
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'uses urls instead of trying to find base endpoint of parent class' do
|
82
|
+
stub_request(:get, "#{datastore}/entry/123/contracts?limit=100")
|
83
|
+
.to_return(body: [{ product: { href: "#{datastore}/products/LBC" } }].to_json)
|
84
|
+
stub_request(:get, "#{datastore}/products/LBC")
|
85
|
+
.to_return(body: { name: 'Local Business Card' }.to_json)
|
86
|
+
expect(lambda {
|
87
|
+
Contract.includes(:product).where(entry_id: '123').all.first
|
88
|
+
}).not_to raise_error # Multiple base endpoints found
|
89
|
+
end
|
90
|
+
end
|
72
91
|
end
|
73
92
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lhs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.0.
|
4
|
+
version: 9.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/local-ch/lhs/graphs/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|