Skip to content

Commit

Permalink
Merge pull request #351 from Braintly/feature/delete-secondary-emails
Browse files Browse the repository at this point in the history
Add support for adding/deleting secondary email addresses API
  • Loading branch information
ksvirkou-hubspot authored Jun 30, 2021
2 parents f414cf1 + a2c2b91 commit 3d8a3bd
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/Resources/Contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,44 @@ public function merge($id, $vidToMerge)
);
}

/**
* @param int $id
* @param string $emailToDelete
* @return \SevenShores\Hubspot\Http\Response
*
* @see https://legacydocs.hubspot.com/docs/methods/contacts/delete-a-secondary-email-address
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function deleteSecondaryEmail($id, $emailToDelete)
{
$endpoint = "https://api.hubapi.com/contacts/v1/secondary-email/{$id}/email/{$emailToDelete}";

return $this->client->request(
'delete',
$endpoint
);
}

/**
* @param int $id
* @param string $emailToAdd
* @return \SevenShores\Hubspot\Http\Response
*
* @see https://legacydocs.hubspot.com/docs/methods/contacts/add-a-secondary-email-address
*
* @return \SevenShores\Hubspot\Http\Response
*/
public function addSecondaryEmail($id, $emailToAdd)
{
$endpoint = "https://api.hubapi.com/contacts/v1/secondary-email/{$id}/email/{$emailToAdd}";

return $this->client->request(
'put',
$endpoint
);
}

/**
* Get Lifecycle Stage metrics for Contacts.
*
Expand Down
23 changes: 23 additions & 0 deletions tests/Integration/Resources/ContactsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,29 @@ public function statistics()
$this->assertEquals(200, $response->getStatusCode());
}

/** @test */
public function addSecondaryEmail()
{
$secondaryEmail = 'rw_test'.uniqid().'@hubspot.com';

$response = $this->resource->addSecondaryEmail($this->entity->vid, $secondaryEmail);
$this->assertEquals(200, $response->getStatusCode());
}

/** @test */
public function deleteSecondaryEmail()
{
$secondaryEmail = 'rw_test'.uniqid().'@hubspot.com';

$response = $this->resource->addSecondaryEmail($this->entity->vid, $secondaryEmail);
$this->assertEquals(200, $response->getStatusCode());

sleep(1);

$response = $this->resource->deleteSecondaryEmail($this->entity->vid, $secondaryEmail);
$this->assertEquals(200, $response->getStatusCode());
}

/** @test */
public function getLifecycleStageMetrics()
{
Expand Down

0 comments on commit 3d8a3bd

Please sign in to comment.