From 740d8c552de01777e5d0a913b3ef4c1bc2613786 Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 20 May 2020 12:49:35 +0200 Subject: [PATCH 1/9] findemail + listTags --- src/contacts/Contacts.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/contacts/Contacts.php b/src/contacts/Contacts.php index 169ffb8..9111c8f 100644 --- a/src/contacts/Contacts.php +++ b/src/contacts/Contacts.php @@ -323,4 +323,30 @@ public function removeAutomation(int $contactAutomationId) return 200 === $req->getStatusCode(); } + /** + * @param string $email + * @return string + */ + public function findEmail(string $email) + { + $req = $this->client + ->getClient() + ->get('/api/3/contacts/?search=' . $email); + + return $req->getBody()->getContents(); + } + + /** + * @param int $id + * @return string + */ + public function listTags(int $id) + { + $req = $this->client + ->getClient() + ->get('/api/3/contacts/' . $id . '/contactTags' ); + + return $req->getBody()->getContents(); + } + } From 7cc395e720b93dae8ec1e60127bbb0353fd37c05 Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 20 May 2020 14:52:28 +0200 Subject: [PATCH 2/9] added find / findOrCreate functions --- src/contacts/Contacts.php | 24 ++++++++++++++++ src/tags/Tags.php | 58 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/src/contacts/Contacts.php b/src/contacts/Contacts.php index 9111c8f..a6d1164 100644 --- a/src/contacts/Contacts.php +++ b/src/contacts/Contacts.php @@ -336,6 +336,30 @@ public function findEmail(string $email) return $req->getBody()->getContents(); } + /** + * @param string $email + * @param array $contactNew + * @return int + */ + public function findOrCreate(string $email, array $contactNew) : int + { + $contact = $this->findEmail($email); + $contact = json_decode($contact); + if ( count($contact->contacts) > 0 ) { + $contactId = $contact->contacts[0]->id; + if ($contactId !== 0) { + return $contactId; + } + } + + $contact = $this->create($contactNew); + $contact = json_decode($contact); + $contactId = $contact->contact->id; + return $contactId; + } + + + /** * @param int $id * @return string diff --git a/src/tags/Tags.php b/src/tags/Tags.php index f8c2312..edae0b5 100644 --- a/src/tags/Tags.php +++ b/src/tags/Tags.php @@ -12,6 +12,62 @@ class Tags extends Resource { + /** + * @param string $name + * @param string $description + * @return string + */ + public function create(string $name, string $description = "") + { + $req = $this->client + ->getClient() + ->post('/api/3/tags', [ + 'json' => [ + 'tag' => [ + 'tag' => $name, + 'description' => $description, + 'tagType' => 'contact', + ] + ] + ]); + + return $req->getBody()->getContents(); + } + + /** + * @param string $name + * @param string $description + * @return int + */ + public function findOrCreate(string $name, string $description = "") : int + { + $tagId = $this->find($name); + if ( $tagId !== 0 ) { + return $tagId; + } + $createdTag = $this->create($name, $description); + $createdTag = json_decode($createdTag); + return $createdTag->tag->id; + } + + /** + * @param string $name + * @return int + */ + public function find(string $name) : int + { + $allTags = $this->listAll(); + $allTags = json_decode($allTags); + $allTags = $allTags->tags; + + foreach($allTags as $tag) { + if (0 === strcasecmp($tag->tag, $name)) { + return $tag->id; + } + } + return 0; + } + /** * List all tags * @see https://developers.activecampaign.com/reference#retrieve-all-tags @@ -29,4 +85,4 @@ public function listAll(array $query_params = []) return $req->getBody()->getContents(); } -} \ No newline at end of file +} From 92a4a48805ddfbdf55db1727c676ddad90e43a92 Mon Sep 17 00:00:00 2001 From: rob Date: Mon, 25 May 2020 10:55:16 +0200 Subject: [PATCH 3/9] fix typehinting --- src/contacts/Contacts.php | 2 +- src/tags/Tags.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/contacts/Contacts.php b/src/contacts/Contacts.php index a6d1164..bf730ac 100644 --- a/src/contacts/Contacts.php +++ b/src/contacts/Contacts.php @@ -341,7 +341,7 @@ public function findEmail(string $email) * @param array $contactNew * @return int */ - public function findOrCreate(string $email, array $contactNew) : int + public function findOrCreate(string $email, array $contactNew) { $contact = $this->findEmail($email); $contact = json_decode($contact); diff --git a/src/tags/Tags.php b/src/tags/Tags.php index edae0b5..cc16404 100644 --- a/src/tags/Tags.php +++ b/src/tags/Tags.php @@ -17,7 +17,7 @@ class Tags extends Resource * @param string $description * @return string */ - public function create(string $name, string $description = "") + public function create(string $name, string $description = null) { $req = $this->client ->getClient() @@ -39,7 +39,7 @@ public function create(string $name, string $description = "") * @param string $description * @return int */ - public function findOrCreate(string $name, string $description = "") : int + public function findOrCreate(string $name, string $description = null) : int { $tagId = $this->find($name); if ( $tagId !== 0 ) { From cee77a18a23468b672966b98645dc92ca2bb575f Mon Sep 17 00:00:00 2001 From: rob Date: Mon, 25 May 2020 12:56:44 +0200 Subject: [PATCH 4/9] list all more than 20 --- src/tags/Tags.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tags/Tags.php b/src/tags/Tags.php index cc16404..dfb4e10 100644 --- a/src/tags/Tags.php +++ b/src/tags/Tags.php @@ -76,6 +76,7 @@ public function find(string $name) : int */ public function listAll(array $query_params = []) { + $query_params = array_merge($query_params, ['limit' => '20000']); $req = $this->client ->getClient() ->get('/api/3/tags', [ From 080a90a303a5ceb67e5d5da6d438ed713a380a7f Mon Sep 17 00:00:00 2001 From: rob Date: Mon, 7 Dec 2020 12:00:01 +0100 Subject: [PATCH 5/9] Renamed namespaces --- src/{contacts => Contacts}/Contacts.php | 0 src/{deals => Deals}/Deals.php | 0 src/{lists => Lists}/Lists.php | 0 src/{organizations => Organizations}/Organizations.php | 0 src/{tags => Tags}/Tags.php | 0 src/{tracking => Tracking}/EventTracking.php | 0 src/{tracking => Tracking}/SiteTracking.php | 0 7 files changed, 0 insertions(+), 0 deletions(-) rename src/{contacts => Contacts}/Contacts.php (100%) rename src/{deals => Deals}/Deals.php (100%) rename src/{lists => Lists}/Lists.php (100%) rename src/{organizations => Organizations}/Organizations.php (100%) rename src/{tags => Tags}/Tags.php (100%) rename src/{tracking => Tracking}/EventTracking.php (100%) rename src/{tracking => Tracking}/SiteTracking.php (100%) diff --git a/src/contacts/Contacts.php b/src/Contacts/Contacts.php similarity index 100% rename from src/contacts/Contacts.php rename to src/Contacts/Contacts.php diff --git a/src/deals/Deals.php b/src/Deals/Deals.php similarity index 100% rename from src/deals/Deals.php rename to src/Deals/Deals.php diff --git a/src/lists/Lists.php b/src/Lists/Lists.php similarity index 100% rename from src/lists/Lists.php rename to src/Lists/Lists.php diff --git a/src/organizations/Organizations.php b/src/Organizations/Organizations.php similarity index 100% rename from src/organizations/Organizations.php rename to src/Organizations/Organizations.php diff --git a/src/tags/Tags.php b/src/Tags/Tags.php similarity index 100% rename from src/tags/Tags.php rename to src/Tags/Tags.php diff --git a/src/tracking/EventTracking.php b/src/Tracking/EventTracking.php similarity index 100% rename from src/tracking/EventTracking.php rename to src/Tracking/EventTracking.php diff --git a/src/tracking/SiteTracking.php b/src/Tracking/SiteTracking.php similarity index 100% rename from src/tracking/SiteTracking.php rename to src/Tracking/SiteTracking.php From 60c9ecffbae6d54e83ee560a50a7a7540eeafff2 Mon Sep 17 00:00:00 2001 From: rob Date: Mon, 7 Dec 2020 13:36:14 +0100 Subject: [PATCH 6/9] trigger psr-4 violation to debug composer autload --- src/{Contacts => contacts}/Contacts.php | 2 +- tests/contacts/ContactsTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/{Contacts => contacts}/Contacts.php (99%) diff --git a/src/Contacts/Contacts.php b/src/contacts/Contacts.php similarity index 99% rename from src/Contacts/Contacts.php rename to src/contacts/Contacts.php index bf730ac..f3011dc 100644 --- a/src/Contacts/Contacts.php +++ b/src/contacts/Contacts.php @@ -1,6 +1,6 @@ Date: Mon, 7 Dec 2020 13:58:43 +0100 Subject: [PATCH 7/9] removed psr-4 violation --- src/{contacts => Contacts}/Contacts.php | 2 +- tests/contacts/ContactsTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename src/{contacts => Contacts}/Contacts.php (99%) diff --git a/src/contacts/Contacts.php b/src/Contacts/Contacts.php similarity index 99% rename from src/contacts/Contacts.php rename to src/Contacts/Contacts.php index f3011dc..bf730ac 100644 --- a/src/contacts/Contacts.php +++ b/src/Contacts/Contacts.php @@ -1,6 +1,6 @@ Date: Mon, 4 Jan 2021 10:54:34 +0100 Subject: [PATCH 8/9] upgrade to guzzle 7.2 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index cb129f4..a4e017f 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "mediatoolkit/activecampaign-v3-php", "description": "PHP Wrapper for ActiveCampaign", "require": { - "guzzlehttp/guzzle": "~6.3" + "guzzlehttp/guzzle": "^7.2" }, "require-dev": { "phpunit/phpunit": "^7" From f7b2f10822184d7af30e7c3ba1541eca4e3b0cd7 Mon Sep 17 00:00:00 2001 From: rob Date: Mon, 4 Jan 2021 10:57:23 +0100 Subject: [PATCH 9/9] downgrade guzzle --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index a4e017f..e177f18 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "mediatoolkit/activecampaign-v3-php", "description": "PHP Wrapper for ActiveCampaign", "require": { - "guzzlehttp/guzzle": "^7.2" + "guzzlehttp/guzzle": "^6.3" }, "require-dev": { "phpunit/phpunit": "^7"