customerio 1.0.0 → 2.0.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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWFhMDk1ZmMzOTBjZTZhMzYxNGYyZTJmZDFlMTdiZWI1NjdhMTY4YQ==
4
+ ZGQ1ZjA4MDkwN2JhMDljOTRjODBhOTdhZjllMDg0YTZmOGRlMmI0Yg==
5
5
  data.tar.gz: !binary |-
6
- YmMyODY3OTIxMjhkN2MxYzVlNzdlOWRiOTgxNzc2OWUyYWJjNDc0Ng==
6
+ NTk1ODZkN2MwMDY0ZjI5ZDI4MTk3ZjlmZjI3MDdhZGVlYTdjYTJiNg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NjA5OWUwZDU4ZmJmYjA3YmQ4ZTY0ZDhlNWQzMjU2MDViNzk3NjkxNzI2Zjcw
10
- YjFjNDg4N2Q5YzQwMWIxZGJkZWFmNzNlYTEzYjVkNWZlY2Q4MjgyNjM3MWNm
11
- M2ZjMzU5MGUyMzljOTg0NTA0OWM5NDZkMDU4MTVlMzViNDEzYWU=
9
+ YTNmYjQxYmU1YWM1ZmRiYjNjZWFhZjE5NjczZmE2MTI5NWIyMjhjNGYzYjkw
10
+ YjAxMjYwOTI3ZGZiNDhmZjgwNGNmYzNlMmIwY2Y2ODg3ODQ0NjA3ZGNjODVl
11
+ OTg5YzU1NWJlYzJjNDAwZWM5OWM3MWE0ZDk5NzY5NmUzMzgyNTU=
12
12
  data.tar.gz: !binary |-
13
- YTMxNjA2NzJjNzU2ZDExNzBjZDYxODBhMDRiMTg1MWE3ZDIzMmI5YzcxYzE5
14
- MGNhNTc5YTJmYjRmNjBlYTljODU3YzhiMGZiZGNkM2UyOTZhYzkyMWE0ZTBl
15
- MGY2Mzg1YzMyMGYxNzg2NGY1YjY4YmFhZjkwYzVjN2IxYjNkYTE=
13
+ YmU2NzM4N2ZiNDI0MmU1MTA5MmQ1N2U1ZDc5OGM3OGY3NTg2ODExY2Y0YzAz
14
+ YmI2Y2YyOTBkMDVkOGYzMDg0ZWZjMDZhMGI2YjgyMjNjNTBkYWNiMjc1Zjhk
15
+ YjA5MWZjODg4ZGU1NGFiMWMwNzQxN2VmZTRkNzg4MGUzYTk1MGI=
data/.travis.yml CHANGED
@@ -1,14 +1,9 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 1.8.7
5
4
  - 1.9.2
6
5
  - 1.9.3
7
6
  - 2.0.0
8
7
  - 2.1.6
9
8
  - 2.2.2
10
- - jruby-18mode
11
9
  - jruby-19mode
