customerio 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZTZjMjYyNzc2NDA2ZjViNGM3YzY0MjM2ZmU1MGNkZmRmOTRmNmYzOA==
4
+ ZGI2YjQwMzVhYWJlNGE2ZWRiNDA4ZmY2MjQ3ZGJiMzEwNDlhNGU2ZA==
5
5
  data.tar.gz: !binary |-
6
- NzljMDM4NjY5ZDljN2MwOTYyMWMzOGFiYzFiOGEzNjM5ZTgyMjc1MA==
6
+ OWFlNzY0YzcwZDczMGU4NzRiNDQxMDIzY2FhYzEyMTlhNjU4N2ZjMw==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- YmQzNDE4OTMyMTFmODE0NWNkMTc4NGYzYmZkNjJkMjlkZTVlNTBkYTIyNWE4
10
- YWVkMTA5NzBmNjkxZTEzZTNkMmFmNDRlNTlkNWRhNTQ0NzM3ZTM5YzlhYTAy
11
- ODg2OWU3ZWQ4MjcwY2IwODY4Mzk2ODdjM2UxNDkyNzNkZDUxODQ=
9
+ NjIxNDhlYzU0OGRmMWI3Y2I5YmViYWExZDNlYTEyNjUyYTRmYjgwZDM1NTM2
10
+ ZjE4YzdkNzBmYmRkZWY2MDM5YmYxOTI0YjE1YmVlYjdiZjJlZGYyYTQ3ZWRm
11
+ Y2IwOGMzYzQ3OWE4YWUxMzM1OWRjODIwZDQzODU2N2ExMjM4NTY=
12
12
  data.tar.gz: !binary |-
