lhs 7.0.0 → 7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aa6cec36b44adf1e4a4ec191be5ddadeade8df99
4
- data.tar.gz: 504a4cbb77242734dc54a9545d8871325ff1467b
3
+ metadata.gz: 2e11e78d3dd76e163a20dd38f8873322ff71ff81
4
+ data.tar.gz: 763cb822c37ca6e938cfd8f9a7f7014a1f47dc7f
5
5
  SHA512:
6
- metadata.gz: 2980127f21442628806801f96bf5cae65b7fd426a45639b739831e2f9cf06480c2f2fb0d4317b5d7604e6f68703d2306113371ca360be92bcc5ddc497301d90c
7
- data.tar.gz: f61ba980791188f4bed6dd59c3f67c9334f77871fa60e5e97c3bba4b2142346ee3b8d799293ec348405cb85b4af8a53353943b932293da5b910512da14a0562f
6
+ metadata.gz: 970ba3f98020e099502f5dcf768d0efc0e40bb147be2f334cd5429dbec35543fd0b6157459f45a7c293e7ecd08a2ffae951e06aba758eabae61d15baf2fe220a
7
+ data.tar.gz: 00d4680483a466f6ae84487c3ed1d6c014e493ee2c120f47cef1a35c4a1e8ad5a5ea6c2d0f58a741715db146ee14d141771ef0688234e9395ac2fd88f12bd283
@@ -14,15 +14,15 @@ class LHS::Item < LHS::Proxy
14
14
  end
15
15
 
16
16
  def save!(options = {})
17
- options ||= {}
18
- record = _data.class
17
+ options = options.present? ? options.dup : {}
19
18
  data = _data._raw.dup
20
19
  if href.present?
21
20
  url = href
22
21
  else
23
- endpoint = record.find_endpoint(data)
24
- url = endpoint.compile(data)
22
+ endpoint = endpoint_for_persistance(data, options)
23
+ url = url_for_persistance(endpoint, data, options)
25
24
  endpoint.remove_interpolated_params!(data)
25
+ endpoint.remove_interpolated_params!(options.fetch(:params, {}))
26
26
  options.merge!(endpoint.options.merge(options)) if endpoint.options
27
27
  end
28
28
 
@@ -30,9 +30,34 @@ class LHS::Item < LHS::Proxy
30
30
  options[:headers] ||= {}
31
31
  options[:headers].merge!('Content-Type' => 'application/json')
32
32
 
33
- data = record.request(options)
33
+ data = record_for_persistance.request(options)
34
34
  _data.merge_raw!(data)
35
35
  true
36
36
  end
37
+
38
+ private
39
+
40
+ def endpoint_for_persistance(data, options)
41
+ record_for_persistance
42
+ .find_endpoint(merge_data_with_options(data, options))
43
+ end
44
+
45
+ def merge_data_with_options(data, options)
46
+ if options && options[:params]
47
+ data.merge(options[:params])
48
+ else
49
+ data
50
+ end
51
+ end
52
+
53
+ def record_for_persistance
54
+ _data.class
55
+ end
56
+
57
+ def url_for_persistance(endpoint, data, options)
58
+ endpoint.compile(
59
+ merge_data_with_options(data, options)
60
+ )
61
+ end
37
62
  end
38
63
  end
@@ -1,3 +1,3 @@
1
1
  module LHS
2
- VERSION = "7.0.0"
2
+ VERSION = "7.0.1"
3
3
  end
@@ -14,14 +14,24 @@ describe LHS::Record do
14
14
  let(:campaign_id) { 12345 }
15
15
  let(:object) { { recommended: true } }
16
16
  let(:item) { Feedback.new(object.merge(campaign_id: campaign_id)) }
17
-
18
- it 'removes params used to compute url from send data' do
19
- datastore_request = stub_request(:post, "#{datastore}/content-ads/#{campaign_id}/feedbacks")
17
+ let!(:request) do
18
+ stub_request(:post, "#{datastore}/content-ads/#{campaign_id}/feedbacks")
20
19
  .with(body: object.to_json)
21
20
  .to_return(status: 200, body: object.to_json)
21
+ end
22
22
 
23
+ it 'removes params used to compute url from send data' do
23
24
  item.save!
24
- expect(datastore_request).to have_been_made.once
25
+ expect(request).to have_been_made.once
26
+ end
27
+
28
+ context 'item without data' do
29
+ let(:item) { Feedback.new(object) }
30
+
31
+ it 'takes params to find endpoint also from the options' do
32
+ item.save!(params: { campaign_id: campaign_id })
33
+ expect(request).to have_been_made.once
34
+ end
25
35
  end
26
36
  end
27
37
  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: 7.0.0
4
+ version: 7.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: 2016-11-16 00:00:00.000000000 Z
11
+ date: 2016-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lhc