Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 53 additions & 4 deletions src/Analytics/Adapter/HubSpot.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -85,6 +85,24 @@ public function contactExists(string $email): bool|int
}
}

/**
* Get Contact
*/
public function getContact(string $contactId)
{
try {
$result = $this->call('GET', '/crm/v3/objects/contacts/'.$contactId, [
'Content-Type' => 'application/json',
]);

return json_decode($result, true);
} catch (\Exception $e) {
$this->logError($e);

return false;
}
}

/**
* Create a contact
*/
Expand DownExpand Up@@ -164,6 +182,26 @@ public function deleteContact(string $email): bool
}
}

/**
* Get Property
*/
public function getContactProperty(string $contactId, string $property)
{
try {
$result = $this->call('GET', '/crm/v3/objects/contacts/'.$contactId.'?properties='.urlencode($property), [
'Content-Type' => 'application/json',
]);

$data = json_decode($result, true);

return $data['properties'][$property] ?? [];
} catch (\Exception $e) {
$this->logError($e);

return false;
}
}

/**
* Account Exists
*/
Expand DownExpand Up@@ -224,15 +262,26 @@ public function createAccount(string $name, string $url = ''): bool
/**
* Update an account
*/
public function updateAccount(string $accountId, string $name, string $url = '', int $ownerId = 1, array $fields = []): bool
public function updateAccount(string $accountId, string $name= '', string $url = '', array $fields = []): bool
{
$body = [
'name' => $name,
'domain' => $url,
'properties' => [],
];

if ($name) {
$body['name'] = $name;
}

if ($url) {
$body['domain'] = $url;
}

foreach ($fields as $key => $value) {
$body['properties'][$key] = $value;
}

try {
$this->call('PATCH', '/crm/v3/objects/companies/'.$accountId, [
$this->call('PATCH', '/crm/v3/objects/contacts/'.$accountId, [
'Content-Type' => 'application/json',
], $body);

Expand Down
3 changes: 1 addition & 2 deletions tests/Analytics/AnalyticsTest.php
Original file line numberDiff line numberDiff line change
Expand Up@@ -191,8 +191,7 @@ public function testHubSpotUpdateAccount($data)
$this->assertTrue($this->hs->updateAccount(
$data['accountID'],
'Utopia',
'utopia.com',
1
'utopia.com'
));

return $data;
Expand Down