13
- NGU3MjIzNDFjN2ZiN2I5MmZiY2FlY2YwNGU5MjE0OGFkZjJjY2RhNDc5NmM5
14
- NDNmMDFlMjI2N2Q0YjEzZWQ1ZGRiYjY3MzE1YTg1ZDFhNjZiZTY0MGMzYjI5
15
- ODYxZDQ4OTZmMTc5NDU3MmRmNDNmNDQyNzViZmVkYzQ1OWIzZjc=
13
+ YzI0Nzk1NGNkOTFkMWQxZDcyZjkwNzQ3OTlhZGExYjQ5NjhhNWU4ZDUxZTdl
14
+ OWZlZWFjNzk5MDkzZDU0OGVkZGU0MzI2ZmU0N2U4NDI2OWRjOTIxODc4YzUy
15
+ YTU1NDAyNGJlNzgxMDc1NWU4YjYxNWNiNDdiMjgxNGVmMzU5MDg=
@@ -1,3 +1,15 @@
1
+ ## Customerio 0.7.0 - Mar 2, 2016 ##
2
+
3
+ * 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)
4
+
5
+ * Use JSON encoding by default. [#37](https://github.com/customerio/customerio-ruby/pull/37)
6
+
7
+ If you want to stick with form-encoding for your integration, you must add `:json => false` to your Customerio::Client initializer. Like this:
8
+
9
+ ```ruby
10
+ customerio = Customerio::Client.new("YOUR SITE ID", "YOUR API SECRET KEY", :json => false)
11
+ ```
12
+
1
13
  ## Customerio 0.6.1 - Oct 8, 2015 ##
2
14
 
3
15
  * Include HTTP response as an attribute on the InvalidResponse exception to help with debugging failed API requests. For example:
@@ -134,6 +134,16 @@ $customerio.track(5, "purchase", :type => "socks", :price => "13.99")
134
134
  $customerio.track(5, "purchase", :type => "socks", :price => "13.99", :timestamp => 1365436200)
135
135
  ```
136
136
 
137
+ ### Tracking anonymous events
138
+
139
+ You can also send anonymous events, for situations where you don't yet have a customer record but still want to trigger a campaign:
140
+
141
+ ```ruby
142
+ $customerio.anonymous_track("help_enquiry", :recipient => 'user@example.com')
143
+ ```
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).
146
+
137
147
  ## Contributing
138
148
 
139
149
  1. Fork it
@@ -19,10 +19,7 @@ module Customerio
19
19
 
20
20
  def initialize(site_id, secret_key, options = {})
21
21
  @auth = { :username => site_id, :password => secret_key }
22
- if options[:json].nil?
23
- warn "[DEPRECATION] Customerio::Client: JSON encoding will be the default in the next release. We recommend switching to JSON. To continue to use form-encoding, you must specify `:json => false` in your initializer."
24
- end
25
- @json = options[:json]
22
+ @json = options.has_key?(:json) ? options[:json] : true
26
23
  end
27
24
 
28
25
  def identify(attributes)
@@ -49,6 +46,10 @@ module Customerio
49
46
  end
50
47
  end
51
48
 
49
+ def anonymous_track(event_name, attributes = {})
50
+ create_anonymous_event(event_name, attributes)
51
+ end
52
+
52
53
  private
53
54
 
54
55
  def create_or_update(attributes = {})
@@ -1,3 +1,3 @@
1
1
  module Customerio
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
@@ -11,6 +11,36 @@ describe Customerio::Client do
11
11
  Customerio::Client.stub(:put).and_return(response)
12
12
  end
13
13
 
14
+ describe "json option" do
15
+ let(:body) { { :id => 5, :name => "Bob" } }
16
+
17
+ it "uses json by default" do
18
+ client = Customerio::Client.new("SITE_ID", "API_KEY")
19
+
20
+ json = MultiJson.dump(body)
21
+ Customerio::Client.should_receive(:put).with(
22
+ "/api/v1/customers/5",
23
+ {
24
+ :basic_auth=>{:username=>"SITE_ID", :password=>"API_KEY"},
25
+ :body=>json,
26
+ :headers=>{"Content-Type"=>"application/json"}
27
+ }).and_return(response)
28
+ client.identify(body)
29
+ end
30
+
31
+ it "allows disabling json" do
32
+ client = Customerio::Client.new("SITE_ID", "API_KEY", :json => false)
33
+
34
+ Customerio::Client.should_receive(:put).with(
35
+ "/api/v1/customers/5",
36
+ {
37
+ :basic_auth=>{:username=>"SITE_ID", :password=>"API_KEY"},
38
+ :body=>body
39
+ }).and_return(response)
40
+ client.identify(body)
41
+ end
42
+ end
43
+
14
44
  describe ".base_uri" do
15
45
  it "should be set to customer.io's api" do
16
46
  Customerio::Client.base_uri.should == "https://track.customer.io"
@@ -247,4 +277,65 @@ describe Customerio::Client do
247
277
  end
248
278
  end
249
279
  end
280
+
281
+ describe "#anonymous_track" do
282
+ it "sends a POST request to the customer.io event API" do
283
+ Customerio::Client.should_receive(:post).with("/api/v1/events", anything()).and_return(response)
284
+ client.anonymous_track("purchase")
285
+ end
286
+
287
+ it "raises an error if POST doesn't return a 2xx response code" do
288
+ Customerio::Client.should_receive(:post).and_return(double("Response", :code => 500))
289
+ lambda { client.anonymous_track("purchase") }.should raise_error(Customerio::Client::InvalidResponse)
290
+ end
291
+
292
+ it "uses the site_id and api key for basic auth" do
293
+ Customerio::Client.should_receive(:post).with("/api/v1/events", {
294
+ :basic_auth => { :username => "SITE_ID", :password => "API_KEY" },
295
+ :body => anything()
296
+ })
297
+
298
+ client.anonymous_track("purchase")
299
+ end
300
+
301
+ it "sends the event name" do
302
+ Customerio::Client.should_receive(:post).with("/api/v1/events", {
303
+ :basic_auth => anything(),
304
+ :body => { :name => "purchase", :data => {} }
305
+ }).and_return(response)
306
+
307
+ client.anonymous_track("purchase")
308
+ end
309
+
310
+ it "sends any optional event attributes" do
311
+ Customerio::Client.should_receive(:post).with("/api/v1/events", {
312
+ :basic_auth => anything(),
313
+ :body => {
314
+ :name => "purchase",
315
+ :data => { :type => "socks", :price => "27.99" }
316
+ }
317
+ }).and_return(response)
318
+
319
+ client.anonymous_track("purchase", :type => "socks", :price => "27.99")
320
+ end
321
+
322
+ it "allows sending of a timestamp" do
323
+ Customerio::Client.should_receive(:post).with("/api/v1/events", {
324
+ :basic_auth => anything(),
325
+ :body => {
326
+ :name => "purchase",
327
+ :data => { :type => "socks", :price => "27.99", :timestamp => 1561235678 },
328
+ :timestamp => 1561235678
329
+ }
330
+ }).and_return(response)
331
+
332
+ client.anonymous_track("purchase", :type => "socks", :price => "27.99", :timestamp => 1561235678)
333
+ end
334
+
335
+ context "too many arguments are passed" do
336
+ it "throws an error" do
337
+ lambda { client.anonymous_track("purchase", "text", :type => "socks", :price => "27.99") }.should raise_error(ArgumentError)
338
+ end
339
+ end
340
+ end
250
341
  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: 0.6.1
4
+ version: 0.7.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: 2015-10-08 00:00:00.000000000 Z
11
+ date: 2016-03-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty
@@ -98,12 +98,12 @@ files:
98
98
  - CHANGELOG.markdown
99
99
  - Gemfile
100
100
  - LICENSE
101
+ - README.md
101
102
  - Rakefile
102
103
  - customerio.gemspec
103
104
  - lib/customerio.rb
104
105
  - lib/customerio/client.rb
105
106
  - lib/customerio/version.rb
106
- - readme.markdown
107
107
  - spec/client_spec.rb
108
108
  - spec/spec_helper.rb
109
109
  homepage: http://customer.io