Skip to content

Commit

Permalink
Support additional event properties
Browse files Browse the repository at this point in the history
  • Loading branch information
derrickreimer committed Sep 15, 2015
1 parent bc77c77 commit 82f2ef6
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 17 deletions.
7 changes: 5 additions & 2 deletions lib/drip/client/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ module Events
# email - Required. The String email address of the subscriber.
# action - Required. The String event action.
# properties - Optional. A Hash of event properties.
# options - Optional. A Hash of additional options:
# - prospect - A Boolean indicating if the subscriber is a prospect.
# - occurred_at - A String time at which the event occurred in ISO-8601 format.
#
# Returns a Drip::Response.
# See https://www.getdrip.com/docs/rest-api#record_event
def track_event(email, action, properties = {})
data = { "email" => email, "action" => action, "properties" => properties }
def track_event(email, action, properties = {}, options = {})
data = options.merge({ "email" => email, "action" => action, "properties" => properties })
post "#{account_id}/events", generate_resource("events", data)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/drip/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Drip
VERSION = "0.0.4"
VERSION = "0.0.5"
end
61 changes: 47 additions & 14 deletions test/drip/client/events_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,58 @@ def setup
@email = "derrick@getdrip.com"
@action = "Signed up"
@properties = { "foo" => "bar" }
@payload = {
"events" => [{
"email" => @email,
"action" => @action,
"properties" => @properties
}]
}.to_json
end

@response_status = 201
@response_body = stub
context "without options" do
setup do
@payload = {
"events" => [{
"email" => @email,
"action" => @action,
"properties" => @properties
}]
}.to_json

@stubs.post "12345/events", @payload do
[@response_status, {}, @response_body]
@response_status = 201
@response_body = stub

@stubs.post "12345/events", @payload do
[@response_status, {}, @response_body]
end
end

should "send the right request" do
expected = Drip::Response.new(@response_status, @response_body)
assert_equal expected, @client.track_event(@email, @action, @properties)
end
end

should "send the right request" do
expected = Drip::Response.new(@response_status, @response_body)
assert_equal expected, @client.track_event(@email, @action, @properties)
context "with options" do
setup do
@occurred_at = "2015-09-28T10:00:00Z"
@options = { occurred_at: @occurred_at }

@payload = {
"events" => [{
"occurred_at" => @occurred_at,
"email" => @email,
"action" => @action,
"properties" => @properties
}]
}.to_json

@response_status = 201
@response_body = stub

@stubs.post "12345/events", @payload do
[@response_status, {}, @response_body]
end
end

should "send the right request" do
expected = Drip::Response.new(@response_status, @response_body)
assert_equal expected, @client.track_event(@email, @action, @properties, @options)
end
end
end

Expand Down

0 comments on commit 82f2ef6

Please sign in to comment.