Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Closes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
hmschreiner committed Jun 16, 2017
1 parent ecbb192 commit dd7543a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
10 changes: 10 additions & 0 deletions dist/endpoints/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ var Contacts = function Contacts() {
return (0, _errorHandler2.default)(error);
});
},
getContactByEmail: function getContactByEmail(email) {
var parameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};


return api.get('contacts/v1/contact/email/' + email + '/profile', parameters).then(function (response) {
return (0, _responseHandler2.default)(response);
}).catch(function (error) {
return (0, _errorHandler2.default)(error);
});
},
createContact: function createContact(properties) {

var mappedProperties = this.mapProperties(properties);
Expand Down
6 changes: 6 additions & 0 deletions src/endpoints/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ const Contacts = (api = null) => {
.then(response => responseHandler(response))
.catch(error => errorHandler(error))
},
getContactByEmail(email, parameters = {}) {

return api.get(`contacts/v1/contact/email/${email}/profile`, parameters)
.then(response => responseHandler(response))
.catch(error => errorHandler(error))
},
createContact(properties) {

let mappedProperties = this.mapProperties(properties)
Expand Down
22 changes: 21 additions & 1 deletion test/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ describe('Contacts', () => {

before(() => {

api.contacts.getAll()
api.contacts.getAll({
count: 1,
property: [
'email', 'firstname', 'lastname',
],
})
.then(response => response.data.contacts[0])
.then(contactData => {
testContact = contactData
Expand All @@ -45,6 +50,21 @@ describe('Contacts', () => {
expect(response.data.properties.lastname.value).to.be.equal(lastname.value)
})
})

it('Should return a single contact, by email address', () => {

let { firstname, lastname, email } = testContact.properties

return api.contacts.getContactByEmail(email.value)
.then(response => {
expect(response.status).to.equal(200)
expect(response.data).to.be.a('object')
expect(response.data.vid).to.be.a('number')
expect(response.data.properties.firstname.value).to.be.equal(firstname.value)
expect(response.data.properties.lastname.value).to.be.equal(lastname.value)
expect(response.data.properties.email.value).to.be.equal(email.value)
})
})
})

describe('Create or update a contact', () => {
Expand Down

0 comments on commit dd7543a

Please sign in to comment.