12
- - jruby-head
13
- - ree
14
- - ruby-head
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,9 @@
1
+ ## Customerio 2.0.0 - Apr 10, 2018 ##
2
+
3
+ With this release we have dropped the support for ruby 1.8.7.
4
+
5
+ * Support new add and remove device endpoints for push notifications [#47](https://github.com/customerio/customerio-ruby/pull/47)
6
+
1
7
  ## Customerio 1.0.0 - Mar 15, 2016 ##
2
8
 
3
9
  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`.
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/docs/api/overview.html).
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/docs/basic-integration.html).
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://manage.customer.io/integration).
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,30 @@ 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/docs/invitation-emails.html).
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
+ ```
146
169
 
147
170
  ## Contributing
148
171
 
data/customerio.gemspec CHANGED
@@ -17,9 +17,9 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency('multi_json', "~> 1.0")
19
19
 
20
- gem.add_development_dependency('rake')
21
- gem.add_development_dependency('rspec')
22
- gem.add_development_dependency('webmock')
20
+ gem.add_development_dependency('rake', '~> 10.5')
21
+ gem.add_development_dependency('rspec', '3.3.0')
22
+ gem.add_development_dependency('webmock', '1.24.2')
23
23
  gem.add_development_dependency('addressable', '~> 2.3.6')
24
24
  gem.add_development_dependency('json')
25
25
  end
@@ -7,6 +7,7 @@ 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
@@ -53,8 +54,42 @@ module Customerio
53
54
  create_anonymous_event(event_name, attributes)
54
55
  end
55
56
 
57
+ def add_device(customer_id, device_id, platform, data={})
58
+ raise ParamError.new("customer_id must be a non-empty string") unless customer_id != "" and !customer_id.nil?
59
+ raise ParamError.new("device_id must be a non-empty string") unless device_id != "" and !device_id.nil?
60
+ raise ParamError.new("platform must be a non-empty string") unless platform != "" and !platform.nil?
61
+
62
+ if data.nil?
63
+ data = {}
64
+ end
65
+
66
+ raise ParamError.new("data parameter must be a hash") unless data.is_a?(Hash)
67
+
68
+ verify_response(request(:put, device_path(customer_id), {
69
+ :device => data.update({
70
+ :id => device_id,
71
+ :platform => platform,
72
+ })
73
+ }))
74
+ end
75
+
76
+ def delete_device(customer_id, device_id)
77
+ raise ParamError.new("customer_id must be a non-empty string") unless customer_id != "" and !customer_id.nil?
78
+ raise ParamError.new("device_id must be a non-empty string") unless device_id != "" and !device_id.nil?
79
+
80
+ verify_response(request(:delete, device_id_path(customer_id, device_id)))
81
+ end
82
+
56
83
  private
57
84
 
85
+ def device_path(customer_id)
86
+ "/api/v1/customers/#{customer_id}/devices"
87
+ end
88
+
89
+ def device_id_path(customer_id, device_id)
90
+ "/api/v1/customers/#{customer_id}/devices/#{device_id}"
91
+ end
92
+
58
93
  def create_or_update(attributes = {})
59
94
  attributes = Hash[attributes.map { |(k,v)| [ k.to_sym, v ] }]
60
95
 
@@ -1,3 +1,3 @@
1
1
  module Customerio
2
- VERSION = "1.0.0"
2
+ VERSION = "2.0.0"
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -355,4 +355,67 @@ describe Customerio::Client do
355
355
  end
356
356
  end
357
357
  end
358
+
359
+ describe "#devices" do
360
+ it "allows for the creation of a new device" do
361
+ stub_request(:put, api_uri('/api/v1/customers/5/devices')).
362
+ to_return(:status => 200, :body => "", :headers => {})
363
+
364
+ client.add_device(5, "androidDeviceID", "ios", {:last_used=>1561235678})
365
+ client.add_device(5, "iosDeviceID", "android")
366
+ end
367
+ it "requires a valid customer_id when creating" do
368
+ stub_request(:put, api_uri('/api/v1/customers/5/devices')).
369
+ to_return(:status => 200, :body => "", :headers => {})
370
+
371
+ lambda { client.add_device("", "ios", "myDeviceID") }.should raise_error(Customerio::Client::ParamError)
372
+ lambda { client.add_device(nil, "ios", "myDeviceID", {:last_used=>1561235678}) }.should raise_error(Customerio::Client::ParamError)
373
+ end
374
+ it "requires a valid token when creating" do
375
+ stub_request(:put, api_uri('/api/v1/customers/5/devices')).
376
+ to_return(:status => 200, :body => "", :headers => {})
377
+
378
+ lambda { client.add_device(5, "", "ios") }.should raise_error(Customerio::Client::ParamError)
379
+ lambda { client.add_device(5, nil, "ios", {:last_used=>1561235678}) }.should raise_error(Customerio::Client::ParamError)
380
+ end
381
+ it "requires a valid platform when creating" do
382
+ stub_request(:put, api_uri('/api/v1/customers/5/devices')).
383
+ to_return(:status => 200, :body => "", :headers => {})
384
+
385
+ lambda { client.add_device(5, "token", "") }.should raise_error(Customerio::Client::ParamError)
386
+ lambda { client.add_device(5, "toke", nil, {:last_used=>1561235678}) }.should raise_error(Customerio::Client::ParamError)
387
+ end
388
+ it "accepts a nil data param" do
389
+ stub_request(:put, api_uri('/api/v1/customers/5/devices')).
390
+ to_return(:status => 200, :body => "", :headers => {})
391
+
392
+ client.add_device(5, "ios", "myDeviceID", nil)
393
+ end
394
+ it "fails on invalid data param" do
395
+ stub_request(:put, api_uri('/api/v1/customers/5/devices')).
396
+ to_return(:status => 200, :body => "", :headers => {})
397
+
398
+ lambda { client.add_device(5, "ios", "myDeviceID", 1000) }.should raise_error(Customerio::Client::ParamError)
399
+ end
400
+ it "supports deletion of devices by token" do
401
+ stub_request(:delete, api_uri('/api/v1/customers/5/devices/myDeviceID')).
402
+ to_return(:status => 200, :body => "", :headers => {})
403
+
404
+ client.delete_device(5, "myDeviceID")
405
+ end
406
+ it "requires a valid customer_id when deleting" do
407
+ stub_request(:delete, api_uri('/api/v1/customers/5/devices/myDeviceID')).
408
+ to_return(:status => 200, :body => "", :headers => {})
409
+
410
+ lambda { client.delete_device("", "myDeviceID") }.should raise_error(Customerio::Client::ParamError)
411
+ lambda { client.delete_device(nil, "myDeviceID") }.should raise_error(Customerio::Client::ParamError)
412
+ end
413
+ it "requires a valid device_id when deleting" do
414
+ stub_request(:delete, api_uri('/api/v1/customers/5/devices/myDeviceID')).
415
+ to_return(:status => 200, :body => "", :headers => {})
416
+
417
+ lambda { client.delete_device(5, "") }.should raise_error(Customerio::Client::ParamError)
418
+ lambda { client.delete_device(5, nil) }.should raise_error(Customerio::Client::ParamError)
419
+ end
420
+ end
358
421
  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: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Allison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-15 00:00:00.000000000 Z
11
+ date: 2018-04-10 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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
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: '0'
68
+ version: 1.24.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: addressable
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.4.7
137
+ rubygems_version: 2.6.2
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: A ruby client for the Customer.io event API.