constructorio 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4f1460ee4a45a554fdded5ffc3868e162a886f52
4
- data.tar.gz: 9d69a6002effdebb0247f07ae13e77a7de93366a
3
+ metadata.gz: d8aeef86fff7ce9f7baeb48332125b65315f63e1
4
+ data.tar.gz: e431cc58b523930af8078d70e506205790779f78
5
5
  SHA512:
6
- metadata.gz: 372bdfd4ff213924afbf4c88e92f638200e8d874d9634eedea1dadf3756c835d93c58868e37ed847759d865feeb954a7757fc72a44c5513ddac30232c61757c5
7
- data.tar.gz: 65d7a7c4ea26094244624b2ce94ce8bbe72209bbca8fb4e04f2b83b5683e839c56bbec59d0160d1ca104021b646fdea773461dc67ee654c83feef15056809faf
6
+ metadata.gz: 7e98301f67a9bddb1a7a668e43e1da270ded3e5387fbf5046678e1e1e5fc92360e2b7135c75f503b0a541f5677b40e63f963d15c7759a4750080daf6e0942029
7
+ data.tar.gz: eda3cc8a98784edf756c24a991b39129afdfee6c2d241805ddcb0c043771584a34e13bf9a0d74e51929554c5a7fa62723ecace4d8df4ed84f45acca2e6bc5372
@@ -17,6 +17,10 @@ module ConstructorIO
17
17
  call_api("item", "post", params)
18
18
  end
19
19
 
20
+ def add_or_update(params)
21
+ call_api("item", "put", params, {force: 1})
22
+ end
23
+
20
24
  def remove(params)
21
25
  call_api("item", "delete", params)
22
26
  end
@@ -45,21 +49,25 @@ module ConstructorIO
45
49
  call_api("batch_items", "post", params)
46
50
  end
47
51
 
52
+ def add_or_update_batch(params)
53
+ call_api("batch_items", "put", params, {force: 1})
54
+ end
55
+
48
56
  private
49
57
 
50
- def call_api(path, method, params = {})
58
+ def call_api(path, method, params = {}, additional_query_params = {})
51
59
  api_token = self.local_configuration.api_token
52
60
  api_url = self.local_configuration.api_url
53
61
  autocomplete_key = self.local_configuration.autocomplete_key
54
62
  @http_client ||= Faraday.new(url: api_url)
55
63
  @http_client.basic_auth(api_token, '')
56
64
 
57
- send_request(path, method, @http_client, params, autocomplete_key)
65
+ send_request(path, method, @http_client, params, autocomplete_key, additional_query_params)
58
66
  end
59
67
 
60
- def send_request(path, method, http_client, params, autocomplete_key)
68
+ def send_request(path, method, http_client, params, autocomplete_key, additional_query_params)
61
69
  response = http_client.send(method) do |request|
62
- request.url "/v1/#{path}?autocomplete_key=#{autocomplete_key}"
70
+ request.url "/v1/#{path}?autocomplete_key=#{autocomplete_key}#{URI.encode_www_form(additional_query_params)}"
63
71
  request.headers['Content-Type'] = 'application/json'
64
72
  request.body = params.to_json
65
73
  end
@@ -1,3 +1,3 @@
1
1
  module ConstructorIO
2
- VERSION = "2.0.8"
2
+ VERSION = "2.0.9"
3
3
  end
@@ -19,12 +19,39 @@ class ConstructorIOTest < MiniTest::Test
19
19
  "post",
20
20
  instance_of(Faraday::Connection),
21
21
  { item_name: "power drill" },
22
- "example_autocomplete_key"
22
+ "example_autocomplete_key",
23
+ {}
23
24
  )
24
25
 
25
26
  c.add( { item_name: "power drill" } )
26
27
  end
27
28
 
