Skip to content
Open
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mediatoolkit/activecampaign-v3-php",
"description": "PHP Wrapper for ActiveCampaign",
"require": {
"guzzlehttp/guzzle": "~6.3"
"guzzlehttp/guzzle": "^6.3"
},
"require-dev": {
"phpunit/phpunit": "^7"
Expand Down
50 changes: 50 additions & 0 deletions src/contacts/Contacts.php → src/Contacts/Contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,54 @@ 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 string $email
* @param array $contactNew
* @return int
*/
public function findOrCreate(string $email, array $contactNew)
{
$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
*/
public function listTags(int $id)
{
$req = $this->client
->getClient()
->get('/api/3/contacts/' . $id . '/contactTags' );

return $req->getBody()->getContents();
}

}
File renamed without changes.
File renamed without changes.
89 changes: 89 additions & 0 deletions src/Tags/Tags.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?php

namespace Mediatoolkit\ActiveCampaign\Tags;

use Mediatoolkit\ActiveCampaign\Resource;

/**
* Class Tags
* @package Mediatoolkit\ActiveCampaign\Tags
* @see https://developers.activecampaign.com/reference#tags
*/
class Tags extends Resource
{

/**
* @param string $name
* @param string $description
* @return string
*/
public function create(string $name, string $description = null)
{
$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 = null) : 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
* @param array $query_params
* @return string
*/
public function listAll(array $query_params = [])
{
$query_params = array_merge($query_params, ['limit' => '20000']);
$req = $this->client
->getClient()
->get('/api/3/tags', [
'query' => $query_params
]);

return $req->getBody()->getContents();
}

}
File renamed without changes.
File renamed without changes.
32 changes: 0 additions & 32 deletions src/tags/Tags.php

This file was deleted.