diff --git a/src/Zendesk/API/HttpClient.php b/src/Zendesk/API/HttpClient.php index d38e2e79b..0d8dcfeb0 100644 --- a/src/Zendesk/API/HttpClient.php +++ b/src/Zendesk/API/HttpClient.php @@ -58,6 +58,7 @@ use Zendesk\API\Resources\HelpCenter; use Zendesk\API\Resources\Talk; use Zendesk\API\Resources\Voice; +use Zendesk\API\Resources\Sell; use Zendesk\API\Traits\Utility\InstantiatorTrait; use Zendesk\API\Utilities\Auth; @@ -185,6 +186,11 @@ class HttpClient */ public $talk; + /** + * @var Sell + */ + public $sell; + /** * @param string $subdomain * @param string $username @@ -229,6 +235,7 @@ public function __construct( $this->embeddable = new Embeddable($this); $this->chat = new Chat($this); $this->talk = new Talk($this); + $this->sell = new Sell($this); } /** diff --git a/src/Zendesk/API/Resources/Sell.php b/src/Zendesk/API/Resources/Sell.php new file mode 100644 index 000000000..586e842da --- /dev/null +++ b/src/Zendesk/API/Resources/Sell.php @@ -0,0 +1,42 @@ +client->sell + * + * @method Contacts contacts() + */ +class Sell +{ + use ChainedParametersTrait; + use InstantiatorTrait; + + public $client; + + /** + * Sets the client to be used + * + * @param HttpClient $client + */ + public function __construct(HttpClient $client) + { + $this->client = $client; + } + + /** + * @inheritdoc + * @return array + */ + public static function getValidSubResources() + { + return [ + 'contacts' => Contacts::class, + ]; + } +} diff --git a/src/Zendesk/API/Resources/Sell/Contacts.php b/src/Zendesk/API/Resources/Sell/Contacts.php new file mode 100644 index 000000000..1bf7fcf17 --- /dev/null +++ b/src/Zendesk/API/Resources/Sell/Contacts.php @@ -0,0 +1,62 @@ +setRoutes([ + "find" => "{$this->resourceName}/{id}", + "findAll" => $this->resourceName, + "create" => $this->resourceName, + "update" => "{$this->resourceName}/{id}", + "delete" => "{$this->resourceName}/{id}", + "upsert" => "{$this->resourceName}/upsert", + ]); + } + + /** + * Create a new contact or update an existing, based on a value of a filter or a set of filters + * @param array $params + * @param array $updateResourceFields + * @return \stdClass|null + * @throws \Zendesk\API\Exceptions\ApiResponseException + * @throws \Zendesk\API\Exceptions\AuthException + */ + public function upsert(array $params, array $updateResourceFields) + { + $route = $this->getRoute(__FUNCTION__); + + return $this->client->post( + $route, + [$this->objectName => $updateResourceFields], + ['queryParams' => $params] + ); + } +} diff --git a/src/Zendesk/API/Resources/Sell/ResourceAbstract.php b/src/Zendesk/API/Resources/Sell/ResourceAbstract.php new file mode 100644 index 000000000..928f90006 --- /dev/null +++ b/src/Zendesk/API/Resources/Sell/ResourceAbstract.php @@ -0,0 +1,11 @@ +assertTrue(method_exists($this->client->sell->contacts(), 'create')); + $this->assertTrue(method_exists($this->client->sell->contacts(), 'delete')); + $this->assertTrue(method_exists($this->client->sell->contacts(), 'find')); + $this->assertTrue(method_exists($this->client->sell->contacts(), 'findAll')); + $this->assertTrue(method_exists($this->client->sell->contacts(), 'update')); + $this->assertTrue(method_exists($this->client->sell->contacts(), 'upsert')); + } + + /** + * Tests if the upsert endpoint can be called and passed the correct params + */ + public function testUpsert() + { + $faker = Factory::create(); + + $queryParams = [ + 'email' => $faker->email, + 'phone' => $faker->phoneNumber, + ]; + + $postFields = [ + 'email' => $faker->email, + 'custom_fields' => [ + 'Some Field' => $faker->text + ] + ]; + + $this->assertEndpointCalled(function () use ($queryParams, $postFields) { + $this->client->sell->contacts()->upsert($queryParams, $postFields); + }, '/contacts/upsert', 'POST', [ + 'queryParams' => $queryParams, + 'postFields' => ['data' => $postFields], + 'apiBasePath' => '/v2' + ]); + } +}