diff --git a/lib/drip/client/events.rb b/lib/drip/client/events.rb index 28ea6db..695f13e 100644 --- a/lib/drip/client/events.rb +++ b/lib/drip/client/events.rb @@ -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 diff --git a/lib/drip/version.rb b/lib/drip/version.rb index 13fea7b..432b883 100644 --- a/lib/drip/version.rb +++ b/lib/drip/version.rb @@ -1,3 +1,3 @@ module Drip - VERSION = "0.0.4" + VERSION = "0.0.5" end diff --git a/test/drip/client/events_test.rb b/test/drip/client/events_test.rb index 3babee4..c7303da 100644 --- a/test/drip/client/events_test.rb +++ b/test/drip/client/events_test.rb @@ -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