customerio 0.0.3 → 0.1.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.
- data/Gemfile.lock +1 -1
- data/lib/customerio/client.rb +24 -5
- data/lib/customerio/version.rb +1 -1
- data/spec/client_spec.rb +37 -0
- metadata +2 -2
data/Gemfile.lock
CHANGED
data/lib/customerio/client.rb
CHANGED
@@ -23,9 +23,20 @@ module Customerio
|
|
23
23
|
create_or_update(customer, attributes)
|
24
24
|
end
|
25
25
|
|
26
|
-
def track(
|
27
|
-
|
28
|
-
|
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
|
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(
|
64
|
+
self.class.post(url, options.merge(:body => body))
|
46
65
|
end
|
47
66
|
|
48
67
|
def customer_path(customer)
|
data/lib/customerio/version.rb
CHANGED
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
|
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-
|
12
|
+
date: 2012-11-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httparty
|