From ad4d06df1ed17e8a42477bb064ef634b1cc794ff Mon Sep 17 00:00:00 2001 From: Nicolas Sorice Date: Wed, 23 Jun 2021 12:53:45 -0300 Subject: [PATCH 1/2] Add support for deleting secondary email addresses --- src/Resources/Contacts.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/Resources/Contacts.php b/src/Resources/Contacts.php index f881ffd6..a0445ac7 100644 --- a/src/Resources/Contacts.php +++ b/src/Resources/Contacts.php @@ -423,6 +423,25 @@ 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 + ); + } + /** * Get Lifecycle Stage metrics for Contacts. * From a2c2b916195573e2c8897a236ef168a9ffaf3e5c Mon Sep 17 00:00:00 2001 From: Nicolas Sorice Date: Wed, 23 Jun 2021 15:12:36 -0300 Subject: [PATCH 2/2] Adding addSecondaryEmail method and tests --- src/Resources/Contacts.php | 19 ++++++++++++++++ tests/Integration/Resources/ContactsTest.php | 23 ++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/src/Resources/Contacts.php b/src/Resources/Contacts.php index a0445ac7..c241abff 100644 --- a/src/Resources/Contacts.php +++ b/src/Resources/Contacts.php @@ -442,6 +442,25 @@ public function deleteSecondaryEmail($id, $emailToDelete) ); } + /** + * @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. * diff --git a/tests/Integration/Resources/ContactsTest.php b/tests/Integration/Resources/ContactsTest.php index 0c3f59f1..68278daa 100644 --- a/tests/Integration/Resources/ContactsTest.php +++ b/tests/Integration/Resources/ContactsTest.php @@ -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() {