Skip to content

Commit

Permalink
Tag service (#145)
Browse files Browse the repository at this point in the history
* Added Restful TagService

* Cannot where() and find() traits

Restful TagService doesn't seem to work with where and find.
  • Loading branch information
toddstoker authored and MicFai committed Sep 14, 2017
1 parent 5d84293 commit 56c1c00
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/Infusionsoft/Api/Rest/TagService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php namespace Infusionsoft\Api\Rest;

use Infusionsoft\Api\Rest\Traits\CannotCreate;
use Infusionsoft\Api\Rest\Traits\CannotDelete;
use Infusionsoft\Api\Rest\Traits\CannotFind;
use Infusionsoft\Api\Rest\Traits\CannotSave;
use Infusionsoft\Api\Rest\Traits\CannotSync;
use Infusionsoft\Api\Rest\Traits\CannotWhere;
use Infusionsoft\Infusionsoft;
use Infusionsoft\InfusionsoftException;

class TagService extends RestModel
{
use CannotSync;
use CannotCreate;
use CannotSave;
use CannotDelete;
use CannotFind;
use CannotWhere;

public $full_url = 'https://api.infusionsoft.com/crm/rest/v1/tags';

public $return_key = 'tags';

public function __construct(Infusionsoft $client)
{
parent::__construct($client);
}

public function contacts()
{
$data = $this->client->restfulRequest('get', $this->getFullUrl($this->id . '/contacts'));
$this->fill($data);

return $this;
}

public function removeContacts($contactIds)
{
if (!is_array($contactIds)) {
throw new InfusionsoftException('Must be an array of contact ids');
} elseif (count($contactIds) > 100) {
throw new InfusionsoftException('A maximum of 100 contact ids can be modified at once');
}

$contactIds = ['ids' => implode(",", $contactIds)];

$response = $this->client->restfulRequest('delete', $this->getFullUrl($this->id . '/contacts'), $contactIds);

return $response;
}

public function addContacts($contactIds)
{
if (!is_array($contactIds)) {
throw new InfusionsoftException('Must be an array of contact ids');
} elseif (count($contactIds) > 100) {
throw new InfusionsoftException('A maximum of 100 contact ids can be modified at once');
}

$contacts = new \stdClass();
$contacts->ids = $contactIds;

$response = $this->client->restfulRequest('post', $this->getFullUrl($this->id . '/contacts'), $contacts);

return $response;
}

}
13 changes: 13 additions & 0 deletions src/Infusionsoft/Api/Rest/Traits/CannotFind.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php namespace Infusionsoft\Api\Rest\Traits;

use Infusionsoft\InfusionsoftException;

trait CannotFind {

public function find() {
throw new InfusionsoftException(
__CLASS__.' cannot use '.__FUNCTION__.' function.'
);
}

}
13 changes: 13 additions & 0 deletions src/Infusionsoft/Api/Rest/Traits/CannotWhere.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php namespace Infusionsoft\Api\Rest\Traits;

use Infusionsoft\InfusionsoftException;

trait CannotWhere {

public function where() {
throw new InfusionsoftException(
__CLASS__.' cannot use '.__FUNCTION__.' function.'
);
}

}
9 changes: 9 additions & 0 deletions src/Infusionsoft/Infusionsoft.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ public function __get($name)
'orders',
'products',
'search',
'tags',
'shipping',
'webForms',
'webTracking'
Expand Down Expand Up @@ -705,6 +706,14 @@ public function customfields()
return $this->getRestApi('CustomFieldService');
}

/**
* @return \Infusionsoft\Api\Rest\TagService
*/
public function tags()
{
return $this->getRestApi('TagService');
}

/**
* @return \Infusionsoft\Api\Rest\TransactionService
*/
Expand Down

0 comments on commit 56c1c00

Please sign in to comment.