-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow customer_id to be specified in identify URL (based on work by j…
…rbeck)
- Loading branch information
1 parent
16e0afe
commit 6292726
Showing
3 changed files
with
80 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,29 @@ $customerio.identify( | |
) | ||
``` | ||
|
||
### Updating customers | ||
### Updating customers: Using other IDs | ||
|
||
If you wish to specify a customer ID that is different than the one used in the `id` attribute, you can do so by using the `identify_customer_id` method: | ||
|
||
```ruby | ||
# Arguments | ||
# customer_id (required) - the customer ID to use for this customer, may be an id, email address, or the cio_id. | ||
# This will be used to construct the URL but not sent in the body attributes. | ||
# attributes (required) - a hash of information about the customer. You can pass any | ||
# information that would be useful in your triggers. You | ||
# must at least pass in an id, email, and created_at timestamp. | ||
|
||
$customerio.identify_customer_id( | ||
:customer_id => "[email protected]", | ||
:id => 5, | ||
:email => "[email protected]", | ||
:created_at => customer.created_at.to_i, | ||
:first_name => "Bob", | ||
:plan => "basic" | ||
) | ||
``` | ||
|
||
### Updating customers: Changing identifiers | ||
|
||
You can use the identify operation to update customers. | ||
If you need to change the `id` or `email` identifiers for a customer, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -225,6 +225,50 @@ def json(data) | |
end | ||
end | ||
|
||
describe "#identify_customer_id" do | ||
it "uses provided id rather than id" do | ||
stub_request(:put, api_uri('/api/v1/customers/1234')). | ||
with(body: json(id: "5")). | ||
to_return(status: 200, body: "", headers: {}) | ||
|
||
client.identify_customer_id( | ||
customer_id: "1234", | ||
id: "5" | ||
) | ||
end | ||
|
||
it "uses provided cio_id rather than id" do | ||
stub_request(:put, api_uri('/api/v1/customers/cio_5')). | ||
with(body: json(id: "5")). | ||
to_return(status: 200, body: "", headers: {}) | ||
|
||
client.identify_customer_id( | ||
customer_id: "cio_5", | ||
id: "5" | ||
) | ||
end | ||
|
||
it "uses provided email rather than id" do | ||
stub_request(:put, api_uri('/api/v1/customers/[email protected]')). | ||
with(body: json(id: "5")). | ||
to_return(status: 200, body: "", headers: {}) | ||
|
||
client.identify_customer_id( | ||
customer_id: "[email protected]", | ||
id: "5" | ||
) | ||
end | ||
|
||
it "requires a customer_id attribute" do | ||
lambda { client.identify_customer_id() }.should raise_error(Customerio::Client::MissingIdAttributeError) | ||
lambda { client.identify_customer_id(customer_id: "") }.should raise_error(Customerio::Client::MissingIdAttributeError) | ||
# None of these are customer_id | ||
lambda { client.identify_customer_id(id: "5") }.should raise_error(Customerio::Client::MissingIdAttributeError) | ||
lambda { client.identify_customer_id(cio_id: "cio_5") }.should raise_error(Customerio::Client::MissingIdAttributeError) | ||
lambda { client.identify_customer_id(email: "[email protected]") }.should raise_error(Customerio::Client::MissingIdAttributeError) | ||
end | ||
end | ||
|
||
describe "#delete" do | ||
it "sends a DELETE request to the customer.io's event API" do | ||
stub_request(:delete, api_uri('/api/v1/customers/5')). | ||
|
@@ -650,7 +694,7 @@ def json(data) | |
}.to raise_error(Customerio::Client::ParamError, 'timestamp must be a valid timestamp') | ||
end | ||
end | ||
|
||
describe "#merge_customers" do | ||
before(:each) do | ||
@client = Customerio::Client.new("SITE_ID", "API_KEY", :json => true) | ||
|