lhs 2.0.4 → 2.0.5
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/service/request.rb +13 -19
- data/lib/lhs/version.rb +1 -1
- data/spec/service/includes_spec.rb +15 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf11afeed9a8a7a43f2c594ad95dd909e1a12f0d
|
4
|
+
data.tar.gz: 885dacb37539493c398957242a4fba4c20e13a4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e854348297280962ce9553f22112b0f014462263f94eef3d18f870e4602524ac658679427927827230977c1052234d7dda39e6350b54bd1676599a1af83163c1
|
7
|
+
data.tar.gz: 760777a4f2e23e6a31509aa436417ce5abcff5a60805b5ec56a81fbe75594ac7b5562738179c16418b6c4203ae3563127e3729de94763924b392be4dcdd28506
|
@@ -45,39 +45,33 @@ class LHS::Service
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
-
def handle_includes(data)
|
48
|
+
def handle_includes(includes, data)
|
49
49
|
if includes.is_a? Hash
|
50
|
-
includes.
|
50
|
+
includes.each { |_include, sub_includes| handle_include(_include, data, sub_includes) }
|
51
51
|
elsif includes.is_a? Array
|
52
|
-
includes.each { |
|
52
|
+
includes.each { |_include| handle_includes(_include, data) }
|
53
53
|
else
|
54
|
-
handle_include(
|
54
|
+
handle_include(includes, data)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
-
def handle_include(data,
|
58
|
+
def handle_include(_include, data, sub_includes = nil)
|
59
59
|
return unless data.present?
|
60
60
|
options = if data._proxy.is_a? LHS::Collection
|
61
|
-
options_for_multiple(data,
|
61
|
+
options_for_multiple(data, _include)
|
62
62
|
else
|
63
|
-
url_option_for(data,
|
63
|
+
url_option_for(data, _include)
|
64
64
|
end
|
65
|
-
addition = load_include(
|
66
|
-
extend(data, addition,
|
65
|
+
addition = load_include(options, data, sub_includes)
|
66
|
+
extend(data, addition, _include)
|
67
67
|
end
|
68
68
|
|
69
69
|
# Load additional resources that are requested with include
|
70
|
-
def load_include(
|
70
|
+
def load_include(options, data, sub_includes)
|
71
71
|
service = service_for_options(options) || self
|
72
72
|
options = convert_options_to_endpoints(options) if service_for_options(options)
|
73
|
-
further_keys = includes.fetch(key, nil) if includes.is_a? Hash
|
74
|
-
service_class = if further_keys
|
75
|
-
service.class.includes(further_keys)
|
76
|
-
else
|
77
|
-
service.class.includes(nil)
|
78
|
-
end
|
79
73
|
begin
|
80
|
-
|
74
|
+
service.class.includes(sub_includes).instance.request(options)
|
81
75
|
rescue LHC::NotFound
|
82
76
|
LHS::Data.new({}, data, service)
|
83
77
|
end
|
@@ -96,7 +90,7 @@ class LHS::Service
|
|
96
90
|
responses = LHC.request(options)
|
97
91
|
data = responses.map{ |response| LHS::Data.new(response.body, nil, self.class, response.request) }
|
98
92
|
data = LHS::Data.new(data, nil, self.class)
|
99
|
-
handle_includes(data) if includes
|
93
|
+
handle_includes(includes, data) if includes
|
100
94
|
data
|
101
95
|
end
|
102
96
|
|
@@ -136,7 +130,7 @@ class LHS::Service
|
|
136
130
|
def single_request(options)
|
137
131
|
response = LHC.request(process_options(options))
|
138
132
|
data = LHS::Data.new(response.body, nil, self.class, response.request)
|
139
|
-
handle_includes(data) if includes
|
133
|
+
handle_includes(includes, data) if includes
|
140
134
|
data
|
141
135
|
end
|
142
136
|
|
data/lib/lhs/version.rb
CHANGED
@@ -120,6 +120,21 @@ describe LHS::Service do
|
|
120
120
|
expect(feedbacks.campaign.user.name).to eq 'Mario'
|
121
121
|
end
|
122
122
|
|
123
|
+
it 'includes list of linked resources while fetching a single resource from one service' do
|
124
|
+
|
125
|
+
stub_request(:get, "#{datastore}/feedbacks/123")
|
126
|
+
.to_return(status: 200, body: {
|
127
|
+
'href' => "#{datastore}/feedbacks/-Sc4_pYNpqfsudzhtivfkA",
|
128
|
+
'campaign' => { 'href' => "#{datastore}/content-ads/51dfc5690cf271c375c5a12d" },
|
129
|
+
'user' => { 'href' => "#{datastore}/users/lakj35asdflkj1203va" }
|
130
|
+
}.to_json)
|
131
|
+
|
132
|
+
feedbacks = Feedback.includes(:user, campaign: [:entry, :user]).find(123)
|
133
|
+
expect(feedbacks.campaign.entry.name).to eq 'Casa Ferlin'
|
134
|
+
expect(feedbacks.campaign.user.name).to eq 'Mario'
|
135
|
+
expect(feedbacks.user.name).to eq 'Mario'
|
136
|
+
end
|
137
|
+
|
123
138
|
context 'include objects from known services' do
|
124
139
|
|
125
140
|
let(:stub_feedback_request) do
|