Skip to content

add data attributes endpoints #347

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 6 additions & 0 deletions src/IntercomClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ class IntercomClient
*/
public $teams;

/**
* @var IntercomDataAttribute $dataAttribute
*/
public $dataAttribute;

/**
* @var array $rateLimitDetails
*/
Expand Down Expand Up @@ -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;
Expand Down
66 changes: 66 additions & 0 deletions src/IntercomDataAttribute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Intercom;

use stdClass;
use Http\Client\Exception;

class IntercomDataAttribute extends IntercomResource
{
/**
* Creates Data Attribute.
*
* @see https://developers.intercom.com/intercom-api-reference/reference#create-data-attributes
*
* @param array $options
*
* @return stdClass
* @throws Exception
*/
public function create(array $options)
{
return $this->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;
}
}
38 changes: 38 additions & 0 deletions tests/IntercomDataAttributeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Intercom\Test;

use Intercom\IntercomDataAttribute;

class IntercomDataAttributeTest extends TestCase
{
public function testDataAttributeCreate()
{
$this->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'));
}
}