Skip to content

Commit

Permalink
Merge pull request #279 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 507b621 + 6a320d7 commit 5a0ea34
Show file tree
Hide file tree
Showing 3 changed files with 202 additions and 150 deletions.
1 change: 1 addition & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* @method \SevenShores\Hubspot\Resources\ContactProperties contactProperties()
* @method \SevenShores\Hubspot\Resources\Contacts contacts()
* @method \SevenShores\Hubspot\Resources\CrmAssociations crmAssociations()
* @method \SevenShores\Hubspot\Resources\CrmPipelines crmPipelines()
* @method \SevenShores\Hubspot\Resources\Email email()
* @method \SevenShores\Hubspot\Resources\EmailEvents emailEvents()
* @method \SevenShores\Hubspot\Resources\Engagements engagements()
Expand Down
181 changes: 132 additions & 49 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($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($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 string $email
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode',
* 'showListMemberships']
Expand All @@ -228,9 +271,12 @@ public function getByEmail($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 @@ -253,12 +299,17 @@ public function getBatchByEmails($emails, array $params = [])

$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 string $utk
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode',
* 'showListMemberships']
Expand All @@ -271,9 +322,12 @@ public function getByToken($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 @@ -300,9 +354,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 @@ -327,12 +384,17 @@ public function search($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 @@ -358,8 +420,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 5a0ea34

Please sign in to comment.