-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Restful TagService * Cannot where() and find() traits Restful TagService doesn't seem to work with where and find.
- Loading branch information
1 parent
5d84293
commit 56c1c00
Showing
4 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.' | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters