diff --git a/README.md b/README.md index 3fd8ad3..a0074bb 100644 --- a/README.md +++ b/README.md @@ -554,6 +554,39 @@ $client->teams->getTeams(); $client->teams->getTeam('1188'); ``` +## Data Attributes +```php + +// Create a Data Attribute +// See more options here: https://developers.intercom.com/intercom-api-reference/reference#create-data-attributes +$client->dataAttribute->create([ + 'name' => 'list_cda', + 'description' => 'You are either alive or dead', + 'data_type' => 'string', + 'model' => 'contact', + 'options' => [ + (object)['value' => 'alive'], + (object)['value' => 'dead'], + ] +]); + +// Update a Data Attribute +// See more options here: https://developers.intercom.com/intercom-api-reference/reference#update-data-attributes +$client->dataAttribute->update('123', [ + 'description' => 'Here is a new description' +]); + +// List all Data Attributes +// See more options here: https://developers.intercom.com/intercom-api-reference/reference#list-data-attributes +$client->dataAttribute->getDataAttributes(); + +// List all Data Attributes for specific model type +$client->dataAttribute->getDataAttributes([ + 'model' => 'contact' +]); + +``` + ## Rate Limits Rate limit info is passed via the rate limit headers. diff --git a/src/IntercomClient.php b/src/IntercomClient.php index 076f9ed..8531d39 100644 --- a/src/IntercomClient.php +++ b/src/IntercomClient.php @@ -128,6 +128,11 @@ class IntercomClient */ public $teams; + /** + * @var IntercomDataAttribute $dataAttribute + */ + public $dataAttribute; + /** * @var array $rateLimitDetails */ @@ -157,6 +162,7 @@ public function __construct(string $appIdOrToken, string $password = null, array $this->bulk = new IntercomBulk($this); $this->notes = new IntercomNotes($this); $this->teams = new IntercomTeams($this); + $this->dataAttribute = new IntercomDataAttribute($this); $this->appIdOrToken = $appIdOrToken; $this->passwordPart = $password; diff --git a/src/IntercomDataAttribute.php b/src/IntercomDataAttribute.php new file mode 100644 index 0000000..2214555 --- /dev/null +++ b/src/IntercomDataAttribute.php @@ -0,0 +1,66 @@ +client->post('data_attributes', $options); + } + + /** + * Update a Data Attribute. + * + * @see https://developers.intercom.com/intercom-api-reference/reference#update-data-attributes + * + * @param array $options + * + * @return stdClass + * @throws Exception + */ + public function update(string $id, array $options) + { + $path = $this->dataAttributePath($id); + + return $this->client->put($path, $options); + } + + /** + * Lists Data Attributes. + * + * @see https://developers.intercom.com/intercom-api-reference/reference#list-data-attributes + * + * @param array $options + * + * @return stdClass + * @throws Exception + */ + public function getDataAttributes(array $options = []) + { + return $this->client->get('data_attributes', $options); + } + + /** + * @param string $id + * + * @return string + */ + public function dataAttributePath(string $id) + { + return 'data_attributes/' . $id; + } +} diff --git a/tests/IntercomDataAttributeTest.php b/tests/IntercomDataAttributeTest.php new file mode 100644 index 0000000..a6774fb --- /dev/null +++ b/tests/IntercomDataAttributeTest.php @@ -0,0 +1,38 @@ +client->method('post')->willReturn('foo'); + + $dataAttributes = new IntercomDataAttribute($this->client); + $this->assertSame('foo', $dataAttributes->create([])); + } + + public function testDataAttributeUpdate() + { + $this->client->method('put')->willReturn('foo'); + + $dataAttribute = new IntercomDataAttribute($this->client); + $this->assertSame('foo', $dataAttribute->update('', [])); + } + + public function testDataAttributesGet() + { + $this->client->method('get')->willReturn('foo'); + + $dataAttributes = new IntercomDataAttribute($this->client); + $this->assertSame('foo', $dataAttributes->getDataAttributes([])); + } + + public function testDataAttributesGetPath() + { + $dataAttributes = new IntercomDataAttribute($this->client); + $this->assertSame('data_attributes/1', $dataAttributes->dataAttributePath('1')); + } +}