customerio 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- customerio (0.0.2)
4
+ customerio (0.0.3)
5
5
  httparty (~> 0.9.0)
6
6
 
7
7
  GEM
@@ -23,9 +23,20 @@ module Customerio
23
23
  create_or_update(customer, attributes)
24
24
  end
25
25
 
26
- def track(customer, event_name, hash = {})
27
- identify(customer)
28
- create_event(customer, event_name, hash)
26
+ def track(*args)
27
+ hash = args.last.is_a?(Hash) ? args.pop : {}
28
+
29
+ if args.length == 1
30
+ # Only passed in an event name, create an anonymous event
31
+ create_anonymous_event(args.first, hash)
32
+ else
33
+ # Passed in a customer and an event name.
34
+ # Track the event for the given customer
35
+ customer, event_name = args
36
+
37
+ identify(customer)
38
+ create_customer_event(customer, event_name, hash)
39
+ end
29
40
  end
30
41
 
31
42
  private
@@ -40,9 +51,17 @@ module Customerio
40
51
  self.class.put(customer_path(customer), options.merge(:body => body))
41
52
  end
42
53
 
43
- def create_event(customer, event_name, attributes = {})
54
+ def create_customer_event(customer, event_name, attributes = {})
55
+ create_event("#{customer_path(customer)}/events", event_name, attributes)
56
+ end
57
+
58
+ def create_anonymous_event(event_name, attributes = {})
59
+ create_event("/api/v1/events", event_name, attributes)
60
+ end
61
+
62
+ def create_event(url, event_name, attributes = {})
44
63
  body = { :name => event_name, :data => attributes }
45
- self.class.post("#{customer_path(customer)}/events", options.merge(:body => body))
64
+ self.class.post(url, options.merge(:body => body))
46
65
  end
47
66
 
48
67
  def customer_path(customer)
@@ -1,3 +1,3 @@
1
1
  module Customerio
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
data/spec/client_spec.rb CHANGED
@@ -138,5 +138,42 @@ describe Customerio::Client do
138
138
  client.track(customer, "purchase")
139
139
  end
140
140
  end
141
+
142
+ context "tracking an anonymous event" do
143
+ it "sends a POST request to the customer.io's anonymous event API" do
144
+ Customerio::Client.should_receive(:post).with("/api/v1/events", anything())
145
+ client.track("purchase")
146
+ end
147
+
148
+ it "uses the site_id and api key for basic auth" do
149
+ Customerio::Client.should_receive(:post).with("/api/v1/events", {
150
+ :basic_auth => { :username => "SITE_ID", :password => "API_KEY" },
151
+ :body => anything()
152
+ })
153
+
154
+ client.track("purchase")
155
+ end
156
+
157
+ it "sends the event name" do
158
+ Customerio::Client.should_receive(:post).with("/api/v1/events", {
159
+ :basic_auth => anything(),
160
+ :body => { :name => "purchase", :data => {} }
161
+ })
162
+
163
+ client.track("purchase")
164
+ end
165
+
166
+ it "sends any optional event attributes" do
167
+ Customerio::Client.should_receive(:post).with("/api/v1/events", {
168
+ :basic_auth => anything(),
169
+ :body => {
170
+ :name => "purchase",
171
+ :data => { :type => "socks", :price => "13.99" }
172
+ }
173
+ })
174
+
175
+ client.track("purchase", :type => "socks", :price => "13.99")
176
+ end
177
+ end
141
178
  end
142
179
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: customerio
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-06 00:00:00.000000000 Z
12
+ date: 2012-11-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty