customerio 5.3.0 → 5.5.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/.github/workflows/main.yml +3 -3
- data/CHANGELOG.markdown +4 -0
- data/README.md +4 -5
- data/customerio.gemspec +1 -0
- data/lib/customerio/api.rb +38 -0
- data/lib/customerio/requests/send_inbox_message_request.rb +31 -0
- data/lib/customerio/requests/send_sms_request.rb +42 -0
- data/lib/customerio/version.rb +1 -1
- data/lib/customerio.rb +2 -0
- data/spec/api_client_spec.rb +118 -0
- metadata +22 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: db681e306c4d3d780852f5aa18546de96e63bde2149e7ea92e44e64f07ef2fdf
|
|
4
|
+
data.tar.gz: 695ef4db24d55f7da1ece9ac0f95e6813bd179db20fd15dc034b1a7660c9682f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 630d232d3851e8abfaa1fa3c0806dda7496199f3d928d26e315d3b2c9bc234c9deeafff2c3d332b624664e355dcaaa54caf935337e8464073c08cfc4ad00a06a
|
|
7
|
+
data.tar.gz: 0d58478028485b1881e1996cfcc545bae0f33304698a84f2df2288a838ef8bc650e905b55ae80e51c84a7328930ba5bc4dc07051d551f28092a770143a47677e
|
data/.github/workflows/main.yml
CHANGED
|
@@ -6,13 +6,13 @@ jobs:
|
|
|
6
6
|
test:
|
|
7
7
|
strategy:
|
|
8
8
|
matrix:
|
|
9
|
-
ruby: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2']
|
|
9
|
+
ruby: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4']
|
|
10
10
|
runs-on: ubuntu-latest
|
|
11
11
|
env:
|
|
12
12
|
BUNDLE_PATH: ${{ github.workspace }}/vendor/bundle
|
|
13
13
|
steps:
|
|
14
|
-
- uses: actions/checkout@
|
|
15
|
-
- uses: ruby/setup-ruby@v1
|
|
14
|
+
- uses: actions/checkout@v4
|
|
15
|
+
- uses: ruby/setup-ruby@354a1ad156761f5ee2b7b13fa8e09943a5e8d252 # v1.229.0
|
|
16
16
|
with:
|
|
17
17
|
ruby-version: ${{ matrix.ruby }}
|
|
18
18
|
bundler-cache: true
|
data/CHANGELOG.markdown
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
## Customerio 5.4.0 - June 13, 2025
|
|
2
|
+
### Changed
|
|
3
|
+
- Added `send_sms` to `APIClient` and `SendSMSRequest` to support sending transactional push notifications.
|
|
4
|
+
|
|
1
5
|
## Customerio 5.3.0 - December 8, 2023
|
|
2
6
|
### Changed
|
|
3
7
|
- The `identify` method has been updated to allow the customer ID to be specified separately from the attributes, using the `customer_id` attribute. This allows a person to be updated by identifying them by e.g.: their email address. Thanks to trwalzer, jrbeck and jeremyw for the original changes that this is based on.
|
data/README.md
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
<p align=
|
|
1
|
+
<p align=center>
|
|
2
2
|
<a href="https://customer.io">
|
|
3
|
-
<img src="https://
|
|
3
|
+
<img src="https://avatars.githubusercontent.com/u/1152079?s=200&v=4" height="60">
|
|
4
4
|
</a>
|
|
5
|
-
<p align="center">Power automated communication that people like to receive.</p>
|
|
6
5
|
</p>
|
|
7
6
|
|
|
8
7
|
[](https://gitpod.io/#https://github.com/customerio/customerio-ruby/)
|
|
9
8
|
[](https://github.com/customerio/customerio-ruby/actions/workflows/main.yml)
|
|
10
9
|
|
|
11
|
-
# Customer.io Ruby
|
|
10
|
+
# Customer.io Ruby
|
|
12
11
|
|
|
13
|
-
A ruby client for the [Customer.io Track API](https://customer.io/docs/api
|
|
12
|
+
A ruby client for the [Customer.io Journeys Track API](https://customer.io/docs/api/track/).
|
|
14
13
|
|
|
15
14
|
## Installation
|
|
16
15
|
|
data/customerio.gemspec
CHANGED
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
|
|
|
18
18
|
|
|
19
19
|
gem.add_dependency('multi_json', "~> 1.0")
|
|
20
20
|
gem.add_dependency('addressable', '~> 2.8.0')
|
|
21
|
+
gem.add_dependency('base64', '~> 0.3.0')
|
|
21
22
|
|
|
22
23
|
gem.add_development_dependency('rake', '~> 10.5')
|
|
23
24
|
gem.add_development_dependency('rspec', '~> 3.10')
|
data/lib/customerio/api.rb
CHANGED
|
@@ -41,6 +41,36 @@ module Customerio
|
|
|
41
41
|
end
|
|
42
42
|
end
|
|
43
43
|
|
|
44
|
+
def send_sms(req)
|
|
45
|
+
raise "request must be an instance of Customerio::SendSMSRequest" unless req.is_a?(Customerio::SendSMSRequest)
|
|
46
|
+
response = @client.request(:post, send_sms_path, req.message)
|
|
47
|
+
|
|
48
|
+
case response
|
|
49
|
+
when Net::HTTPSuccess then
|
|
50
|
+
JSON.parse(response.body)
|
|
51
|
+
when Net::HTTPBadRequest then
|
|
52
|
+
json = JSON.parse(response.body)
|
|
53
|
+
raise Customerio::InvalidResponse.new(response.code, json['meta']['error'], response)
|
|
54
|
+
else
|
|
55
|
+
raise InvalidResponse.new(response.code, response.body)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def send_inbox_message(req)
|
|
60
|
+
raise "request must be an instance of Customerio::SendInboxMessageRequest" unless req.is_a?(Customerio::SendInboxMessageRequest)
|
|
61
|
+
response = @client.request(:post, send_inbox_message_path, req.message)
|
|
62
|
+
|
|
63
|
+
case response
|
|
64
|
+
when Net::HTTPSuccess then
|
|
65
|
+
JSON.parse(response.body)
|
|
66
|
+
when Net::HTTPBadRequest then
|
|
67
|
+
json = JSON.parse(response.body)
|
|
68
|
+
raise Customerio::InvalidResponse.new(response.code, json['meta']['error'], response)
|
|
69
|
+
else
|
|
70
|
+
raise InvalidResponse.new(response.code, response.body)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
44
74
|
private
|
|
45
75
|
|
|
46
76
|
def send_email_path
|
|
@@ -50,5 +80,13 @@ module Customerio
|
|
|
50
80
|
def send_push_path
|
|
51
81
|
"/v1/send/push"
|
|
52
82
|
end
|
|
83
|
+
|
|
84
|
+
def send_sms_path
|
|
85
|
+
"/v1/send/sms"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def send_inbox_message_path
|
|
89
|
+
"/v1/send/inbox_message"
|
|
90
|
+
end
|
|
53
91
|
end
|
|
54
92
|
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'base64'
|
|
2
|
+
|
|
3
|
+
module Customerio
|
|
4
|
+
class SendInboxMessageRequest
|
|
5
|
+
attr_reader :message
|
|
6
|
+
|
|
7
|
+
def initialize(opts)
|
|
8
|
+
@message = opts.delete_if { |field| invalid_field?(field) }
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
REQUIRED_FIELDS = %i(identifiers transactional_message_id)
|
|
14
|
+
|
|
15
|
+
OPTIONAL_FIELDS = %i(
|
|
16
|
+
message_data
|
|
17
|
+
disable_message_retention
|
|
18
|
+
queue_draft
|
|
19
|
+
send_at
|
|
20
|
+
language
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
def invalid_field?(field)
|
|
24
|
+
!REQUIRED_FIELDS.include?(field) && !OPTIONAL_FIELDS.include?(field)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def encode(data)
|
|
28
|
+
Base64.strict_encode64(data)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
require 'base64'
|
|
2
|
+
|
|
3
|
+
module Customerio
|
|
4
|
+
class SendSMSRequest
|
|
5
|
+
attr_reader :message
|
|
6
|
+
|
|
7
|
+
def initialize(opts)
|
|
8
|
+
@message = opts.delete_if { |field| invalid_field?(field) }
|
|
9
|
+
@message[:attachments] = {}
|
|
10
|
+
@message[:headers] = {}
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def attach(name, data, encode: true)
|
|
14
|
+
raise "attachment #{name} already exists" if @message[:attachments].has_key?(name)
|
|
15
|
+
@message[:attachments][name] = encode ? Base64.strict_encode64(data) : data
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
REQUIRED_FIELDS = %i(identifiers transactional_message_id)
|
|
21
|
+
|
|
22
|
+
OPTIONAL_FIELDS = %i(
|
|
23
|
+
message_data
|
|
24
|
+
from
|
|
25
|
+
to
|
|
26
|
+
disable_message_retention
|
|
27
|
+
send_to_unsubscribed
|
|
28
|
+
tracked
|
|
29
|
+
queue_draft
|
|
30
|
+
send_at
|
|
31
|
+
language
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
def invalid_field?(field)
|
|
35
|
+
!REQUIRED_FIELDS.include?(field) && !OPTIONAL_FIELDS.include?(field)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def encode(data)
|
|
39
|
+
Base64.strict_encode64(data)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
data/lib/customerio/version.rb
CHANGED
data/lib/customerio.rb
CHANGED
|
@@ -6,6 +6,8 @@ module Customerio
|
|
|
6
6
|
require "customerio/client"
|
|
7
7
|
require "customerio/requests/send_email_request"
|
|
8
8
|
require "customerio/requests/send_push_request"
|
|
9
|
+
require "customerio/requests/send_sms_request"
|
|
10
|
+
require "customerio/requests/send_inbox_message_request"
|
|
9
11
|
require "customerio/api"
|
|
10
12
|
require "customerio/param_encoder"
|
|
11
13
|
end
|
data/spec/api_client_spec.rb
CHANGED
|
@@ -252,4 +252,122 @@ describe Customerio::APIClient do
|
|
|
252
252
|
client.send_push(req).should eq({ "delivery_id" => 2 })
|
|
253
253
|
end
|
|
254
254
|
end
|
|
255
|
+
|
|
256
|
+
describe "#send_sms" do
|
|
257
|
+
it "sends a POST request to the /api/send/sms path" do
|
|
258
|
+
req = Customerio::SendSMSRequest.new(
|
|
259
|
+
identifiers: {
|
|
260
|
+
id: 'c1',
|
|
261
|
+
},
|
|
262
|
+
transactional_message_id: 1,
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
stub_request(:post, api_uri('/v1/send/sms'))
|
|
266
|
+
.with(headers: request_headers, body: req.message)
|
|
267
|
+
.to_return(status: 200, body: { delivery_id: 1 }.to_json, headers: {})
|
|
268
|
+
|
|
269
|
+
client.send_sms(req).should eq({ "delivery_id" => 1 })
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
it "handles validation failures (400)" do
|
|
273
|
+
req = Customerio::SendSMSRequest.new(
|
|
274
|
+
identifiers: {
|
|
275
|
+
id: 'c1',
|
|
276
|
+
},
|
|
277
|
+
transactional_message_id: 1,
|
|
278
|
+
)
|
|
279
|
+
|
|
280
|
+
err_json = { meta: { error: "example error" } }.to_json
|
|
281
|
+
|
|
282
|
+
stub_request(:post, api_uri('/v1/send/sms'))
|
|
283
|
+
.with(headers: request_headers, body: req.message)
|
|
284
|
+
.to_return(status: 400, body: err_json, headers: {})
|
|
285
|
+
|
|
286
|
+
lambda { client.send_sms(req) }.should(
|
|
287
|
+
raise_error(Customerio::InvalidResponse) { |error|
|
|
288
|
+
error.message.should eq "example error"
|
|
289
|
+
error.code.should eq "400"
|
|
290
|
+
}
|
|
291
|
+
)
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
it "handles other failures (5xx)" do
|
|
295
|
+
req = Customerio::SendSMSRequest.new(
|
|
296
|
+
identifiers: {
|
|
297
|
+
id: 'c1',
|
|
298
|
+
},
|
|
299
|
+
transactional_message_id: 1,
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
stub_request(:post, api_uri('/v1/send/sms'))
|
|
303
|
+
.with(headers: request_headers, body: req.message)
|
|
304
|
+
.to_return(status: 500, body: "Server unavailable", headers: {})
|
|
305
|
+
|
|
306
|
+
lambda { client.send_sms(req) }.should(
|
|
307
|
+
raise_error(Customerio::InvalidResponse) { |error|
|
|
308
|
+
error.message.should eq "Server unavailable"
|
|
309
|
+
error.code.should eq "500"
|
|
310
|
+
}
|
|
311
|
+
)
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
describe "#send_inbox_message" do
|
|
316
|
+
it "sends a POST request to the /api/send/inbox_message path" do
|
|
317
|
+
req = Customerio::SendInboxMessageRequest.new(
|
|
318
|
+
identifiers: {
|
|
319
|
+
id: 'c1',
|
|
320
|
+
},
|
|
321
|
+
transactional_message_id: 1,
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
stub_request(:post, api_uri('/v1/send/inbox_message'))
|
|
325
|
+
.with(headers: request_headers, body: req.message)
|
|
326
|
+
.to_return(status: 200, body: { delivery_id: 1 }.to_json, headers: {})
|
|
327
|
+
|
|
328
|
+
client.send_inbox_message(req).should eq({ "delivery_id" => 1 })
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
it "handles validation failures (400)" do
|
|
332
|
+
req = Customerio::SendInboxMessageRequest.new(
|
|
333
|
+
identifiers: {
|
|
334
|
+
id: 'c1',
|
|
335
|
+
},
|
|
336
|
+
transactional_message_id: 1,
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
err_json = { meta: { error: "example error" } }.to_json
|
|
340
|
+
|
|
341
|
+
stub_request(:post, api_uri('/v1/send/inbox_message'))
|
|
342
|
+
.with(headers: request_headers, body: req.message)
|
|
343
|
+
.to_return(status: 400, body: err_json, headers: {})
|
|
344
|
+
|
|
345
|
+
lambda { client.send_inbox_message(req) }.should(
|
|
346
|
+
raise_error(Customerio::InvalidResponse) { |error|
|
|
347
|
+
error.message.should eq "example error"
|
|
348
|
+
error.code.should eq "400"
|
|
349
|
+
}
|
|
350
|
+
)
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
it "handles other failures (5xx)" do
|
|
354
|
+
req = Customerio::SendInboxMessageRequest.new(
|
|
355
|
+
identifiers: {
|
|
356
|
+
id: 'c1',
|
|
357
|
+
},
|
|
358
|
+
transactional_message_id: 1,
|
|
359
|
+
)
|
|
360
|
+
|
|
361
|
+
stub_request(:post, api_uri('/v1/send/inbox_message'))
|
|
362
|
+
.with(headers: request_headers, body: req.message)
|
|
363
|
+
.to_return(status: 500, body: "Server unavailable", headers: {})
|
|
364
|
+
|
|
365
|
+
lambda { client.send_inbox_message(req) }.should(
|
|
366
|
+
raise_error(Customerio::InvalidResponse) { |error|
|
|
367
|
+
error.message.should eq "Server unavailable"
|
|
368
|
+
error.code.should eq "500"
|
|
369
|
+
}
|
|
370
|
+
)
|
|
371
|
+
end
|
|
372
|
+
end
|
|
255
373
|
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: 5.
|
|
4
|
+
version: 5.5.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:
|
|
11
|
+
date: 2026-02-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: multi_json
|
|
@@ -38,6 +38,20 @@ dependencies:
|
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
40
|
version: 2.8.0
|
|
41
|
+
- !ruby/object:Gem::Dependency
|
|
42
|
+
name: base64
|
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - "~>"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: 0.3.0
|
|
48
|
+
type: :runtime
|
|
49
|
+
prerelease: false
|
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
51
|
+
requirements:
|
|
52
|
+
- - "~>"
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: 0.3.0
|
|
41
55
|
- !ruby/object:Gem::Dependency
|
|
42
56
|
name: rake
|
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -117,7 +131,9 @@ files:
|
|
|
117
131
|
- lib/customerio/param_encoder.rb
|
|
118
132
|
- lib/customerio/regions.rb
|
|
119
133
|
- lib/customerio/requests/send_email_request.rb
|
|
134
|
+
- lib/customerio/requests/send_inbox_message_request.rb
|
|
120
135
|
- lib/customerio/requests/send_push_request.rb
|
|
136
|
+
- lib/customerio/requests/send_sms_request.rb
|
|
121
137
|
- lib/customerio/version.rb
|
|
122
138
|
- spec/api_client_spec.rb
|
|
123
139
|
- spec/base_client_spec.rb
|
|
@@ -127,7 +143,7 @@ homepage: https://customer.io
|
|
|
127
143
|
licenses:
|
|
128
144
|
- MIT
|
|
129
145
|
metadata: {}
|
|
130
|
-
post_install_message:
|
|
146
|
+
post_install_message:
|
|
131
147
|
rdoc_options: []
|
|
132
148
|
require_paths:
|
|
133
149
|
- lib
|
|
@@ -142,8 +158,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
142
158
|
- !ruby/object:Gem::Version
|
|
143
159
|
version: '0'
|
|
144
160
|
requirements: []
|
|
145
|
-
rubygems_version: 3.
|
|
146
|
-
signing_key:
|
|
161
|
+
rubygems_version: 3.0.3.1
|
|
162
|
+
signing_key:
|
|
147
163
|
specification_version: 4
|
|
148
164
|
summary: A ruby client for the Customer.io event API.
|
|
149
165
|
test_files:
|