customerio 4.3.2 → 5.1.0
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/CHANGELOG.markdown +4 -0
- data/README.md +41 -1
- data/lib/customerio/api.rb +19 -0
- data/lib/customerio/requests/send_email_request.rb +2 -2
- data/lib/customerio/requests/send_push_request.rb +36 -0
- data/lib/customerio/version.rb +1 -1
- data/lib/customerio.rb +1 -0
- data/spec/api_client_spec.rb +84 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18279a486386052aa99a48c56652ac566bf6abc973a6428af4d5886ec2ac3b85
|
4
|
+
data.tar.gz: dcaef6f328effd4cf6dc820e81b27661e440ce79d2af33b6736da544be30a0e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bad65a5e1d2097aa9db014e71d2c1c310546ec57ce4efa002484a28d6a9031fd5db48a221659d74861ce7a7ff07489b4b8ac956ba11b7b7cadab4eabed730a98
|
7
|
+
data.tar.gz: ce94e157fd6145afdaf303b1a6a91a5f2eeb9e8ea581d60acad95834e39bba788489c50e164070e83d4232bdb4c692315772bc52c0220676c216d26eeb217f1a
|
data/CHANGELOG.markdown
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## Customerio 5.1.0 - May 5, 2023
|
2
|
+
### Added
|
3
|
+
- Added `send_push` to `APIClient` and `SendPushRequest` to support sending transactional push notifications.
|
4
|
+
|
1
5
|
## Customerio 4.3.1 - January 5, 2023
|
2
6
|
### Added
|
3
7
|
- Added the `disable_css_preprocessing` and `language` optional fields to send request
|
data/README.md
CHANGED
@@ -217,7 +217,9 @@ $customerio.unsuppress(5)
|
|
217
217
|
|
218
218
|
### Send Transactional Messages
|
219
219
|
|
220
|
-
To use the Customer.io [Transactional API](https://customer.io/docs/transactional-api), create an instance of the API client using an [app key](https://customer.io/docs/managing-credentials#app-api-keys).
|
220
|
+
To use the Customer.io [Transactional API](https://customer.io/docs/transactional-api), create an instance of the API client using an [app key](https://customer.io/docs/managing-credentials#app-api-keys) and create a request object of your message type.
|
221
|
+
|
222
|
+
#### Email
|
221
223
|
|
222
224
|
Create a new `SendEmailRequest` object containing:
|
223
225
|
|
@@ -262,6 +264,44 @@ rescue Customerio::InvalidResponse => e
|
|
262
264
|
end
|
263
265
|
```
|
264
266
|
|
267
|
+
#### Push
|
268
|
+
|
269
|
+
Create a new `SendPushRequest` object containing:
|
270
|
+
|
271
|
+
* `transactional_message_id`: the ID or trigger name of the transactional message you want to send.
|
272
|
+
* an `identifiers` object containing the `id` or `email` of your recipient. If the profile does not exist, Customer.io creates it.
|
273
|
+
|
274
|
+
Use `send_push` referencing your request to send a transactional message. [Learn more about transactional messages and `SendPushRequest` properties](https://customer.io/docs/transactional-api).
|
275
|
+
|
276
|
+
|
277
|
+
```ruby
|
278
|
+
require "customerio"
|
279
|
+
|
280
|
+
client = Customerio::APIClient.new("your API key", region: Customerio::Regions::US)
|
281
|
+
|
282
|
+
request = Customerio::SendPushRequest.new(
|
283
|
+
transactional_message_id: "3",
|
284
|
+
message_data: {
|
285
|
+
name: "Person",
|
286
|
+
items: {
|
287
|
+
name: "shoes",
|
288
|
+
price: "59.99",
|
289
|
+
},
|
290
|
+
products: [],
|
291
|
+
},
|
292
|
+
identifiers: {
|
293
|
+
id: "2",
|
294
|
+
},
|
295
|
+
)
|
296
|
+
|
297
|
+
begin
|
298
|
+
response = client.send_push(request)
|
299
|
+
puts response
|
300
|
+
rescue Customerio::InvalidResponse => e
|
301
|
+
puts e.code, e.message
|
302
|
+
end
|
303
|
+
```
|
304
|
+
|
265
305
|
## Contributing
|
266
306
|
|
267
307
|
1. Fork it
|
data/lib/customerio/api.rb
CHANGED
@@ -26,10 +26,29 @@ module Customerio
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
def send_push(req)
|
30
|
+
raise "request must be an instance of Customerio::SendPushRequest" unless req.is_a?(Customerio::SendPushRequest)
|
31
|
+
response = @client.request(:post, send_push_path, req.message)
|
32
|
+
|
33
|
+
case response
|
34
|
+
when Net::HTTPSuccess then
|
35
|
+
JSON.parse(response.body)
|
36
|
+
when Net::HTTPBadRequest then
|
37
|
+
json = JSON.parse(response.body)
|
38
|
+
raise Customerio::InvalidResponse.new(response.code, json['meta']['error'], response)
|
39
|
+
else
|
40
|
+
raise InvalidResponse.new(response.code, response.body)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
29
44
|
private
|
30
45
|
|
31
46
|
def send_email_path
|
32
47
|
"/v1/send/email"
|
33
48
|
end
|
49
|
+
|
50
|
+
def send_push_path
|
51
|
+
"/v1/send/push"
|
52
|
+
end
|
34
53
|
end
|
35
54
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Customerio
|
2
|
+
class SendPushRequest
|
3
|
+
attr_reader :message
|
4
|
+
|
5
|
+
def initialize(opts)
|
6
|
+
@message = opts.delete_if { |field| invalid_field?(field) }
|
7
|
+
@message[:custom_device] = opts[:device] if opts[:device]
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
REQUIRED_FIELDS = %i(transactional_message_id identifiers)
|
13
|
+
|
14
|
+
OPTIONAL_FIELDS = %i(
|
15
|
+
to
|
16
|
+
title
|
17
|
+
message
|
18
|
+
disable_message_retention
|
19
|
+
send_to_unsubscribed
|
20
|
+
queue_draft
|
21
|
+
message_data
|
22
|
+
send_at
|
23
|
+
language
|
24
|
+
image_url
|
25
|
+
link
|
26
|
+
sound
|
27
|
+
custom_data
|
28
|
+
device
|
29
|
+
custom_device
|
30
|
+
)
|
31
|
+
|
32
|
+
def invalid_field?(field)
|
33
|
+
!REQUIRED_FIELDS.include?(field) && !OPTIONAL_FIELDS.include?(field)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/customerio/version.rb
CHANGED
data/lib/customerio.rb
CHANGED
data/spec/api_client_spec.rb
CHANGED
@@ -6,7 +6,7 @@ require 'tempfile'
|
|
6
6
|
describe Customerio::APIClient do
|
7
7
|
let(:app_key) { "appkey" }
|
8
8
|
|
9
|
-
let(:client)
|
9
|
+
let(:client) { Customerio::APIClient.new(app_key) }
|
10
10
|
let(:response) { double("Response", code: 200) }
|
11
11
|
|
12
12
|
def api_uri(path)
|
@@ -169,4 +169,87 @@ describe Customerio::APIClient do
|
|
169
169
|
req.message[:attachments].should eq({ "test" => Base64.strict_encode64("test-content") })
|
170
170
|
end
|
171
171
|
end
|
172
|
+
|
173
|
+
describe "#send_push" do
|
174
|
+
it "sends a POST request to the /api/send/push path" do
|
175
|
+
req = Customerio::SendPushRequest.new(
|
176
|
+
identifiers: {
|
177
|
+
id: 'c1',
|
178
|
+
},
|
179
|
+
transactional_message_id: 1,
|
180
|
+
)
|
181
|
+
|
182
|
+
stub_request(:post, api_uri('/v1/send/push'))
|
183
|
+
.with(headers: request_headers, body: req.message)
|
184
|
+
.to_return(status: 200, body: { delivery_id: 1 }.to_json, headers: {})
|
185
|
+
|
186
|
+
client.send_push(req).should eq({ "delivery_id" => 1 })
|
187
|
+
end
|
188
|
+
|
189
|
+
it "handles validation failures (400)" do
|
190
|
+
req = Customerio::SendPushRequest.new(
|
191
|
+
identifiers: {
|
192
|
+
id: 'c1',
|
193
|
+
},
|
194
|
+
transactional_message_id: 1,
|
195
|
+
)
|
196
|
+
|
197
|
+
err_json = { meta: { error: "example error" } }.to_json
|
198
|
+
|
199
|
+
stub_request(:post, api_uri('/v1/send/push'))
|
200
|
+
.with(headers: request_headers, body: req.message)
|
201
|
+
.to_return(status: 400, body: err_json, headers: {})
|
202
|
+
|
203
|
+
lambda { client.send_push(req) }.should(
|
204
|
+
raise_error(Customerio::InvalidResponse) { |error|
|
205
|
+
error.message.should eq "example error"
|
206
|
+
error.code.should eq "400"
|
207
|
+
}
|
208
|
+
)
|
209
|
+
end
|
210
|
+
|
211
|
+
it "handles other failures (5xx)" do
|
212
|
+
req = Customerio::SendPushRequest.new(
|
213
|
+
identifiers: {
|
214
|
+
id: 'c1',
|
215
|
+
},
|
216
|
+
transactional_message_id: 1,
|
217
|
+
)
|
218
|
+
|
219
|
+
stub_request(:post, api_uri('/v1/send/push'))
|
220
|
+
.with(headers: request_headers, body: req.message)
|
221
|
+
.to_return(status: 500, body: "Server unavailable", headers: {})
|
222
|
+
|
223
|
+
lambda { client.send_push(req) }.should(
|
224
|
+
raise_error(Customerio::InvalidResponse) { |error|
|
225
|
+
error.message.should eq "Server unavailable"
|
226
|
+
error.code.should eq "500"
|
227
|
+
}
|
228
|
+
)
|
229
|
+
end
|
230
|
+
|
231
|
+
it "sets custom_device correctly if device present in req" do
|
232
|
+
req = Customerio::SendPushRequest.new(
|
233
|
+
identifiers: {
|
234
|
+
id: 'c1',
|
235
|
+
},
|
236
|
+
transactional_message_id: 1,
|
237
|
+
device: {
|
238
|
+
platform: 'ios',
|
239
|
+
token: 'sample-token',
|
240
|
+
}
|
241
|
+
)
|
242
|
+
|
243
|
+
req.message[:custom_device].should eq({
|
244
|
+
platform: 'ios',
|
245
|
+
token: 'sample-token',
|
246
|
+
})
|
247
|
+
|
248
|
+
stub_request(:post, api_uri('/v1/send/push'))
|
249
|
+
.with(headers: request_headers, body: req.message)
|
250
|
+
.to_return(status: 200, body: { delivery_id: 2 }.to_json, headers: {})
|
251
|
+
|
252
|
+
client.send_push(req).should eq({ "delivery_id" => 2 })
|
253
|
+
end
|
254
|
+
end
|
172
255
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: customerio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Allison
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-05-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/customerio/param_encoder.rb
|
118
118
|
- lib/customerio/regions.rb
|
119
119
|
- lib/customerio/requests/send_email_request.rb
|
120
|
+
- lib/customerio/requests/send_push_request.rb
|
120
121
|
- lib/customerio/version.rb
|
121
122
|
- spec/api_client_spec.rb
|
122
123
|
- spec/base_client_spec.rb
|
@@ -126,7 +127,7 @@ homepage: http://customer.io
|
|
126
127
|
licenses:
|
127
128
|
- MIT
|
128
129
|
metadata: {}
|
129
|
-
post_install_message:
|
130
|
+
post_install_message:
|
130
131
|
rdoc_options: []
|
131
132
|
require_paths:
|
132
133
|
- lib
|
@@ -141,8 +142,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
142
|
- !ruby/object:Gem::Version
|
142
143
|
version: '0'
|
143
144
|
requirements: []
|
144
|
-
rubygems_version: 3.3.
|
145
|
-
signing_key:
|
145
|
+
rubygems_version: 3.0.3.1
|
146
|
+
signing_key:
|
146
147
|
specification_version: 4
|
147
148
|
summary: A ruby client for the Customer.io event API.
|
148
149
|
test_files:
|