29
+ def test_add_or_update_record_calls_post
30
+ c = ConstructorIO::Client.new
31
+ c.expects(:call_api).with(
32
+ "item",
33
+ "put",
34
+ { item_name: "power drill" },
35
+ { force: 1 }
36
+ )
37
+
38
+ c.add_or_update( { item_name: "power drill" } )
39
+ end
40
+
41
+ def test_add_or_update_record_sends_request
42
+ c = ConstructorIO::Client.new
43
+ c.expects(:send_request).with(
44
+ "item",
45
+ "put",
46
+ instance_of(Faraday::Connection),
47
+ { item_name: "power drill" },
48
+ "example_autocomplete_key",
49
+ { force: 1 }
50
+ )
51
+
52
+ c.add_or_update( { item_name: "power drill" } )
53
+ end
54
+
28
55
  def test_add_record_sends_request_with_local_config
29
56
  c = ConstructorIO::Client.new(ConstructorIO::Configuration.new(
30
57
  api_token: "this-api-token",
@@ -36,7 +63,8 @@ class ConstructorIOTest < MiniTest::Test
36
63
  "post",
37
64
  instance_of(Faraday::Connection),
38
65
  { item_name: "power drill" },
39
- "this-autocomplete-key"
66
+ "this-autocomplete-key",
67
+ {}
40
68
  )
41
69
 
42
70
  c.add( { item_name: "power drill" } )
@@ -82,9 +110,81 @@ class ConstructorIOTest < MiniTest::Test
82
110
  "get",
83
111
  instance_of(Faraday::Connection),
84
112
  {},
85
- "example_autocomplete_key"
113
+ "example_autocomplete_key",
114
+ {}
86
115
  )
87
116
 
88
117
  c.verify
89
118
  end
119
+
120
+ def test_add_batch_calls_post
121
+ c = ConstructorIO::Client.new
122
+ c.expects(:call_api).with(
123
+ "batch_items",
124
+ "post",
125
+ { autocomplete_section: "Products", items: [ { item_name: "item" } ] }
126
+ )
127
+
128
+ c.add_batch(
129
+ {
130
+ autocomplete_section: "Products",
131
+ items: [ { item_name: "item" } ]
132
+ }
133
+ )
134
+ end
135
+
136
+ def test_add_batch_sends_request
137
+ c = ConstructorIO::Client.new
138
+ c.expects(:send_request).with(
139
+ "batch_items",
140
+ "post",
141
+ instance_of(Faraday::Connection),
142
+ { autocomplete_section: "Products", items: [ { item_name: "item" } ] },
143
+ "example_autocomplete_key",
144
+ {}
145
+ )
146
+
147
+ c.add_batch(
148
+ {
149
+ autocomplete_section: "Products",
150
+ items: [ { item_name: "item" } ]
151
+ }
152
+ )
153
+ end
154
+
155
+ def test_add_or_update_batch_calls_post
156
+ c = ConstructorIO::Client.new
157
+ c.expects(:call_api).with(
158
+ "batch_items",
159
+ "put",
160
+ { autocomplete_section: "Products", items: [ { item_name: "item" } ] },
161
+ { force: 1 }
162
+ )
163
+
164
+ c.add_or_update_batch(
165
+ {
166
+ autocomplete_section: "Products",
167
+ items: [ { item_name: "item" } ]
168
+ }
169
+ )
170
+ end
171
+
172
+ def test_add_or_update_batch_sends_request
173
+ c = ConstructorIO::Client.new
174
+ c.expects(:send_request).with(
175
+ "batch_items",
176
+ "put",
177
+ instance_of(Faraday::Connection),
178
+ { autocomplete_section: "Products", items: [ { item_name: "item" } ] },
179
+ "example_autocomplete_key",
180
+ { force: 1 }
181
+ )
182
+
183
+ c.add_or_update_batch(
184
+ {
185
+ autocomplete_section: "Products",
186
+ items: [ { item_name: "item" } ]
187
+ }
188
+ )
189
+ end
90
190
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: constructorio
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8
4
+ version: 2.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan McCormick
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-15 00:00:00.000000000 Z
11
+ date: 2016-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday