-
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 (#111)
* Allow customer_id to be specified in identify URL (based on work by jrbeck) * Bump for release 5.3.0 * Re-order the code docs and clarify usage of cio_id * Move the support for :customer_id into the base identify method * Update changelog * Note that customer_id attribute can't be set anymore
- Loading branch information
1 parent
da7c1f5
commit c29ac0b
Showing
5 changed files
with
89 additions
and
4 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
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,7 @@ $customerio.identify( | |
) | ||
``` | ||
|
||
### Updating customers | ||
### 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, | ||
|
@@ -113,6 +113,35 @@ $customerio.identify( | |
) | ||
``` | ||
|
||
This method requires either the `id` or `cio_id` for the person. It does not work with email addresses. | ||
|
||
You can also use this method to make other updates to the person using the `cio_id`. | ||
|
||
### Updating customers: Using email address | ||
|
||
If you need to identify a person using their email address, then you can do so | ||
by passing in a customer ID to the `identify` method. This allows you to specify | ||
a customer ID that is different than the one used in the `id` attribute. E.g.: | ||
|
||
```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 => "[email protected]", | ||
:location => "Australia" | ||
) | ||
``` | ||
|
||
Note: | ||
|
||
* If you want to use the `cio_id` in the `customer_id` field of `identify_customer_id`, you will need to prefix it with `"cio_"`. E.g.: `"cio_f000000d"` for a `cio_id` of `f000000d`. | ||
* The `identify` method can identify the person using one of `customer_id`, `cio_id` or `id`. The order of precedence is `customer_id` > `cio_id` > `id`. | ||
|
||
### Deleting customers | ||
|
||
Deleting a customer will remove them, and all their information from | ||
|
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module Customerio | ||
VERSION = "5.2.0" | ||
VERSION = "5.3.0" | ||
end |
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 |
---|---|---|
|
@@ -173,6 +173,7 @@ def json(data) | |
lambda { client.identify(email: "[email protected]") }.should raise_error(Customerio::Client::MissingIdAttributeError) | ||
lambda { client.identify(id: "") }.should raise_error(Customerio::Client::MissingIdAttributeError) | ||
lambda { client.identify(cio_id: "") }.should raise_error(Customerio::Client::MissingIdAttributeError) | ||
lambda { client.identify(customer_id: "") }.should raise_error(Customerio::Client::MissingIdAttributeError) | ||
end | ||
|
||
it 'should not raise errors when attribute keys are strings' do | ||
|
@@ -223,6 +224,39 @@ def json(data) | |
location: "here" | ||
}) | ||
end | ||
|
||
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: "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: "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: "[email protected]", | ||
id: "5" | ||
) | ||
end | ||
end | ||
|
||
describe "#delete" do | ||
|
@@ -650,7 +684,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) | ||
|