-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added search customer by email api #124
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,9 +95,9 @@ cio.destroy(1); | |
|
||
- **id**: String or number (required) | ||
|
||
#### Attention! | ||
#### Attention! | ||
|
||
This method will only delete a person and not suppress them. This means they can be readded. | ||
This method will only delete a person and not suppress them. This means they can be readded. | ||
If you need to suppress a person, please use [`cio.suppress`](https://github.com/customerio/customerio-node#ciosuppressid). | ||
|
||
--- | ||
|
@@ -173,7 +173,7 @@ cio.trackAnonymous(anonymous_id, { | |
|
||
#### Anonymous invite events | ||
|
||
If you previously sent [invite events](https://customer.io/docs/anonymous-invite-emails/), you can achieve the same functionality by sending an anonymous event with an empty string for the anonymous identifier. To send anonymous invites, your event *must* include a `recipient` attribute. | ||
If you previously sent [invite events](https://customer.io/docs/anonymous-invite-emails/), you can achieve the same functionality by sending an anonymous event with an empty string for the anonymous identifier. To send anonymous invites, your event *must* include a `recipient` attribute. | ||
|
||
```javascript | ||
cio.trackAnonymous("", { | ||
|
@@ -347,6 +347,20 @@ api.triggerBroadcast(1, { name: "foo" }, { emails: ["[email protected]"], email | |
- **data**: Object (optional) | ||
- **recipients**: Object (optional) | ||
|
||
### api.getCustomersByEmail(email) | ||
|
||
Returns customer object with given email. | ||
|
||
```javascript | ||
api.getCustomersByEmail("[email protected]") | ||
``` | ||
|
||
[You can learn more about the available recipient fields here](https://customer.io/docs/api/#operation/getPeopleEmail). | ||
|
||
#### Options | ||
|
||
- **email**: String (required) | ||
|
||
## Further examples | ||
|
||
We've included functional examples in the [examples/ directory](https://github.com/customerio/customerio-node/tree/main/examples) of the repo to further assist in demonstrating how to use this library to integrate with Customer.io | ||
|
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const { APIClient, RegionUS, RegionEU } = require('../dist/index'); | ||
// In actual use require the node module: | ||
// const { TrackClient, RegionUS, RegionEU } = require('customerio-node'); | ||
const appKey = require('./config').appKey; | ||
const campaignId = require('./config').campaignId; | ||
const segmentId = require('./config').segmentId; | ||
const cio = new APIClient(appKey, { region: RegionUS }); | ||
|
||
const email = "[email protected]" | ||
|
||
cio.getCustomersByEmail(email); |
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
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 |
---|---|---|
|
@@ -133,6 +133,35 @@ test('#sendEmail: override body: success', (t) => { | |
t.is(req.message.transactional_message_id, 1); | ||
}); | ||
|
||
test('#getCustomersByEmail: searching for a customer email (default)', (t) => { | ||
sinon.stub(t.context.client.request, 'get'); | ||
|
||
const email = '[email protected]'; | ||
t.context.client.getCustomersByEmail(email); | ||
t.truthy((t.context.client.request.get as SinonStub).calledWith(`${RegionUS.apiUrl}/customers?email=${email}`)); | ||
}) | ||
|
||
test('#getCustomersByEmail: should throw error when email is empty', (t) => { | ||
const email = ''; | ||
t.throws(() => t.context.client.getCustomersByEmail(email)); | ||
}) | ||
|
||
|
||
test('#getCustomersByEmail: should throw error when email is null', (t) => { | ||
const email: unknown = null; | ||
t.throws(() => t.context.client.getCustomersByEmail(email as string)); | ||
}) | ||
|
||
test('#getCustomersByEmail: should throw error when email is undefined', (t) => { | ||
const email: unknown = undefined; | ||
t.throws(() => t.context.client.getCustomersByEmail(email as string)); | ||
}) | ||
|
||
test('#getCustomersByEmail: should throw error when email is not a string object', (t) => { | ||
const email: unknown = { "object": "test" }; | ||
t.throws(() => t.context.client.getCustomersByEmail(email as string)); | ||
}) | ||
|
||
test('#sendEmail: adding attachments with encoding (default)', (t) => { | ||
sinon.stub(t.context.client.request, 'post'); | ||
let req = new SendEmailRequest({ to: '[email protected]', identifiers: { id: '2' }, transactional_message_id: 1 }); | ||
|
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import avaTest, { TestInterface } from 'ava'; | ||
import { cleanEmail } from '../lib/utils'; | ||
|
||
type TestContext = {}; | ||
|
||
const test = avaTest as TestInterface<TestContext>; | ||
|
||
|
||
test('#cleanEmail correctly formats email (default)', (t) => { | ||
let email = "[email protected]"; | ||
let result = cleanEmail(email); | ||
t.is(result, 'hello%[email protected]'); | ||
|
||
email = "[email protected]"; | ||
result = cleanEmail(email); | ||
t.is(result, '[email protected]'); | ||
|
||
email = ""; | ||
result = cleanEmail(email); | ||
t.is(result, ''); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another test should be added for cases where
null
/undefined
or a non-string object are used for non-typescript clientsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!