Skip to content

Commit

Permalink
Merge pull request #304 from HubSpot/bugfix/companiesContactsTests
Browse files Browse the repository at this point in the history
rewrite companis + add sleep
  • Loading branch information
ksvirkou-hubspot authored Mar 16, 2020
2 parents 99d4c71 + c609699 commit bb18cac
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 185 deletions.
88 changes: 56 additions & 32 deletions src/Resources/Companies.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace SevenShores\Hubspot\Resources;

/**
* @see https://developers.hubspot.com/docs/methods/companies/companies-overview
*/
class Companies extends Resource
{
/**
Expand All @@ -16,9 +19,12 @@ class Companies extends Resource
public function create(array $properties)
{
$endpoint = 'https://api.hubapi.com/companies/v2/companies/';
$options['json'] = ['properties' => $properties];

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

/**
Expand All @@ -34,9 +40,12 @@ public function create(array $properties)
public function update($id, array $properties)
{
$endpoint = "https://api.hubapi.com/companies/v2/companies/{$id}";
$options['json'] = ['properties' => $properties];

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

/**
Expand All @@ -47,9 +56,8 @@ public function update($id, array $properties)
public function updateBatch(array $companies)
{
$endpoint = 'https://api.hubapi.com/companies/v1/batch-async/update';
$options['json'] = $companies;

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

/**
Expand Down Expand Up @@ -81,9 +89,12 @@ public function all(array $params = [])
{
$endpoint = 'https://api.hubapi.com/companies/v2/companies/paged';

$queryString = build_query_string($params);

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

/**
Expand All @@ -99,9 +110,12 @@ public function getRecentlyModified(array $params = [])
{
$endpoint = 'https://api.hubapi.com/companies/v2/companies/recent/modified';

$queryString = build_query_string($params);

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

/**
Expand All @@ -117,35 +131,45 @@ public function getRecentlyCreated(array $params = [])
{
$endpoint = 'https://api.hubapi.com/companies/v2/companies/recent/created';

$queryString = build_query_string($params);

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

/**
* @param string $domain
* @param int $limit
* @param int $offset
* Search for companies by domain.
*
* @see https://developers.hubspot.com/docs/methods/companies/search_companies_by_domain
*
* @return \Psr\Http\Message\ResponseInterface|\SevenShores\Hubspot\Http\Response
*/
public function searchByDomain($domain, array $properties = [], $limit = 100, $offset = 0)
{
public function searchByDomain(
string $domain,
array $properties = [],
int $limit = 100,
int $offset = 0
) {
$endpoint = "https://api.hubapi.com/companies/v2/domains/{$domain}/companies";
$options['json'] = [
'limit' => $limit,
'offset' => [
'isPrimary' => true,
'companyId' => $offset,
],
'requestOptions' => [
'properties' => $properties,
],
];

return $this->client->request('post', $endpoint, $options);

return $this->client->request(
'post',
$endpoint,
[
'json' => [
'limit' => $limit,
'offset' => [
'isPrimary' => true,
'companyId' => $offset,
],
'requestOptions' => [
'properties' => $properties,
],
],
]
);
}

/**
Expand Down
62 changes: 31 additions & 31 deletions src/Resources/Contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class Contacts extends Resource
*
* @param array $properties array of contact properties
*
* @return \SevenShores\Hubspot\Http\Response
*
* @see https://developers.hubspot.com/docs/methods/contacts/create_contact
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function create(array $properties)
{
Expand All @@ -33,9 +33,9 @@ public function create(array $properties)
* @param int $id the contact id
* @param array $properties the contact properties to update
*
* @return \SevenShores\Hubspot\Http\Response
*
* @see https://developers.hubspot.com/docs/methods/contacts/update_contact
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function update($id, array $properties)
{
Expand All @@ -54,9 +54,9 @@ public function update($id, array $properties)
* @param string $email the contact's email address
* @param array $properties the contact properties to update
*
* @return \SevenShores\Hubspot\Http\Response
*
* @see https://developers.hubspot.com/docs/methods/contacts/update_contact-by-email
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function updateByEmail(string $email, array $properties)
{
Expand All @@ -75,9 +75,9 @@ public function updateByEmail(string $email, array $properties)
* @param string $email the contact's email address
* @param array $properties the contact properties
*
* @return \SevenShores\Hubspot\Http\Response
*
* @see https://developers.hubspot.com/docs/methods/contacts/create_or_update
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function createOrUpdate(string $email, array $properties = [])
{
Expand All @@ -96,9 +96,9 @@ public function createOrUpdate(string $email, array $properties = [])
* @param array $contacts the contacts and properties
* @param array $params Array of optional parameters ['auditId']
*
* @return \SevenShores\Hubspot\Http\Response
*
* @see https://developers.hubspot.com/docs/methods/contacts/batch_create_or_update
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function createOrUpdateBatch(array $contacts, array $params = [])
{
Expand All @@ -117,9 +117,9 @@ public function createOrUpdateBatch(array $contacts, array $params = [])
*
* @param int $id
*
* @return \SevenShores\Hubspot\Http\Response
*
* @see https://developers.hubspot.com/docs/methods/contacts/delete_contact
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function delete($id)
{
Expand Down Expand Up @@ -161,11 +161,11 @@ public function all(array $params = [])
* A paginated list of contacts will be returned to you, with a maximum of 100 contacts per page, as specified by
* the "count" parameter. The endpoint only scrolls back in time 30 days.
*
* @see https://developers.hubspot.com/docs/methods/contacts/get_recently_updated_contacts
*
* @param array $params Array of optional parameters ['count', 'timeOffset', 'vidOffset', 'property',
* 'propertyMode', 'formSubmissionMode', 'showListMemberships']
*
* @see https://developers.hubspot.com/docs/methods/contacts/get_recently_updated_contacts
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function recent(array $params = [])
Expand All @@ -185,11 +185,11 @@ public function recent(array $params = [])
* A paginated list of contacts will be returned to you, with a maximum of 100 contacts per page, as specified by
* the "count" parameter. The endpoint only scrolls back in time 30 days.
*
* @see https://developers.hubspot.com/docs/methods/contacts/get_recently_updated_contacts
*
* @param array $params Array of optional parameters ['count', 'timeOffset', 'vidOffset', 'property',
* 'propertyMode', 'formSubmissionMode', 'showListMemberships']
*
* @see https://developers.hubspot.com/docs/methods/contacts/get_recently_updated_contacts
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function recentNew(array $params = [])
Expand All @@ -211,9 +211,9 @@ public function recentNew(array $params = [])
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode',
* 'showListMemberships']
*
* @return \SevenShores\Hubspot\Http\Response
*
* @see https://developers.hubspot.com/docs/methods/contacts/get_contact
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getById($id, array $params = [])
{
Expand All @@ -234,12 +234,12 @@ public function getById($id, array $params = [])
* This method will also return you much of the HubSpot lead "intelligence" for each requested contact record. The
* endpoint accepts many query parameters that allow for customization based on a variety of integration use cases.
*
* @see https://developers.hubspot.com/docs/methods/contacts/get_batch_by_vid
*
* @param array $vids Array of visitor IDs
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode',
* 'showListMemberships', 'includeDeletes']
*
* @see https://developers.hubspot.com/docs/methods/contacts/get_batch_by_vid
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getBatchByIds(array $vids, array $params = [])
Expand All @@ -262,9 +262,9 @@ public function getBatchByIds(array $vids, array $params = [])
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode',
* 'showListMemberships']
*
* @return \SevenShores\Hubspot\Http\Response
*
* @see https://developers.hubspot.com/docs/methods/contacts/get_contact_by_email
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getByEmail(string $email, array $params = [])
{
Expand All @@ -284,15 +284,15 @@ public function getByEmail(string $email, array $params = [])
* This method will also return you much of the HubSpot lead "intelligence" for each requested contact record. The
* endpoint accepts many query parameters that allow for customization based on a variety of integration use cases.
*
* @see https://developers.hubspot.com/docs/methods/contacts/get_batch_by_email
*
* @param array $emails Array of email adresses
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode',
* 'showListMemberships', 'includeDeletes']
*
* @see https://developers.hubspot.com/docs/methods/contacts/get_batch_by_email
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getBatchByEmails($emails, array $params = [])
public function getBatchByEmails(array $emails, array $params = [])
{
$endpoint = 'https://api.hubapi.com/contacts/v1/contact/emails/batch/';

Expand All @@ -312,9 +312,9 @@ public function getBatchByEmails($emails, array $params = [])
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode',
* 'showListMemberships']
*
* @return \SevenShores\Hubspot\Http\Response
*
* @see https://developers.hubspot.com/docs/methods/contacts/get_contact_by_utk
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getByToken(string $utk, array $params = [])
{
Expand All @@ -338,12 +338,12 @@ public function getByToken(string $utk, array $params = [])
* The endpoint does not allow for CORS, so if you are looking up contacts from their user token on the client,
* you'll need to spin up a proxy server to interact with the API.
*
* @see https://developers.hubspot.com/docs/methods/contacts/get_batch_by_utk
*
* @param array $utks Array of hubspot user tokens (hubspotutk)
* @param array $params Array of optional parameters ['property', 'propertyMode', 'formSubmissionMode',
* 'showListMemberships', 'includeDeletes']
*
* @see https://developers.hubspot.com/docs/methods/contacts/get_batch_by_utk
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function getBatchByTokens(array $utks, array $params = [])
Expand Down Expand Up @@ -408,9 +408,9 @@ public function statistics()
* @param int $id primary contact id
* @param int $vidToMerge contact ID of the secondary contact
*
* @return \SevenShores\Hubspot\Http\Response
*
* @see https://developers.hubspot.com/docs/methods/contacts/merge-contacts
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function merge($id, $vidToMerge)
{
Expand Down
7 changes: 6 additions & 1 deletion tests/Integration/Abstraction/DefaultTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ public function setUp()
parent::setUp();

if (empty($this->resource)) {
$this->resource = new $this->resourceClass(new Client(['key' => getenv($this->key)]));
$this->resource = new $this->resourceClass($this->getClient());
}
sleep(1);
}

protected function getClient(): Client
{
return new Client(['key' => getenv($this->key)]);
}
}
Loading

0 comments on commit bb18cac

Please sign in to comment.