Skip to content

Commit 82f2ef6

Browse files
committed
Support additional event properties
1 parent bc77c77 commit 82f2ef6

File tree

3 files changed

+53
-17
lines changed

3 files changed

+53
-17
lines changed

lib/drip/client/events.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ module Events
88
# email - Required. The String email address of the subscriber.
99
# action - Required. The String event action.
1010
# properties - Optional. A Hash of event properties.
11+
# options - Optional. A Hash of additional options:
12+
# - prospect - A Boolean indicating if the subscriber is a prospect.
13+
# - occurred_at - A String time at which the event occurred in ISO-8601 format.
1114
#
1215
# Returns a Drip::Response.
1316
# See https://www.getdrip.com/docs/rest-api#record_event
14-
def track_event(email, action, properties = {})
15-
data = { "email" => email, "action" => action, "properties" => properties }
17+
def track_event(email, action, properties = {}, options = {})
18+
data = options.merge({ "email" => email, "action" => action, "properties" => properties })
1619
post "#{account_id}/events", generate_resource("events", data)
1720
end
1821

lib/drip/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Drip
2-
VERSION = "0.0.4"
2+
VERSION = "0.0.5"
33
end

test/drip/client/events_test.rb

Lines changed: 47 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,58 @@ def setup
1717
@email = "[email protected]"
1818
@action = "Signed up"
1919
@properties = { "foo" => "bar" }
20-
@payload = {
21-
"events" => [{
22-
"email" => @email,
23-
"action" => @action,
24-
"properties" => @properties
25-
}]
26-
}.to_json
20+
end
2721

28-
@response_status = 201
29-
@response_body = stub
22+
context "without options" do
23+
setup do
24+
@payload = {
25+
"events" => [{
26+
"email" => @email,
27+
"action" => @action,
28+
"properties" => @properties
29+
}]
30+
}.to_json
3031

31-
@stubs.post "12345/events", @payload do
32-
[@response_status, {}, @response_body]
32+
@response_status = 201
33+
@response_body = stub
34+
35+
@stubs.post "12345/events", @payload do
36+
[@response_status, {}, @response_body]
37+
end
38+
end
39+
40+
should "send the right request" do
41+
expected = Drip::Response.new(@response_status, @response_body)
42+
assert_equal expected, @client.track_event(@email, @action, @properties)
3343
end
3444
end
3545

36-
should "send the right request" do
37-
expected = Drip::Response.new(@response_status, @response_body)
38-
assert_equal expected, @client.track_event(@email, @action, @properties)
46+
context "with options" do
47+
setup do
48+
@occurred_at = "2015-09-28T10:00:00Z"
49+
@options = { occurred_at: @occurred_at }
50+
51+
@payload = {
52+
"events" => [{
53+
"occurred_at" => @occurred_at,
54+
"email" => @email,
55+
"action" => @action,
56+
"properties" => @properties
57+
}]
58+
}.to_json
59+
60+
@response_status = 201
61+
@response_body = stub
62+
63+
@stubs.post "12345/events", @payload do
64+
[@response_status, {}, @response_body]
65+
end
66+
end
67+
68+
should "send the right request" do
69+
expected = Drip::Response.new(@response_status, @response_body)
70+
assert_equal expected, @client.track_event(@email, @action, @properties, @options)
71+
end
3972
end
4073
end
4174

0 commit comments

Comments
 (0)