lhs 14.3.1 → 14.3.2
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/item/save.rb +2 -3
- data/lib/lhs/concerns/item/update.rb +2 -4
- data/lib/lhs/data.rb +11 -4
- data/lib/lhs/proxy.rb +1 -1
- data/lib/lhs/version.rb +1 -1
- data/spec/record/reload_spec.rb +39 -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: 23918846d8c64e8753d97597980490a1e81727db
|
4
|
+
data.tar.gz: 0b7aa7f5dc6a6621959f76391aab092b69655b46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ed8155be2929a3ba33c54f3f26b8f3c7d3dc55ab86a71b235eda98001e4132e4b979d2e294c6e066950aa770fc839ee9498461a554ae69123f5354fd4df15dfe
|
7
|
+
data.tar.gz: 85f20098c747b9e2f3596169ef1f48e2577f95e5f53cc0b97c39aeaaaa86c226b62a5db6c9d97357bf8f99c04624e9c677d9f41b9f248946396cba412c83ad65
|
@@ -34,12 +34,11 @@ class LHS::Item < LHS::Proxy
|
|
34
34
|
|
35
35
|
def create_and_merge_data!(options)
|
36
36
|
direct_response_data = record.request(options)
|
37
|
-
|
38
|
-
_data.merge_raw!(direct_response_data, nested_path)
|
37
|
+
_data.merge_raw!(direct_response_data.unwrap(:item_created_key))
|
39
38
|
response_headers = direct_response_data._request.response.headers
|
40
39
|
if response_headers && response_headers['Location']
|
41
40
|
location_data = record.request(options.merge(url: response_headers['Location'], method: :get, body: nil))
|
42
|
-
_data.merge_raw!(location_data
|
41
|
+
_data.merge_raw!(location_data.unwrap(:item_created_key))
|
43
42
|
end
|
44
43
|
true
|
45
44
|
end
|
@@ -26,8 +26,7 @@ class LHS::Item < LHS::Proxy
|
|
26
26
|
def update!(params, options = {}, partial_update = false)
|
27
27
|
options ||= {}
|
28
28
|
partial_data = LHS::Data.new(params, _data.parent, record)
|
29
|
-
|
30
|
-
_data.merge_raw!(partial_data, nested_path)
|
29
|
+
_data.merge_raw!(partial_data)
|
31
30
|
data_sent = partial_update ? partial_data : _data
|
32
31
|
url = href || record.find_endpoint(id: id).compile(id: id)
|
33
32
|
response_data = record.request(
|
@@ -38,8 +37,7 @@ class LHS::Item < LHS::Proxy
|
|
38
37
|
headers: { 'Content-Type' => 'application/json' }
|
39
38
|
)
|
40
39
|
)
|
41
|
-
|
42
|
-
_data.merge_raw!(response_data, nested_path)
|
40
|
+
_data.merge_raw!(response_data.unwrap(:item_created_key))
|
43
41
|
true
|
44
42
|
end
|
45
43
|
end
|
data/lib/lhs/data.rb
CHANGED
@@ -28,11 +28,18 @@ class LHS::Data
|
|
28
28
|
|
29
29
|
# merging data
|
30
30
|
# e.g. when loading remote data via link
|
31
|
-
def merge_raw!(data
|
31
|
+
def merge_raw!(data)
|
32
32
|
return false if data.blank? || !data._raw.is_a?(Hash)
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
_raw.merge! data._raw
|
34
|
+
end
|
35
|
+
|
36
|
+
# Unwraps data for certain use cases
|
37
|
+
# like items_created_key for CREATE, UPDATED etc.
|
38
|
+
# like item_key for GET etc.
|
39
|
+
def unwrap(usecase)
|
40
|
+
nested_path = record.send(usecase) if record
|
41
|
+
return LHS::Data.new(dig(*nested_path) || _raw, nil, self.class) if nested_path
|
42
|
+
self
|
36
43
|
end
|
37
44
|
|
38
45
|
def _root
|
data/lib/lhs/proxy.rb
CHANGED
data/lib/lhs/version.rb
CHANGED
data/spec/record/reload_spec.rb
CHANGED
@@ -21,4 +21,43 @@ describe LHS::Record do
|
|
21
21
|
expect(record.reload!).to be_kind_of Record
|
22
22
|
end
|
23
23
|
end
|
24
|
+
|
25
|
+
context 'nested items' do
|
26
|
+
|
27
|
+
before(:each) do
|
28
|
+
class Location < LHS::Record
|
29
|
+
endpoint 'http://uberall/locations'
|
30
|
+
endpoint 'http://uberall/locations/:id'
|
31
|
+
|
32
|
+
configuration item_key: [:response, :location], items_key: [:response, :locations]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'merges reloads properly' do
|
37
|
+
stub_request(:get, "http://uberall/locations?identifier=http://places/1&limit=1")
|
38
|
+
.to_return(
|
39
|
+
body: {
|
40
|
+
response: {
|
41
|
+
locations: [{
|
42
|
+
id: 1,
|
43
|
+
name: 'Fridolin'
|
44
|
+
}]
|
45
|
+
}
|
46
|
+
}.to_json
|
47
|
+
)
|
48
|
+
location = Location.find_by(identifier: 'http://places/1')
|
49
|
+
stub_request(:get, "http://uberall/locations/1")
|
50
|
+
.to_return(
|
51
|
+
body: {
|
52
|
+
response: {
|
53
|
+
location: {
|
54
|
+
normalizationStatus: 'NORMALIZED'
|
55
|
+
}
|
56
|
+
}
|
57
|
+
}.to_json
|
58
|
+
)
|
59
|
+
location.reload!
|
60
|
+
expect(location.normalizationStatus).to eq 'NORMALIZED'
|
61
|
+
end
|
62
|
+
end
|
24
63
|
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: 14.3.
|
4
|
+
version: 14.3.2
|
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-10-
|
11
|
+
date: 2017-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: lhc
|