customerio 1.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -13
- data/.circleci/config.yml +61 -0
- data/CHANGELOG.markdown +80 -47
- data/README.md +90 -10
- data/customerio.gemspec +5 -4
- data/lib/customerio.rb +3 -0
- data/lib/customerio/api.rb +34 -0
- data/lib/customerio/base_client.rb +87 -0
- data/lib/customerio/client.rb +77 -94
- data/lib/customerio/requests/send_email_request.rb +49 -0
- data/lib/customerio/version.rb +1 -1
- data/spec/api_client_spec.rb +130 -0
- data/spec/base_client_spec.rb +67 -0
- data/spec/client_spec.rb +310 -163
- metadata +44 -37
- data/.travis.yml +0 -14
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YmMyODY3OTIxMjhkN2MxYzVlNzdlOWRiOTgxNzc2OWUyYWJjNDc0Ng==
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bd807525a01387116c22f29d0ac98e9b783fe669fd092da9d97cac74a660316d
|
4
|
+
data.tar.gz: 0ff5f3b518f07d5e3432a69e4a5738fd5bdeabc359593960bf9ac8f46081a7fc
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
YjFjNDg4N2Q5YzQwMWIxZGJkZWFmNzNlYTEzYjVkNWZlY2Q4MjgyNjM3MWNm
|
11
|
-
M2ZjMzU5MGUyMzljOTg0NTA0OWM5NDZkMDU4MTVlMzViNDEzYWU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YTMxNjA2NzJjNzU2ZDExNzBjZDYxODBhMDRiMTg1MWE3ZDIzMmI5YzcxYzE5
|
14
|
-
MGNhNTc5YTJmYjRmNjBlYTljODU3YzhiMGZiZGNkM2UyOTZhYzkyMWE0ZTBl
|
15
|
-
MGY2Mzg1YzMyMGYxNzg2NGY1YjY4YmFhZjkwYzVjN2IxYjNkYTE=
|
6
|
+
metadata.gz: 07a1b0e3472abe674a69413e81e6cf2b87c5002a3b074a26053efc0b8da2e7d91d380055c54409922d35ff2d876aeb22c956ce1ea246842ec1ce08ad3079f35b
|
7
|
+
data.tar.gz: eb291aab81e6e802a204d7c0b2d36890fa2ce26cf82c3af773a8cfddcacdc9b0d4fca7c684aee03a884bafdda4ac088c234294d197fe28041bae2573b186a1da
|
@@ -0,0 +1,61 @@
|
|
1
|
+
---
|
2
|
+
version: 2
|
3
|
+
|
4
|
+
references:
|
5
|
+
restore_cache: &restore_cache
|
6
|
+
type: cache-restore
|
7
|
+
name: Restore bundle cache
|
8
|
+
key: customerio-ruby-{{ checksum "customerio.gemspec" }}
|
9
|
+
|
10
|
+
save_cache: &save_cache
|
11
|
+
type: cache-save
|
12
|
+
name: Store bundle cache
|
13
|
+
key: customerio-ruby-{{ checksum "customerio.gemspec" }}
|
14
|
+
paths:
|
15
|
+
- vendor/bundle
|
16
|
+
|
17
|
+
jobs:
|
18
|
+
ruby_27:
|
19
|
+
working_directory: ~/customerio-ruby
|
20
|
+
docker:
|
21
|
+
- image: circleci/ruby:2.7.2
|
22
|
+
environment:
|
23
|
+
RAILS_ENV: test
|
24
|
+
steps:
|
25
|
+
- checkout
|
26
|
+
- *restore_cache
|
27
|
+
- run: bundle install
|
28
|
+
- *save_cache
|
29
|
+
- run: bundle exec rspec
|
30
|
+
ruby_26:
|
31
|
+
working_directory: ~/customerio-ruby
|
32
|
+
docker:
|
33
|
+
- image: circleci/ruby:2.6.6
|
34
|
+
environment:
|
35
|
+
RAILS_ENV: test
|
36
|
+
steps:
|
37
|
+
- checkout
|
38
|
+
- *restore_cache
|
39
|
+
- run: bundle install
|
40
|
+
- *save_cache
|
41
|
+
- run: bundle exec rspec
|
42
|
+
ruby_25:
|
43
|
+
working_directory: ~/customerio-ruby
|
44
|
+
docker:
|
45
|
+
- image: circleci/ruby:2.5.8
|
46
|
+
environment:
|
47
|
+
RAILS_ENV: test
|
48
|
+
steps:
|
49
|
+
- checkout
|
50
|
+
- *restore_cache
|
51
|
+
- run: bundle install
|
52
|
+
- *save_cache
|
53
|
+
- run: bundle exec rspec
|
54
|
+
|
55
|
+
workflows:
|
56
|
+
version: 2
|
57
|
+
test:
|
58
|
+
jobs:
|
59
|
+
- ruby_27
|
60
|
+
- ruby_26
|
61
|
+
- ruby_25
|
data/CHANGELOG.markdown
CHANGED
@@ -1,38 +1,71 @@
|
|
1
|
-
## Customerio
|
1
|
+
## Customerio 3.0.0 - Dec 2, 2020
|
2
|
+
|
3
|
+
### Added
|
4
|
+
- Support for the Transactional API
|
5
|
+
|
6
|
+
### Removed
|
7
|
+
- `add_to_segment` and `remove_from_segment` methods
|
8
|
+
- Support for non-JSON data
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
- IDs in the URLs are now escaped.
|
12
|
+
- Improved validations for data that's passed in.
|
13
|
+
- Earlier, if you passed in an event name without a customer ID to the `track` method, we would create an anonymous event. That is now removed. To create an anonymous event, use the `anonymous_track` method.
|
14
|
+
|
15
|
+
## Customerio 2.2.1 - Mar 23, 2020
|
16
|
+
|
17
|
+
- Add license to gemspec [#55](https://github.com/customerio/customerio-ruby/pull/55)
|
18
|
+
- Bubble up error message [#51](https://github.com/customerio/customerio-ruby/pull/51)
|
19
|
+
|
20
|
+
## Customerio 2.2.0 - Oct 18, 2018
|
21
|
+
|
22
|
+
Add support for manual segments [#52](https://github.com/customerio/customerio-ruby/pull/52)
|
23
|
+
|
24
|
+
## Customerio 2.1.0 - May 22, 2018
|
25
|
+
|
26
|
+
Added support for the suppress / unsuppress methods [#49](https://github.com/customerio/customerio-ruby/pull/49)
|
27
|
+
|
28
|
+
## Customerio 2.0.0 - Apr 10, 2018
|
29
|
+
|
30
|
+
With this release we have dropped the support for ruby 1.8.7.
|
31
|
+
|
32
|
+
- Support new add and remove device endpoints for push notifications [#47](https://github.com/customerio/customerio-ruby/pull/47)
|
33
|
+
|
34
|
+
## Customerio 1.0.0 - Mar 15, 2016
|
2
35
|
|
3
36
|
There is a slight breaking change in this release. If you are depending on the HTTP response object included in the InvalidResponse exception (introduced in 0.6.1), note that it is now a `Net::HTTPBadRequest`.
|
4
37
|
|
5
|
-
|
38
|
+
- Remove HTTParty dependency, use Net::HTTP instead. [#42](https://github.com/customerio/customerio-ruby/pull/42)
|
6
39
|
|
7
|
-
|
40
|
+
- Update test suite to use webmock, to increase confidence that we're not changing our HTTP requests [#41](https://github.com/customerio/customerio-ruby/pull/41)
|
8
41
|
|
9
|
-
## Customerio 0.7.0 - Mar 2, 2016
|
42
|
+
## Customerio 0.7.0 - Mar 2, 2016
|
10
43
|
|
11
|
-
|
44
|
+
- Add new method for tracking anonymous events: `anonymous_track`. See README for more details. Many thanks to @sdawson for this contribution! [#36](https://github.com/customerio/customerio-ruby/pull/36)
|
12
45
|
|
13
|
-
|
46
|
+
- Use JSON encoding by default. [#37](https://github.com/customerio/customerio-ruby/pull/37)
|
14
47
|
|
15
|
-
|
48
|
+
If you want to stick with form-encoding for your integration, you must add `:json => false` to your Customerio::Client initializer. Like this:
|
16
49
|
|
17
|
-
|
18
|
-
|
19
|
-
|
50
|
+
```ruby
|
51
|
+
customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY", :json => false)
|
52
|
+
```
|
20
53
|
|
21
|
-
## Customerio 0.6.1 - Oct 8, 2015
|
54
|
+
## Customerio 0.6.1 - Oct 8, 2015
|
22
55
|
|
23
|
-
|
56
|
+
- Include HTTP response as an attribute on the InvalidResponse exception to help with debugging failed API requests. For example:
|
24
57
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
58
|
+
```ruby
|
59
|
+
begin
|
60
|
+
$customerio.track(1, 'event', { :test => 'testing' })
|
61
|
+
rescue => e
|
62
|
+
puts e.message
|
63
|
+
puts e.response.status
|
64
|
+
puts e.response.body
|
65
|
+
end
|
66
|
+
```
|
34
67
|
|
35
|
-
## Customerio 0.6.0 - Oct 6, 2015
|
68
|
+
## Customerio 0.6.0 - Oct 6, 2015
|
36
69
|
|
37
70
|
Deprecation warning: we are going to switch to JSON encoding by default for the next release. The current default is form-encoding. This will probably not affect you, unless you rely on how form-encoding arrays work.
|
38
71
|
|
@@ -44,46 +77,46 @@ customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY", :json
|
|
44
77
|
|
45
78
|
Other fixes and improvements, with many thanks to the community contributors:
|
46
79
|
|
47
|
-
|
48
|
-
|
49
|
-
|
80
|
+
- Added HTTP timeout of 10 seconds (@stayhero)
|
81
|
+
- Added JSON support for events (@kemper)
|
82
|
+
- Convert attribute keys to symbols (@joshnabbott)
|
50
83
|
|
51
|
-
## Customerio 0.5.0 - Mar 28, 2014
|
84
|
+
## Customerio 0.5.0 - Mar 28, 2014
|
52
85
|
|
53
|
-
|
86
|
+
- Added flag to send body encoded as JSON, rather than the default form encoding.
|
54
87
|
|
55
|
-
## Customerio 0.5.0 - Apr 8, 2013
|
88
|
+
## Customerio 0.5.0 - Apr 8, 2013
|
56
89
|
|
57
|
-
|
58
|
-
|
90
|
+
- Removed deprecated methods around using a customer object. All calls simply take a hash of attributes now.
|
91
|
+
- Added ability to set a timestamp on a tracked event. Useful for backfilling past events.
|
59
92
|
|
60
|
-
## Customerio 0.4.1 - Feb 18, 2013
|
93
|
+
## Customerio 0.4.1 - Feb 18, 2013
|
61
94
|
|
62
|
-
|
95
|
+
- Bug fixes related to the 4.0 change.
|
63
96
|
|
64
|
-
## Customerio 0.4.0 - Feb 18, 2013
|
97
|
+
## Customerio 0.4.0 - Feb 18, 2013
|
65
98
|
|
66
|
-
|
99
|
+
- Added support for deleting customers.
|
67
100
|
|
68
|
-
## Customerio 0.3.0 - Dec 28, 2012
|
101
|
+
## Customerio 0.3.0 - Dec 28, 2012
|
69
102
|
|
70
|
-
|
71
|
-
|
103
|
+
- Now raise an error if an API call doesn't respond with a 200 response code
|
104
|
+
- Removed dependency on ActiveSupport
|
72
105
|
|
73
|
-
## Customerio 0.2.0 - Nov 21, 2012
|
106
|
+
## Customerio 0.2.0 - Nov 21, 2012
|
74
107
|
|
75
|
-
|
76
|
-
|
77
|
-
|
108
|
+
- Allow raw hashes to be passed into `identify` and `track` methods rather than a customer object.
|
109
|
+
- Passing a customer object has been depreciated.
|
110
|
+
- Customizing ids with `Customerio::Client.id` block is deprecated.
|
78
111
|
|
79
|
-
## Customerio 0.1.0 - Nov 15, 2012
|
112
|
+
## Customerio 0.1.0 - Nov 15, 2012
|
80
113
|
|
81
|
-
|
114
|
+
- Allow tracking of anonymous events.
|
82
115
|
|
83
|
-
## Customerio 0.0.3 - Nov 5, 2012
|
116
|
+
## Customerio 0.0.3 - Nov 5, 2012
|
84
117
|
|
85
|
-
|
118
|
+
- Bump httparty dependency to the latest version.
|
86
119
|
|
87
|
-
## Customerio 0.0.2 - May 22, 2012
|
120
|
+
## Customerio 0.0.2 - May 22, 2012
|
88
121
|
|
89
|
-
|
122
|
+
- First release.
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Customerio
|
2
2
|
|
3
|
-
A ruby client for the [Customer.io](http://customer.io) [event API](http://customer.io/
|
3
|
+
A ruby client for the [Customer.io](http://customer.io) [event API](http://learn.customer.io/api/).
|
4
4
|
|
5
5
|
[![Build Status](https://secure.travis-ci.org/customerio/customerio-ruby.png?branch=master)](http://travis-ci.org/customerio/customerio-ruby)
|
6
6
|
[![Code Climate](https://codeclimate.com/github/customerio/customerio-ruby/badges/gpa.svg)](https://codeclimate.com/github/customerio/customerio-ruby)
|
@@ -24,7 +24,7 @@ Or install it yourself:
|
|
24
24
|
### Before we get started: API client vs. JavaScript snippet
|
25
25
|
|
26
26
|
It's helpful to know that everything below can also be accomplished
|
27
|
-
through the [Customer.io JavaScript snippet](http://customer.io/
|
27
|
+
through the [Customer.io JavaScript snippet](http://learn.customer.io/developer-documentation/javascript-quick-start.html).
|
28
28
|
|
29
29
|
In many cases, using the JavaScript snippet will be easier to integrate with
|
30
30
|
your app, but there are several reasons why using the API client is useful:
|
@@ -43,7 +43,7 @@ You'll be able to integrate **fully** with [Customer.io](http://customer.io) wit
|
|
43
43
|
### Setup
|
44
44
|
|
45
45
|
Create an instance of the client with your [customer.io](http://customer.io) credentials
|
46
|
-
which can be found on the [customer.io integration screen](https://
|
46
|
+
which can be found on the [customer.io integration screen](https://fly.customer.io/account/customerio_integration).
|
47
47
|
|
48
48
|
If you're using Rails, create an initializer `config/initializers/customerio.rb`:
|
49
49
|
|
@@ -51,12 +51,6 @@ If you're using Rails, create an initializer `config/initializers/customerio.rb`
|
|
51
51
|
$customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY")
|
52
52
|
```
|
53
53
|
|
54
|
-
If you'd like to send complex data to associate to a user as json, pass a json option:
|
55
|
-
|
56
|
-
```ruby
|
57
|
-
customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY", :json => true)
|
58
|
-
```
|
59
|
-
|
60
54
|
### Identify logged in customers
|
61
55
|
|
62
56
|
Tracking data of logged in customers is a key part of [Customer.io](http://customer.io). In order to
|
@@ -142,7 +136,93 @@ You can also send anonymous events, for situations where you don't yet have a cu
|
|
142
136
|
$customerio.anonymous_track("help_enquiry", :recipient => 'user@example.com')
|
143
137
|
```
|
144
138
|
|
145
|
-
Use the `recipient` attribute to specify the email address to send the messages to. [See our documentation on how to use anonymous events for more details](https://customer.io/
|
139
|
+
Use the `recipient` attribute to specify the email address to send the messages to. [See our documentation on how to use anonymous events for more details](https://learn.customer.io/recipes/invite-emails.html).
|
140
|
+
|
141
|
+
### Adding a mobile device
|
142
|
+
|
143
|
+
To send push notifications, you can add ios and android device tokens to a customer:
|
144
|
+
|
145
|
+
```ruby
|
146
|
+
$customerio.add_device(5, "my_ios_device_id", "ios")
|
147
|
+
$customerio.add_device(5, "my_android_device_id", "android")
|
148
|
+
```
|
149
|
+
|
150
|
+
Optionally, `last_used` can be passed in to specify the last touch of the device. Otherwise, this attribute is set by the API.
|
151
|
+
|
152
|
+
```ruby
|
153
|
+
$customerio.add_device(5, "my_ios_device_id", "ios", {:last_used=>Time.now.to_i})
|
154
|
+
```
|
155
|
+
|
156
|
+
### Removing a mobile device
|
157
|
+
|
158
|
+
Deleting a device token will remove it from the associated customer to stop further push notifications from being sent for that device
|
159
|
+
|
160
|
+
```ruby
|
161
|
+
$customerio.delete_device(5, "my_device_token")
|
162
|
+
```
|
163
|
+
|
164
|
+
### Suppress a user
|
165
|
+
|
166
|
+
Deletes the customer with the provided id if it exists and suppresses all future events and identifies for for that customer.
|
167
|
+
|
168
|
+
```ruby
|
169
|
+
$customerio.suppress(5)
|
170
|
+
```
|
171
|
+
|
172
|
+
### Unsuppress a user
|
173
|
+
|
174
|
+
Start tracking events and identifies again for a previously suppressed customer. Note when a user is suppressed thier history is deleted and unsupressing them wil not recover that history.
|
175
|
+
|
176
|
+
```ruby
|
177
|
+
$customerio.unsuppress(5)
|
178
|
+
```
|
179
|
+
|
180
|
+
### Send Transactional Messages
|
181
|
+
|
182
|
+
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).
|
183
|
+
|
184
|
+
Create a new `SendEmailRequest` object containing:
|
185
|
+
|
186
|
+
* `transactional_message_id`: the ID of the transactional message you want to send, or the `body`, `from`, and `subject` of a new message.
|
187
|
+
* `to`: the email address of your recipients
|
188
|
+
* an `identifiers` object containing the `id` of your recipient. If the `id` does not exist, Customer.io creates it.
|
189
|
+
* a `message_data` object containing properties that you want reference in your message using liquid.
|
190
|
+
* You can also send attachments with your message. Use `attach` to encode attachments.
|
191
|
+
|
192
|
+
Use `send_email` referencing your request to send a transactional message. [Learn more about transactional messages and `SendEmailRequest` properties](https://customer.io/docs/transactional-api).
|
193
|
+
|
194
|
+
|
195
|
+
```ruby
|
196
|
+
require "customerio"
|
197
|
+
|
198
|
+
client = Customerio::APIClient.new("your API key")
|
199
|
+
|
200
|
+
request = Customerio::SendEmailRequest.new(
|
201
|
+
to: "person@example.com",
|
202
|
+
transactional_message_id: "3",
|
203
|
+
message_data: {
|
204
|
+
name: "Person",
|
205
|
+
items: {
|
206
|
+
name: "shoes",
|
207
|
+
price: "59.99",
|
208
|
+
},
|
209
|
+
products: [],
|
210
|
+
},
|
211
|
+
identifiers: {
|
212
|
+
id: "2",
|
213
|
+
},
|
214
|
+
)
|
215
|
+
|
216
|
+
file = File.open('<file-path>', 'r')
|
217
|
+
request.attach("filename", file.read)
|
218
|
+
|
219
|
+
begin
|
220
|
+
response = client.send_email(request)
|
221
|
+
puts response
|
222
|
+
rescue Customerio::InvalidResponse => e
|
223
|
+
puts e.code, e.message
|
224
|
+
end
|
225
|
+
```
|
146
226
|
|
147
227
|
## Contributing
|
148
228
|
|
data/customerio.gemspec
CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |gem|
|
|
7
7
|
gem.description = "A ruby client for the Customer.io event API."
|
8
8
|
gem.summary = "A ruby client for the Customer.io event API."
|
9
9
|
gem.homepage = "http://customer.io"
|
10
|
+
gem.license = "MIT"
|
10
11
|
|
11
12
|
gem.files = `git ls-files`.split($\)
|
12
13
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
@@ -16,10 +17,10 @@ Gem::Specification.new do |gem|
|
|
16
17
|
gem.version = Customerio::VERSION
|
17
18
|
|
18
19
|
gem.add_dependency('multi_json', "~> 1.0")
|
20
|
+
gem.add_dependency('addressable', '~> 2.7.0')
|
19
21
|
|
20
|
-
gem.add_development_dependency('rake')
|
21
|
-
gem.add_development_dependency('rspec')
|
22
|
-
gem.add_development_dependency('webmock')
|
23
|
-
gem.add_development_dependency('addressable', '~> 2.3.6')
|
22
|
+
gem.add_development_dependency('rake', '~> 10.5')
|
23
|
+
gem.add_development_dependency('rspec', '3.3.0')
|
24
|
+
gem.add_development_dependency('webmock', '3.6.0')
|
24
25
|
gem.add_development_dependency('json')
|
25
26
|
end
|
data/lib/customerio.rb
CHANGED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'multi_json'
|
3
|
+
|
4
|
+
module Customerio
|
5
|
+
class APIClient
|
6
|
+
DEFAULT_API_URL = 'https://api.customer.io'
|
7
|
+
|
8
|
+
def initialize(app_key, options = {})
|
9
|
+
options[:url] = DEFAULT_API_URL if options[:url].nil? || options[:url].empty?
|
10
|
+
@client = Customerio::BaseClient.new({ app_key: app_key }, options)
|
11
|
+
end
|
12
|
+
|
13
|
+
def send_email(req)
|
14
|
+
raise "request must be an instance of Customerio::SendEmailRequest" unless req.is_a?(Customerio::SendEmailRequest)
|
15
|
+
response = @client.request(:post, send_email_path, req.message)
|
16
|
+
|
17
|
+
case response
|
18
|
+
when Net::HTTPSuccess then
|
19
|
+
JSON.parse(response.body)
|
20
|
+
when Net::HTTPBadRequest then
|
21
|
+
json = JSON.parse(response.body)
|
22
|
+
raise Customerio::InvalidResponse.new(response.code, json['meta']['error'], response)
|
23
|
+
else
|
24
|
+
raise InvalidResponse.new(response.code, response.body)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def send_email_path
|
31
|
+
"/v1/send/email"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|