Skip to content

Commit

Permalink
Merge pull request #280 from HubSpot/review/contactsTest
Browse files Browse the repository at this point in the history
code review of contacts
  • Loading branch information
ksvirkou-hubspot authored Jan 9, 2020
2 parents 910b610 + b530cd6 commit 15604b4
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 151 deletions.
183 changes: 133 additions & 50 deletions src/Resources/Contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

namespace SevenShores\Hubspot\Resources;

/**
* @see https://developers.hubspot.com/docs/methods/contacts/contacts-overview
*/
class Contacts extends Resource
{
/**
* Create a new contact.
*
* @param array $properties array of contact properties
*
* @return \SevenShores\Hubspot\Http\Response
Expand All @@ -15,12 +20,16 @@ public function create(array $properties)
{
$endpoint = 'https://api.hubapi.com/contacts/v1/contact';

$options['json'] = ['properties' => $properties];

return $this->client->request('post', $endpoint, $options);
return $this->client->request(
'post',
$endpoint,
['json' => ['properties' => $properties]]
);
}

/**
* Update an existing contact.
*
* @param int $id the contact id
* @param array $properties the contact properties to update
*
Expand All @@ -32,12 +41,16 @@ public function update($id, array $properties)
{
$endpoint = "https://api.hubapi.com/contacts/v1/contact/vid/{$id}/profile";

$options['json'] = ['properties' => $properties];

return $this->client->request('post', $endpoint, $options);
return $this->client->request(
'post',
$endpoint,
['json' => ['properties' => $properties]]
);
}

/**
* Update an existing contact by email.
*
* @param string $email the contact's email address
* @param array $properties the contact properties to update
*
Expand All @@ -49,12 +62,16 @@ public function updateByEmail(string $email, array $properties)
{
$endpoint = "https://api.hubapi.com/contacts/v1/contact/email/{$email}/profile";

$options['json'] = ['properties' => $properties];

return $this->client->request('post', $endpoint, $options);
return $this->client->request(
'post',
$endpoint,
['json' => ['properties' => $properties]]
);
}

/**
* Create or update a contact.
*
* @param string $email the contact's email address
* @param array $properties the contact properties
*
Expand All @@ -66,12 +83,16 @@ public function createOrUpdate(string $email, array $properties = [])
{
$endpoint = "https://api.hubapi.com/contacts/v1/contact/createOrUpdate/email/{$email}";

$options['json'] = ['properties' => $properties];

return $this->client->request('post', $endpoint, $options);
return $this->client->request(
'post',
$endpoint,
['json' => ['properties' => $properties]]
);
}

/**
* Create or update a group of contacts.
*
* @param array $contacts the contacts and properties
* @param array $params Array of optional parameters ['auditId']
*
Expand All @@ -83,14 +104,17 @@ public function createOrUpdateBatch(array $contacts, array $params = [])
{
$endpoint = 'https://api.hubapi.com/contacts/v1/contact/batch';

$queryString = build_query_string($params);

$options['json'] = $contacts;

return $this->client->request('post', $endpoint, $options, $queryString);
return $this->client->request(
'post',
$endpoint,
['json' => $contacts],
build_query_string($params)
);
}

/**
* Delete a contact.
*
* @param int $id
*
* @return \SevenShores\Hubspot\Http\Response
Expand Down Expand Up @@ -124,9 +148,12 @@ public function all(array $params = [])
{
$endpoint = 'https://api.hubapi.com/contacts/v1/lists/all/contacts/all';

$queryString = build_query_string($params);

return $this->client->request('get', $endpoint, [], $queryString);
return $this->client->request(
'get',
$endpoint,
[],
build_query_string($params)
);
}

/**
Expand All @@ -145,9 +172,12 @@ public function recent(array $params = [])
{
$endpoint = 'https://api.hubapi.com/contacts/v1/lists/recently_updated/contacts/recent';

$queryString = build_query_string($params);

return $this->client->request('get', $endpoint, [], $queryString);
return $this->client->request(
'get',
$endpoint,
[],
build_query_string($params)
);
}

/**
Expand All @@ -166,12 +196,17 @@ public function recentNew(array $params = [])
{
$endpoint = 'https://api.hubapi.com/contacts/v1/lists/all/contacts/recent';

$queryString = build_query_string($params);

return $this->client->request('get', $endpoint, [], $queryString);
return $this->client->request(
'get',
$endpoint,
[],
build_query_string($params)
);
}

/**
* Get a contact by vid(id).
*
* @param int $id
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode',
* 'showListMemberships']
Expand All @@ -184,9 +219,12 @@ public function getById($id, array $params = [])
{
$endpoint = "https://api.hubapi.com/contacts/v1/contact/vid/{$id}/profile";

$queryString = build_query_string($params);

return $this->client->request('get', $endpoint, [], $queryString);
return $this->client->request(
'get',
$endpoint,
[],
build_query_string($params)
);
}

/**
Expand All @@ -210,12 +248,17 @@ public function getBatchByIds(array $vids, array $params = [])

$params['vid'] = $vids;

$queryString = build_query_string($params);

return $this->client->request('get', $endpoint, [], $queryString);
return $this->client->request(
'get',
$endpoint,
[],
build_query_string($params)
);
}

/**
* Get a contact by email address.
*
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode',
* 'showListMemberships']
*
Expand All @@ -227,9 +270,12 @@ public function getByEmail(string $email, array $params = [])
{
$endpoint = "https://api.hubapi.com/contacts/v1/contact/email/{$email}/profile";

$queryString = build_query_string($params);

return $this->client->request('get', $endpoint, [], $queryString);
return $this->client->request(
'get',
$endpoint,
[],
build_query_string($params)
);
}

/**
Expand All @@ -246,18 +292,23 @@ public function getByEmail(string $email, array $params = [])
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getBatchByEmails(array $emails, array $params = [])
public function getBatchByEmails($emails, array $params = [])
{
$endpoint = 'https://api.hubapi.com/contacts/v1/contact/emails/batch/';

$params['email'] = $emails;

$queryString = build_query_string($params);

return $this->client->request('get', $endpoint, [], $queryString);
return $this->client->request(
'get',
$endpoint,
[],
build_query_string($params)
);
}

/**
* Get a contact by its user token.
*
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode',
* 'showListMemberships']
*
Expand All @@ -269,9 +320,12 @@ public function getByToken(string $utk, array $params = [])
{
$endpoint = "https://api.hubapi.com/contacts/v1/contact/utk/{$utk}/profile";

$queryString = build_query_string($params);

return $this->client->request('get', $endpoint, [], $queryString);
return $this->client->request(
'get',
$endpoint,
[],
build_query_string($params)
);
}

/**
Expand All @@ -298,9 +352,12 @@ public function getBatchByTokens(array $utks, array $params = [])

$params['utk'] = $utks;

$queryString = build_query_string($params);

return $this->client->request('get', $endpoint, [], $queryString);
return $this->client->request(
'get',
$endpoint,
[],
build_query_string($params)
);
}

/**
Expand All @@ -325,12 +382,17 @@ public function search(string $query, array $params = [])

$params['q'] = $query;

$queryString = build_query_string($params);

return $this->client->request('get', $endpoint, [], $queryString);
return $this->client->request(
'get',
$endpoint,
[],
build_query_string($params)
);
}

/**
* @deprecated
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function statistics()
Expand All @@ -356,8 +418,29 @@ public function merge($id, $vidToMerge)
{
$endpoint = "https://api.hubapi.com/contacts/v1/contact/merge-vids/{$id}/";

$options['json'] = ['vidToMerge' => $vidToMerge];
return $this->client->request(
'post',
$endpoint,
['json' => ['vidToMerge' => $vidToMerge]]
);
}

/**
* Get Lifecycle Stage metrics for Contacts.
*
* @see https://developers.hubspot.com/docs/methods/contacts/get-lifecycle-stage-metrics-for-contacts
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getLifecycleStageMetrics(array $params = [])
{
$endpoint = 'https://api.hubapi.com/contacts/v1/contacts/statistics';

return $this->client->request('post', $endpoint, $options);
return $this->client->request(
'get',
$endpoint,
[],
build_query_string($params)
);
}
}
Loading

0 comments on commit 15604b4

Please sign in to comment.