customerio 2.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZGQ1ZjA4MDkwN2JhMDljOTRjODBhOTdhZjllMDg0YTZmOGRlMmI0Yg==
5
- data.tar.gz: !binary |-
6
- NTk1ODZkN2MwMDY0ZjI5ZDI4MTk3ZjlmZjI3MDdhZGVlYTdjYTJiNg==
2
+ SHA256:
3
+ metadata.gz: 48f0d7c8bb61994c6bee0e1b846772f7ab304913182a1d1ac87f52a6e4e9beff
4
+ data.tar.gz: e8df14b0db35439d08687a2ff61161d5d6bfc3a9f8ae6df71ba9c1cd7d4c91e9
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YTNmYjQxYmU1YWM1ZmRiYjNjZWFhZjE5NjczZmE2MTI5NWIyMjhjNGYzYjkw
10
- YjAxMjYwOTI3ZGZiNDhmZjgwNGNmYzNlMmIwY2Y2ODg3ODQ0NjA3ZGNjODVl
11
- OTg5YzU1NWJlYzJjNDAwZWM5OWM3MWE0ZDk5NzY5NmUzMzgyNTU=
12
- data.tar.gz: !binary |-
13
- YmU2NzM4N2ZiNDI0MmU1MTA5MmQ1N2U1ZDc5OGM3OGY3NTg2ODExY2Y0YzAz
14
- YmI2Y2YyOTBkMDVkOGYzMDg0ZWZjMDZhMGI2YjgyMjNjNTBkYWNiMjc1Zjhk
15
- YjA5MWZjODg4ZGU1NGFiMWMwNzQxN2VmZTRkNzg4MGUzYTk1MGI=
6
+ metadata.gz: 7fff0a46a46e90a65f39694abf8713abe1a5e9edd0f388d26fea80d305332ed8425998397822899a9b66f27e77fb98e1051cd332842c73cd20da0a7ad7380a9d
7
+ data.tar.gz: 1eab0fb3fe94024954b04f77c34029aa2b9a9b6a089d5d6aa86f9070101e0bf13e7019725e8031fcdd7af0ddf76532e4b2b85b6dfe7e482ecb5f407b339df381
@@ -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
@@ -0,0 +1,30 @@
1
+ name: ruby_ci
2
+
3
+ on: [push]
4
+
5
+ jobs:
6
+ build:
7
+ strategy:
8
+ matrix:
9
+ ruby: ['2.5', '2.6', '2.7']
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: set up ruby
14
+ uses: actions/setup-ruby@v1
15
+ with:
16
+ ruby-version: ${{ matrix.ruby }}
17
+ - name: install bundle
18
+ run: |
19
+ sudo apt-get -yqq install libpq-dev
20
+ gem install bundler
21
+ - name: Cache dependencies
22
+ uses: actions/cache@v2
23
+ with:
24
+ path: vendor/bundle
25
+ key: customerio-${{ matrix.ruby }}-${{ hashFiles('customerio.gemspec') }}
26
+ restore-keys: |
27
+ customerio-${{ matrix.ruby }}-
28
+ - name: Install dependencies
29
+ run: bundle install --path vendor/bundle
30
+ - run: bundle exec rspec
data/CHANGELOG.markdown CHANGED
@@ -1,44 +1,95 @@
1
- ## Customerio 2.0.0 - Apr 10, 2018 ##
1
+
2
+ ## Customerio 3.1.0 - March 25, 2021
3
+ ### Added
4
+ - Support for EU region
5
+
6
+ ### Removed
7
+ ### Changed
8
+ - `Customerio::Client` and `CustomerIO::APIClient` have a new parameter `region` that can be set to either `Customerio::Regions::EU` or `Customerio::Regions::US` (defaults to `Customerio::Regions::US`)
9
+
10
+ ## Customerio 3.0.0 - Dec 2, 2020
11
+
12
+ ### Added
13
+ - Support for the Transactional API
14
+
15
+ ### Removed
16
+ - `add_to_segment` and `remove_from_segment` methods
17
+ - Support for non-JSON data
18
+
19
+ ### Changed
20
+ - IDs in the URLs are now escaped.
21
+ - Improved validations for data that's passed in.
22
+ - 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.
23
+
24
+
25
+ ## Customerio 3.0.0 - Dec 2, 2020
26
+
27
+ ### Added
28
+ - Support for the Transactional API
29
+
30
+ ### Removed
31
+ - `add_to_segment` and `remove_from_segment` methods
32
+ - Support for non-JSON data
33
+
34
+ ### Changed
35
+ - IDs in the URLs are now escaped.
36
+ - Improved validations for data that's passed in.
37
+ - 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.
38
+
39
+ ## Customerio 2.2.1 - Mar 23, 2020
40
+
41
+ - Add license to gemspec [#55](https://github.com/customerio/customerio-ruby/pull/55)
42
+ - Bubble up error message [#51](https://github.com/customerio/customerio-ruby/pull/51)
43
+
44
+ ## Customerio 2.2.0 - Oct 18, 2018
45
+
46
+ Add support for manual segments [#52](https://github.com/customerio/customerio-ruby/pull/52)
47
+
48
+ ## Customerio 2.1.0 - May 22, 2018
49
+
50
+ Added support for the suppress / unsuppress methods [#49](https://github.com/customerio/customerio-ruby/pull/49)
51
+
52
+ ## Customerio 2.0.0 - Apr 10, 2018
2
53
 
3
54
  With this release we have dropped the support for ruby 1.8.7.
4
55
 
5
- * Support new add and remove device endpoints for push notifications [#47](https://github.com/customerio/customerio-ruby/pull/47)
56
+ - Support new add and remove device endpoints for push notifications [#47](https://github.com/customerio/customerio-ruby/pull/47)
6
57
 
7
- ## Customerio 1.0.0 - Mar 15, 2016 ##
58
+ ## Customerio 1.0.0 - Mar 15, 2016
8
59
 
9
60
  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`.
10
61
 
11
- * Remove HTTParty dependency, use Net::HTTP instead. [#42](https://github.com/customerio/customerio-ruby/pull/42)
62
+ - Remove HTTParty dependency, use Net::HTTP instead. [#42](https://github.com/customerio/customerio-ruby/pull/42)
12
63
 
13
- * 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)
64
+ - 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)
14
65
 
15
- ## Customerio 0.7.0 - Mar 2, 2016 ##
66
+ ## Customerio 0.7.0 - Mar 2, 2016
16
67
 
17
- * 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)
68
+ - 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)
18
69
 
19
- * Use JSON encoding by default. [#37](https://github.com/customerio/customerio-ruby/pull/37)
70
+ - Use JSON encoding by default. [#37](https://github.com/customerio/customerio-ruby/pull/37)
20
71
 
21
- If you want to stick with form-encoding for your integration, you must add `:json => false` to your Customerio::Client initializer. Like this:
72
+ If you want to stick with form-encoding for your integration, you must add `:json => false` to your Customerio::Client initializer. Like this:
22
73
 
23
- ```ruby
24
- customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY", :json => false)
25
- ```
74
+ ```ruby
75
+ customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY", :json => false)
76
+ ```
26
77
 
27
- ## Customerio 0.6.1 - Oct 8, 2015 ##
78
+ ## Customerio 0.6.1 - Oct 8, 2015
28
79
 
29
- * Include HTTP response as an attribute on the InvalidResponse exception to help with debugging failed API requests. For example:
80
+ - Include HTTP response as an attribute on the InvalidResponse exception to help with debugging failed API requests. For example:
30
81
 
31
- ```ruby
32
- begin
33
- $customerio.track(1, 'event', { :test => 'testing' })
34
- rescue => e
35
- puts e.message
36
- puts e.response.status
37
- puts e.response.body
38
- end
39
- ```
82
+ ```ruby
83
+ begin
84
+ $customerio.track(1, 'event', { :test => 'testing' })
85
+ rescue => e
86
+ puts e.message
87
+ puts e.response.status
88
+ puts e.response.body
89
+ end
90
+ ```
40
91
 
41
- ## Customerio 0.6.0 - Oct 6, 2015 ##
92
+ ## Customerio 0.6.0 - Oct 6, 2015
42
93
 
43
94
  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.
44
95
 
@@ -50,46 +101,46 @@ customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY", :json
50
101
 
51
102
  Other fixes and improvements, with many thanks to the community contributors:
52
103
 
53
- * Added HTTP timeout of 10 seconds (@stayhero)
54
- * Added JSON support for events (@kemper)
55
- * Convert attribute keys to symbols (@joshnabbott)
104
+ - Added HTTP timeout of 10 seconds (@stayhero)
105
+ - Added JSON support for events (@kemper)
106
+ - Convert attribute keys to symbols (@joshnabbott)
56
107
 
57
- ## Customerio 0.5.0 - Mar 28, 2014 ##
108
+ ## Customerio 0.5.0 - Mar 28, 2014
58
109
 
59
- * Added flag to send body encoded as JSON, rather than the default form encoding.
110
+ - Added flag to send body encoded as JSON, rather than the default form encoding.
60
111
 
61
- ## Customerio 0.5.0 - Apr 8, 2013 ##
112
+ ## Customerio 0.5.0 - Apr 8, 2013
62
113
 
63
- * Removed deprecated methods around using a customer object. All calls simply take a hash of attributes now.
64
- * Added ability to set a timestamp on a tracked event. Useful for backfilling past events.
114
+ - Removed deprecated methods around using a customer object. All calls simply take a hash of attributes now.
115
+ - Added ability to set a timestamp on a tracked event. Useful for backfilling past events.
65
116
 
66
- ## Customerio 0.4.1 - Feb 18, 2013 ##
117
+ ## Customerio 0.4.1 - Feb 18, 2013
67
118
 
68
- * Bug fixes related to the 4.0 change.
119
+ - Bug fixes related to the 4.0 change.
69
120
 
70
- ## Customerio 0.4.0 - Feb 18, 2013 ##
121
+ ## Customerio 0.4.0 - Feb 18, 2013
71
122
 
72
- * Added support for deleting customers.
123
+ - Added support for deleting customers.
73
124
 
74
- ## Customerio 0.3.0 - Dec 28, 2012 ##
125
+ ## Customerio 0.3.0 - Dec 28, 2012
75
126
 
76
- * Now raise an error if an API call doesn't respond with a 200 response code
77
- * Removed dependency on ActiveSupport
127
+ - Now raise an error if an API call doesn't respond with a 200 response code
128
+ - Removed dependency on ActiveSupport
78
129
 
79
- ## Customerio 0.2.0 - Nov 21, 2012 ##
130
+ ## Customerio 0.2.0 - Nov 21, 2012
80
131
 
81
- * Allow raw hashes to be passed into `identify` and `track` methods rather than a customer object.
82
- * Passing a customer object has been depreciated.
83
- * Customizing ids with `Customerio::Client.id` block is deprecated.
132
+ - Allow raw hashes to be passed into `identify` and `track` methods rather than a customer object.
133
+ - Passing a customer object has been depreciated.
134
+ - Customizing ids with `Customerio::Client.id` block is deprecated.
84
135
 
85
- ## Customerio 0.1.0 - Nov 15, 2012 ##
136
+ ## Customerio 0.1.0 - Nov 15, 2012
86
137
 
87
- * Allow tracking of anonymous events.
138
+ - Allow tracking of anonymous events.
88
139
 
89
- ## Customerio 0.0.3 - Nov 5, 2012 ##
140
+ ## Customerio 0.0.3 - Nov 5, 2012
90
141
 
91
- * Bump httparty dependency to the latest version.
142
+ - Bump httparty dependency to the latest version.
92
143
 
93
- ## Customerio 0.0.2 - May 22, 2012 ##
144
+ ## Customerio 0.0.2 - May 22, 2012
94
145
 
95
- * First release.
146
+ - First release.
data/README.md CHANGED
@@ -42,20 +42,15 @@ You'll be able to integrate **fully** with [Customer.io](http://customer.io) wit
42
42
 
43
43
  ### Setup
44
44
 
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://fly.customer.io/account/customerio_integration).
45
+ Create an instance of the client with your [Customer.io credentials](https://fly.customer.io/settings/api_credentials).
47
46
 
48
47
  If you're using Rails, create an initializer `config/initializers/customerio.rb`:
49
48
 
50
49
  ```ruby
51
- $customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY")
50
+ $customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY", region: Customerio::Regions::US)
52
51
  ```
53
52
 
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
- ```
53
+ `region` is optional and takes one of two values—`US` or `EU`. If you do not specify your region, we assume that your account is based in the US (`US`). If your account is based in the EU and you do not provide the correct region (`EU`), we'll route requests to our EU data centers accordingly, however this may cause data to be logged in the US.
59
54
 
60
55
  ### Identify logged in customers
61
56
 
@@ -127,7 +122,7 @@ encourage your customers to perform an action.
127
122
  $customerio.track(5, "purchase", :type => "socks", :price => "13.99")
128
123
  ```
129
124
 
130
- **Note:** If you'd like to track events which occurred in the past, you can include a `timestamp` attribute
125
+ **Note:** If you want to track events which occurred in the past, you can include a `timestamp` attribute
131
126
  (in seconds since the epoch), and we'll use that as the date the event occurred.
132
127
 
133
128
  ```ruby
@@ -167,6 +162,69 @@ Deleting a device token will remove it from the associated customer to stop furt
167
162
  $customerio.delete_device(5, "my_device_token")
168
163
  ```
169
164
 
165
+ ### Suppress a user
166
+
167
+ Deletes the customer with the provided id if it exists and suppresses all future events and identifies for for that customer.
168
+
169
+ ```ruby
170
+ $customerio.suppress(5)
171
+ ```
172
+
173
+ ### Unsuppress a user
174
+
175
+ 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.
176
+
177
+ ```ruby
178
+ $customerio.unsuppress(5)
179
+ ```
180
+
181
+ ### Send Transactional Messages
182
+
183
+ 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).
184
+
185
+ Create a new `SendEmailRequest` object containing:
186
+
187
+ * `transactional_message_id`: the ID of the transactional message you want to send, or the `body`, `from`, and `subject` of a new message.
188
+ * `to`: the email address of your recipients
189
+ * an `identifiers` object containing the `id` of your recipient. If the `id` does not exist, Customer.io creates it.
190
+ * a `message_data` object containing properties that you want reference in your message using liquid.
191
+ * You can also send attachments with your message. Use `attach` to encode attachments.
192
+
193
+ 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).
194
+
195
+
196
+ ```ruby
197
+ require "customerio"
198
+
199
+ client = Customerio::APIClient.new("your API key", region: Customerio::Regions::US)
200
+
201
+ request = Customerio::SendEmailRequest.new(
202
+ to: "person@example.com",
203
+ transactional_message_id: "3",
204
+ message_data: {
205
+ name: "Person",
206
+ items: {
207
+ name: "shoes",
208
+ price: "59.99",
209
+ },
210
+ products: [],
211
+ },
212
+ identifiers: {
213
+ id: "2",
214
+ },
215
+ )
216
+
217
+ file = File.open('<file-path>', 'r')
218
+ request.attach("filename", file.read)
219
+
220
+ begin
221
+ response = client.send_email(request)
222
+ puts response
223
+ rescue Customerio::InvalidResponse => e
224
+ puts e.code, e.message
225
+ end
226
+ ```
227
+
170
228
  ## Contributing
171
229
 
172
230
  1. Fork it
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
22
  gem.add_development_dependency('rake', '~> 10.5')
21
23
  gem.add_development_dependency('rspec', '3.3.0')
22
- gem.add_development_dependency('webmock', '1.24.2')
23
- gem.add_development_dependency('addressable', '~> 2.3.6')
24
+ gem.add_development_dependency('webmock', '3.6.0')
24
25
  gem.add_development_dependency('json')
25
26
  end
data/lib/customerio.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require "customerio/version"
2
2
 
3
3
  module Customerio
4
+ require "customerio/regions"
5
+ require "customerio/base_client"
4
6
  require "customerio/client"
7
+ require "customerio/requests/send_email_request"
8
+ require "customerio/api"
5
9
  require "customerio/param_encoder"
6
10
  end
@@ -0,0 +1,35 @@
1
+ require 'net/http'
2
+ require 'multi_json'
3
+
4
+ module Customerio
5
+ class APIClient
6
+ def initialize(app_key, options = {})
7
+ options[:region] = Customerio::Regions::US if options[:region].nil?
8
+ raise "region must be an instance of Customerio::Regions::Region" unless options[:region].is_a?(Customerio::Regions::Region)
9
+
10
+ options[:url] = options[:region].api_url if options[:url].nil? || options[:url].empty?
11
+ @client = Customerio::BaseClient.new({ app_key: app_key }, options)
12
+ end
13
+
14
+ def send_email(req)
15
+ raise "request must be an instance of Customerio::SendEmailRequest" unless req.is_a?(Customerio::SendEmailRequest)
16
+ response = @client.request(:post, send_email_path, req.message)
17
+
18
+ case response
19
+ when Net::HTTPSuccess then
20
+ JSON.parse(response.body)
21
+ when Net::HTTPBadRequest then
22
+ json = JSON.parse(response.body)
23
+ raise Customerio::InvalidResponse.new(response.code, json['meta']['error'], response)
24
+ else
25
+ raise InvalidResponse.new(response.code, response.body)
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ def send_email_path
32
+ "/v1/send/email"
33
+ end
34
+ end
35
+ end