customerio 1.0.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +11 -9
- data/.travis.yml +0 -5
- data/CHANGELOG.markdown +66 -47
- data/README.md +59 -4
- data/customerio.gemspec +4 -3
- data/lib/customerio/client.rb +82 -1
- data/lib/customerio/version.rb +1 -1
- data/spec/client_spec.rb +127 -0
- metadata +17 -16
checksums.yaml
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
---
|
2
|
-
!binary "
|
2
|
+
!binary "U0hBMjU2":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGJmMGRlMjNmNzZmNzFiZDI5NjM4YzRhNTczOWY1MzUzY2Y1MzVhMmMwZDg3
|
5
|
+
YTcyNTM4NDY5MjM4OTBiOTNlOA==
|
5
6
|
data.tar.gz: !binary |-
|
6
|
-
|
7
|
+
NDE5YWFjYmM4NjQxYWU2YThhZDNhYzM0ZDdmOTU2OWExNWZmODM4YjEwY2Ri
|
8
|
+
ZTZlOWIzNzU5ZDUyZmY4ZDg5Yg==
|
7
9
|
SHA512:
|
8
10
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
11
|
+
MDkxMTRkNGZjYWQyYjIzZjEwODM2YzQxN2Y4YzVmZmZiOWE5YmU3NjUwYzdi
|
12
|
+
Zjg5NzE2ZDg1YWI0YTg2MDY5NTkzM2QwOWNlNTAwN2U3MThmODMwODU5YTVi
|
13
|
+
YzA1ZmM2OTFmYzVkNWIxMjhhMGViNjhhODQ1ZWJkODIxODlhODg=
|
12
14
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
YjNiNTRlZTNkMjg2NGEwNjNiZmEyMTQyZWZhNTMyYjgxZDI1MDkxOGM4MDI1
|
16
|
+
NjRlY2U4OTBmMTM0ZTM1ZDU5M2FkNjJjNjE2ZjhmZTRiMzE0ZmE1MWJkMTQx
|
17
|
+
NDE1MDNhMWYzYmFmZTBlMTJlZDU5OGQzOGQwYjM5ZWNkMGZhOTU=
|
data/.travis.yml
CHANGED
data/CHANGELOG.markdown
CHANGED
@@ -1,38 +1,57 @@
|
|
1
|
-
## Customerio
|
1
|
+
## Customerio 2.2.1 - Mar 23, 2020
|
2
|
+
|
3
|
+
- Add license to gemspec [#55](https://github.com/customerio/customerio-ruby/pull/55)
|
4
|
+
- Bubble up error message [#51](https://github.com/customerio/customerio-ruby/pull/51)
|
5
|
+
|
6
|
+
## Customerio 2.2.0 - Oct 18, 2018
|
7
|
+
|
8
|
+
Add support for manual segments [#52](https://github.com/customerio/customerio-ruby/pull/52)
|
9
|
+
|
10
|
+
## Customerio 2.1.0 - May 22, 2018
|
11
|
+
|
12
|
+
Added support for the suppress / unsuppress methods [#49](https://github.com/customerio/customerio-ruby/pull/49)
|
13
|
+
|
14
|
+
## Customerio 2.0.0 - Apr 10, 2018
|
15
|
+
|
16
|
+
With this release we have dropped the support for ruby 1.8.7.
|
17
|
+
|
18
|
+
- Support new add and remove device endpoints for push notifications [#47](https://github.com/customerio/customerio-ruby/pull/47)
|
19
|
+
|
20
|
+
## Customerio 1.0.0 - Mar 15, 2016
|
2
21
|
|
3
22
|
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
23
|
|
5
|
-
|
24
|
+
- Remove HTTParty dependency, use Net::HTTP instead. [#42](https://github.com/customerio/customerio-ruby/pull/42)
|
6
25
|
|
7
|
-
|
26
|
+
- 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
27
|
|
9
|
-
## Customerio 0.7.0 - Mar 2, 2016
|
28
|
+
## Customerio 0.7.0 - Mar 2, 2016
|
10
29
|
|
11
|
-
|
30
|
+
- 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
31
|
|
13
|
-
|
32
|
+
- Use JSON encoding by default. [#37](https://github.com/customerio/customerio-ruby/pull/37)
|
14
33
|
|
15
|
-
|
34
|
+
If you want to stick with form-encoding for your integration, you must add `:json => false` to your Customerio::Client initializer. Like this:
|
16
35
|
|
17
|
-
|
18
|
-
|
19
|
-
|
36
|
+
```ruby
|
37
|
+
customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY", :json => false)
|
38
|
+
```
|
20
39
|
|
21
|
-
## Customerio 0.6.1 - Oct 8, 2015
|
40
|
+
## Customerio 0.6.1 - Oct 8, 2015
|
22
41
|
|
23
|
-
|
42
|
+
- Include HTTP response as an attribute on the InvalidResponse exception to help with debugging failed API requests. For example:
|
24
43
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
44
|
+
```ruby
|
45
|
+
begin
|
46
|
+
$customerio.track(1, 'event', { :test => 'testing' })
|
47
|
+
rescue => e
|
48
|
+
puts e.message
|
49
|
+
puts e.response.status
|
50
|
+
puts e.response.body
|
51
|
+
end
|
52
|
+
```
|
34
53
|
|
35
|
-
## Customerio 0.6.0 - Oct 6, 2015
|
54
|
+
## Customerio 0.6.0 - Oct 6, 2015
|
36
55
|
|
37
56
|
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
57
|
|
@@ -44,46 +63,46 @@ customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY", :json
|
|
44
63
|
|
45
64
|
Other fixes and improvements, with many thanks to the community contributors:
|
46
65
|
|
47
|
-
|
48
|
-
|
49
|
-
|
66
|
+
- Added HTTP timeout of 10 seconds (@stayhero)
|
67
|
+
- Added JSON support for events (@kemper)
|
68
|
+
- Convert attribute keys to symbols (@joshnabbott)
|
50
69
|
|
51
|
-
## Customerio 0.5.0 - Mar 28, 2014
|
70
|
+
## Customerio 0.5.0 - Mar 28, 2014
|
52
71
|
|
53
|
-
|
72
|
+
- Added flag to send body encoded as JSON, rather than the default form encoding.
|
54
73
|
|
55
|
-
## Customerio 0.5.0 - Apr 8, 2013
|
74
|
+
## Customerio 0.5.0 - Apr 8, 2013
|
56
75
|
|
57
|
-
|
58
|
-
|
76
|
+
- Removed deprecated methods around using a customer object. All calls simply take a hash of attributes now.
|
77
|
+
- Added ability to set a timestamp on a tracked event. Useful for backfilling past events.
|
59
78
|
|
60
|
-
## Customerio 0.4.1 - Feb 18, 2013
|
79
|
+
## Customerio 0.4.1 - Feb 18, 2013
|
61
80
|
|
62
|
-
|
81
|
+
- Bug fixes related to the 4.0 change.
|
63
82
|
|
64
|
-
## Customerio 0.4.0 - Feb 18, 2013
|
83
|
+
## Customerio 0.4.0 - Feb 18, 2013
|
65
84
|
|
66
|
-
|
85
|
+
- Added support for deleting customers.
|
67
86
|
|
68
|
-
## Customerio 0.3.0 - Dec 28, 2012
|
87
|
+
## Customerio 0.3.0 - Dec 28, 2012
|
69
88
|
|
70
|
-
|
71
|
-
|
89
|
+
- Now raise an error if an API call doesn't respond with a 200 response code
|
90
|
+
- Removed dependency on ActiveSupport
|
72
91
|
|
73
|
-
## Customerio 0.2.0 - Nov 21, 2012
|
92
|
+
## Customerio 0.2.0 - Nov 21, 2012
|
74
93
|
|
75
|
-
|
76
|
-
|
77
|
-
|
94
|
+
- Allow raw hashes to be passed into `identify` and `track` methods rather than a customer object.
|
95
|
+
- Passing a customer object has been depreciated.
|
96
|
+
- Customizing ids with `Customerio::Client.id` block is deprecated.
|
78
97
|
|
79
|
-
## Customerio 0.1.0 - Nov 15, 2012
|
98
|
+
## Customerio 0.1.0 - Nov 15, 2012
|
80
99
|
|
81
|
-
|
100
|
+
- Allow tracking of anonymous events.
|
82
101
|
|
83
|
-
## Customerio 0.0.3 - Nov 5, 2012
|
102
|
+
## Customerio 0.0.3 - Nov 5, 2012
|
84
103
|
|
85
|
-
|
104
|
+
- Bump httparty dependency to the latest version.
|
86
105
|
|
87
|
-
## Customerio 0.0.2 - May 22, 2012
|
106
|
+
## Customerio 0.0.2 - May 22, 2012
|
88
107
|
|
89
|
-
|
108
|
+
- 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
|
|
@@ -142,7 +142,62 @@ You can also send anonymous events, for situations where you don't yet have a cu
|
|
142
142
|
$customerio.anonymous_track("help_enquiry", :recipient => 'user@example.com')
|
143
143
|
```
|
144
144
|
|
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/
|
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://learn.customer.io/recipes/invite-emails.html).
|
146
|
+
|
147
|
+
### Adding a mobile device
|
148
|
+
|
149
|
+
To send push notifications, you can add ios and android device tokens to a customer:
|
150
|
+
|
151
|
+
```ruby
|
152
|
+
$customerio.add_device(5, "my_ios_device_id", "ios")
|
153
|
+
$customerio.add_device(5, "my_android_device_id", "android")
|
154
|
+
```
|
155
|
+
|
156
|
+
Optionally, `last_used` can be passed in to specify the last touch of the device. Otherwise, this attribute is set by the API.
|
157
|
+
|
158
|
+
```ruby
|
159
|
+
$customerio.add_device(5, "my_ios_device_id", "ios", {:last_used=>Time.now.to_i})
|
160
|
+
```
|
161
|
+
|
162
|
+
### Removing a mobile device
|
163
|
+
|
164
|
+
Deleting a device token will remove it from the associated customer to stop further push notifications from being sent for that device
|
165
|
+
|
166
|
+
```ruby
|
167
|
+
$customerio.delete_device(5, "my_device_token")
|
168
|
+
```
|
169
|
+
|
170
|
+
### Suppress a user
|
171
|
+
|
172
|
+
Deletes the customer with the provided id if it exists and suppresses all future events and identifies for for that customer.
|
173
|
+
|
174
|
+
```ruby
|
175
|
+
$customerio.suppress(5)
|
176
|
+
```
|
177
|
+
|
178
|
+
### Unsuppress a user
|
179
|
+
|
180
|
+
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.
|
181
|
+
|
182
|
+
```ruby
|
183
|
+
$customerio.unsuppress(5)
|
184
|
+
```
|
185
|
+
|
186
|
+
### Add customers to a manual segment
|
187
|
+
|
188
|
+
Add the list of customer ids to the specified manual segment. If you send customer ids that don't exist yet in an add_to_segment request, we will automatically create customer profiles for the new customer ids.
|
189
|
+
|
190
|
+
```ruby
|
191
|
+
$customerio.add_to_segment(segment_id=1,customer_ids=['1','2','3'])
|
192
|
+
```
|
193
|
+
|
194
|
+
### Remove customers from a manual segment
|
195
|
+
|
196
|
+
Remove the list of customer ids from the specified manual segment.
|
197
|
+
|
198
|
+
```ruby
|
199
|
+
$customerio.remove_from_segment(segment_id=1,customer_ids=['1','2','3'])
|
200
|
+
```
|
146
201
|
|
147
202
|
## Contributing
|
148
203
|
|
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) }
|
@@ -17,9 +18,9 @@ Gem::Specification.new do |gem|
|
|
17
18
|
|
18
19
|
gem.add_dependency('multi_json', "~> 1.0")
|
19
20
|
|
20
|
-
gem.add_development_dependency('rake')
|
21
|
-
gem.add_development_dependency('rspec')
|
22
|
-
gem.add_development_dependency('webmock')
|
21
|
+
gem.add_development_dependency('rake', '~> 10.5')
|
22
|
+
gem.add_development_dependency('rspec', '3.3.0')
|
23
|
+
gem.add_development_dependency('webmock', '1.24.2')
|
23
24
|
gem.add_development_dependency('addressable', '~> 2.3.6')
|
24
25
|
gem.add_development_dependency('json')
|
25
26
|
end
|
data/lib/customerio/client.rb
CHANGED
@@ -7,12 +7,13 @@ module Customerio
|
|
7
7
|
|
8
8
|
class Client
|
9
9
|
class MissingIdAttributeError < RuntimeError; end
|
10
|
+
class ParamError < RuntimeError; end
|
10
11
|
class InvalidRequest < RuntimeError; end
|
11
12
|
class InvalidResponse < RuntimeError
|
12
13
|
attr_reader :response
|
13
14
|
|
14
15
|
def initialize(message, response)
|
15
|
-
|
16
|
+
super(message)
|
16
17
|
@response = response
|
17
18
|
end
|
18
19
|
end
|
@@ -33,6 +34,14 @@ module Customerio
|
|
33
34
|
verify_response(request(:delete, customer_path(customer_id)))
|
34
35
|
end
|
35
36
|
|
37
|
+
def suppress(customer_id)
|
38
|
+
verify_response(request(:post, suppress_path(customer_id)))
|
39
|
+
end
|
40
|
+
|
41
|
+
def unsuppress(customer_id)
|
42
|
+
verify_response(request(:post, unsuppress_path(customer_id)))
|
43
|
+
end
|
44
|
+
|
36
45
|
def track(*args)
|
37
46
|
attributes = extract_attributes(args)
|
38
47
|
|
@@ -53,8 +62,72 @@ module Customerio
|
|
53
62
|
create_anonymous_event(event_name, attributes)
|
54
63
|
end
|
55
64
|
|
65
|
+
def add_device(customer_id, device_id, platform, data={})
|
66
|
+
raise ParamError.new("customer_id must be a non-empty string") unless customer_id != "" and !customer_id.nil?
|
67
|
+
raise ParamError.new("device_id must be a non-empty string") unless device_id != "" and !device_id.nil?
|
68
|
+
raise ParamError.new("platform must be a non-empty string") unless platform != "" and !platform.nil?
|
69
|
+
|
70
|
+
if data.nil?
|
71
|
+
data = {}
|
72
|
+
end
|
73
|
+
|
74
|
+
raise ParamError.new("data parameter must be a hash") unless data.is_a?(Hash)
|
75
|
+
|
76
|
+
verify_response(request(:put, device_path(customer_id), {
|
77
|
+
:device => data.update({
|
78
|
+
:id => device_id,
|
79
|
+
:platform => platform,
|
80
|
+
})
|
81
|
+
}))
|
82
|
+
end
|
83
|
+
|
84
|
+
def delete_device(customer_id, device_id)
|
85
|
+
raise ParamError.new("customer_id must be a non-empty string") unless customer_id != "" and !customer_id.nil?
|
86
|
+
raise ParamError.new("device_id must be a non-empty string") unless device_id != "" and !device_id.nil?
|
87
|
+
|
88
|
+
verify_response(request(:delete, device_id_path(customer_id, device_id)))
|
89
|
+
end
|
90
|
+
|
91
|
+
def add_to_segment(segment_id, customer_ids)
|
92
|
+
raise ParamError.new("segment_id must be an integer") unless segment_id.is_a? Integer
|
93
|
+
raise ParamError.new("customer_ids must be a list of values") unless customer_ids.is_a? Array
|
94
|
+
|
95
|
+
customer_ids = customer_ids.map{ |id| id.to_s }
|
96
|
+
|
97
|
+
verify_response(request(:post, add_to_segment_path(segment_id), {
|
98
|
+
:ids => customer_ids,
|
99
|
+
}))
|
100
|
+
end
|
101
|
+
|
102
|
+
def remove_from_segment(segment_id, customer_ids)
|
103
|
+
raise ParamError.new("segment_id must be an integer") unless segment_id.is_a? Integer
|
104
|
+
raise ParamError.new("customer_ids must be a list of values") unless customer_ids.is_a? Array
|
105
|
+
|
106
|
+
customer_ids = customer_ids.map{ |id| id.to_s }
|
107
|
+
|
108
|
+
verify_response(request(:post, remove_from_segment_path(segment_id), {
|
109
|
+
:ids => customer_ids,
|
110
|
+
}))
|
111
|
+
end
|
112
|
+
|
56
113
|
private
|
57
114
|
|
115
|
+
def add_to_segment_path(segment_id)
|
116
|
+
"/api/v1/segments/#{segment_id}/add_customers"
|
117
|
+
end
|
118
|
+
|
119
|
+
def remove_from_segment_path(segment_id)
|
120
|
+
"/api/v1/segments/#{segment_id}/remove_customers"
|
121
|
+
end
|
122
|
+
|
123
|
+
def device_path(customer_id)
|
124
|
+
"/api/v1/customers/#{customer_id}/devices"
|
125
|
+
end
|
126
|
+
|
127
|
+
def device_id_path(customer_id, device_id)
|
128
|
+
"/api/v1/customers/#{customer_id}/devices/#{device_id}"
|
129
|
+
end
|
130
|
+
|
58
131
|
def create_or_update(attributes = {})
|
59
132
|
attributes = Hash[attributes.map { |(k,v)| [ k.to_sym, v ] }]
|
60
133
|
|
@@ -83,6 +156,14 @@ module Customerio
|
|
83
156
|
"/api/v1/customers/#{id}"
|
84
157
|
end
|
85
158
|
|
159
|
+
def suppress_path(customer_id)
|
160
|
+
"/api/v1/customers/#{customer_id}/suppress"
|
161
|
+
end
|
162
|
+
|
163
|
+
def unsuppress_path(customer_id)
|
164
|
+
"/api/v1/customers/#{customer_id}/unsuppress"
|
165
|
+
end
|
166
|
+
|
86
167
|
def valid_timestamp?(timestamp)
|
87
168
|
timestamp && timestamp.is_a?(Integer) && timestamp > 999999999 && timestamp < 100000000000
|
88
169
|
end
|
data/lib/customerio/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -125,6 +125,24 @@ describe Customerio::Client do
|
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
128
|
+
describe "#suppress" do
|
129
|
+
it "sends a POST request to the customer.io's suppress API" do
|
130
|
+
stub_request(:post, api_uri('/api/v1/customers/5/suppress')).
|
131
|
+
to_return(:status => 200, :body => "", :headers => {})
|
132
|
+
|
133
|
+
client.suppress(5)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "#unsuppress" do
|
138
|
+
it "sends a POST request to the customer.io's unsuppress API" do
|
139
|
+
stub_request(:post, api_uri('/api/v1/customers/5/unsuppress')).
|
140
|
+
to_return(:status => 200, :body => "", :headers => {})
|
141
|
+
|
142
|
+
client.unsuppress(5)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
128
146
|
describe "#track" do
|
129
147
|
it "raises an error if POST doesn't return a 2xx response code" do
|
130
148
|
stub_request(:post, api_uri('/api/v1/customers/5/events')).
|
@@ -355,4 +373,113 @@ describe Customerio::Client do
|
|
355
373
|
end
|
356
374
|
end
|
357
375
|
end
|
376
|
+
|
377
|
+
describe "#devices" do
|
378
|
+
it "allows for the creation of a new device" do
|
379
|
+
stub_request(:put, api_uri('/api/v1/customers/5/devices')).
|
380
|
+
to_return(:status => 200, :body => "", :headers => {})
|
381
|
+
|
382
|
+
client.add_device(5, "androidDeviceID", "ios", {:last_used=>1561235678})
|
383
|
+
client.add_device(5, "iosDeviceID", "android")
|
384
|
+
end
|
385
|
+
it "requires a valid customer_id when creating" do
|
386
|
+
stub_request(:put, api_uri('/api/v1/customers/5/devices')).
|
387
|
+
to_return(:status => 200, :body => "", :headers => {})
|
388
|
+
|
389
|
+
lambda { client.add_device("", "ios", "myDeviceID") }.should raise_error(Customerio::Client::ParamError)
|
390
|
+
lambda { client.add_device(nil, "ios", "myDeviceID", {:last_used=>1561235678}) }.should raise_error(Customerio::Client::ParamError)
|
391
|
+
end
|
392
|
+
it "requires a valid token when creating" do
|
393
|
+
stub_request(:put, api_uri('/api/v1/customers/5/devices')).
|
394
|
+
to_return(:status => 200, :body => "", :headers => {})
|
395
|
+
|
396
|
+
lambda { client.add_device(5, "", "ios") }.should raise_error(Customerio::Client::ParamError)
|
397
|
+
lambda { client.add_device(5, nil, "ios", {:last_used=>1561235678}) }.should raise_error(Customerio::Client::ParamError)
|
398
|
+
end
|
399
|
+
it "requires a valid platform when creating" do
|
400
|
+
stub_request(:put, api_uri('/api/v1/customers/5/devices')).
|
401
|
+
to_return(:status => 200, :body => "", :headers => {})
|
402
|
+
|
403
|
+
lambda { client.add_device(5, "token", "") }.should raise_error(Customerio::Client::ParamError)
|
404
|
+
lambda { client.add_device(5, "toke", nil, {:last_used=>1561235678}) }.should raise_error(Customerio::Client::ParamError)
|
405
|
+
end
|
406
|
+
it "accepts a nil data param" do
|
407
|
+
stub_request(:put, api_uri('/api/v1/customers/5/devices')).
|
408
|
+
to_return(:status => 200, :body => "", :headers => {})
|
409
|
+
|
410
|
+
client.add_device(5, "ios", "myDeviceID", nil)
|
411
|
+
end
|
412
|
+
it "fails on invalid data param" do
|
413
|
+
stub_request(:put, api_uri('/api/v1/customers/5/devices')).
|
414
|
+
to_return(:status => 200, :body => "", :headers => {})
|
415
|
+
|
416
|
+
lambda { client.add_device(5, "ios", "myDeviceID", 1000) }.should raise_error(Customerio::Client::ParamError)
|
417
|
+
end
|
418
|
+
it "supports deletion of devices by token" do
|
419
|
+
stub_request(:delete, api_uri('/api/v1/customers/5/devices/myDeviceID')).
|
420
|
+
to_return(:status => 200, :body => "", :headers => {})
|
421
|
+
|
422
|
+
client.delete_device(5, "myDeviceID")
|
423
|
+
end
|
424
|
+
it "requires a valid customer_id when deleting" do
|
425
|
+
stub_request(:delete, api_uri('/api/v1/customers/5/devices/myDeviceID')).
|
426
|
+
to_return(:status => 200, :body => "", :headers => {})
|
427
|
+
|
428
|
+
lambda { client.delete_device("", "myDeviceID") }.should raise_error(Customerio::Client::ParamError)
|
429
|
+
lambda { client.delete_device(nil, "myDeviceID") }.should raise_error(Customerio::Client::ParamError)
|
430
|
+
end
|
431
|
+
it "requires a valid device_id when deleting" do
|
432
|
+
stub_request(:delete, api_uri('/api/v1/customers/5/devices/myDeviceID')).
|
433
|
+
to_return(:status => 200, :body => "", :headers => {})
|
434
|
+
|
435
|
+
lambda { client.delete_device(5, "") }.should raise_error(Customerio::Client::ParamError)
|
436
|
+
lambda { client.delete_device(5, nil) }.should raise_error(Customerio::Client::ParamError)
|
437
|
+
end
|
438
|
+
end
|
439
|
+
|
440
|
+
describe "#manual_segments" do
|
441
|
+
|
442
|
+
client = Customerio::Client.new("SITE_ID", "API_KEY", :json=>true)
|
443
|
+
|
444
|
+
it "allows adding customers to a manual segment" do
|
445
|
+
stub_request(:post, api_uri('/api/v1/segments/1/add_customers')).to_return(:status => 200, :body => "", :headers => {})
|
446
|
+
|
447
|
+
client.add_to_segment(1, ["customer1", "customer2", "customer3"])
|
448
|
+
end
|
449
|
+
it "requires a valid segment id when adding customers" do
|
450
|
+
stub_request(:post, api_uri('/api/v1/segments/1/add_customers')).to_return(:status => 200, :body => "", :headers => {})
|
451
|
+
|
452
|
+
lambda { client.add_to_segment("not_valid", ["customer1", "customer2", "customer3"]).should raise_error(Customerio::Client::ParamError) }
|
453
|
+
end
|
454
|
+
it "requires a valid customer list when adding customers" do
|
455
|
+
stub_request(:post, api_uri('/api/v1/segments/1/add_customers')).to_return(:status => 200, :body => "", :headers => {})
|
456
|
+
|
457
|
+
lambda { client.add_to_segment(1, "not_valid").should raise_error(Customerio::Client::ParamError) }
|
458
|
+
end
|
459
|
+
it "coerces non-string values to strings when adding customers" do
|
460
|
+
stub_request(:post, api_uri('/api/v1/segments/1/add_customers')).with(:body=>json({:ids=>["1", "2", "3"]})).to_return(:status => 200, :body => "", :headers => {})
|
461
|
+
|
462
|
+
client.add_to_segment(1, [1, 2, 3])
|
463
|
+
end
|
464
|
+
it "allows removing customers from a manual segment" do
|
465
|
+
stub_request(:post, api_uri('/api/v1/segments/1/remove_customers')).to_return(:status => 200, :body => "", :headers => {})
|
466
|
+
|
467
|
+
client.remove_from_segment(1, ["customer1", "customer2", "customer3"])
|
468
|
+
end
|
469
|
+
it "requires a valid segment id when removing customers" do
|
470
|
+
stub_request(:post, api_uri('/api/v1/segments/1/remove_customers')).to_return(:status => 200, :body => "", :headers => {})
|
471
|
+
|
472
|
+
lambda { client.remove_from_segment("not_valid", ["customer1", "customer2", "customer3"]).should raise_error(Customerio::Client::ParamError) }
|
473
|
+
end
|
474
|
+
it "requires a valid customer list when removing customers" do
|
475
|
+
stub_request(:post, api_uri('/api/v1/segments/1/remove_customers')).to_return(:status => 200, :body => "", :headers => {})
|
476
|
+
|
477
|
+
lambda { client.remove_from_segment(1, "not_valid").should raise_error(Customerio::Client::ParamError) }
|
478
|
+
end
|
479
|
+
it "coerces non-string values to strings when removing customers" do
|
480
|
+
stub_request(:post, api_uri('/api/v1/segments/1/remove_customers')).with(:body=>json({:ids=>["1", "2", "3"]})).to_return(:status => 200, :body => "", :headers => {})
|
481
|
+
|
482
|
+
client.remove_from_segment(1, [1, 2, 3])
|
483
|
+
end
|
484
|
+
end
|
358
485
|
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: 2.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Allison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|
@@ -28,44 +28,44 @@ dependencies:
|
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '10.5'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '10.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.3.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 3.3.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: webmock
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 1.24.2
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 1.24.2
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: addressable
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,7 +116,8 @@ files:
|
|
116
116
|
- spec/client_spec.rb
|
117
117
|
- spec/spec_helper.rb
|
118
118
|
homepage: http://customer.io
|
119
|
-
licenses:
|
119
|
+
licenses:
|
120
|
+
- MIT
|
120
121
|
metadata: {}
|
121
122
|
post_install_message:
|
122
123
|
rdoc_options: []
|
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
version: '0'
|
135
136
|
requirements: []
|
136
137
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.
|
138
|
+
rubygems_version: 2.7.7
|
138
139
|
signing_key:
|
139
140
|
specification_version: 4
|
140
141
|
summary: A ruby client for the Customer.io event API.
|