Skip to content

Commit b9947b5

Browse files
Timothy LimGabrielAnca
authored andcommitted
Add support for listing users of a company (Fixes: #285) (#287)
* Add support for listing users of a company * Remove unneeded method and add to readme * Remove unneeded test
1 parent ceb9067 commit b9947b5

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,13 @@ $client->companies->getCompanies([]);
304304

305305
/** Get a company by ID */
306306
$client->companies->getCompany("531ee472cce572a6ec000006");
307+
308+
/** List users belonging to a company by ID */
309+
$client->companies->getCompanyUsers("531ee472cce572a6ec000006");
310+
311+
/** List users belonging to a company by company_id */
312+
$client->companies->getCompanies(["type" => "user", "company_id" => "3"]);
313+
307314
```
308315

309316
## Admins

src/IntercomCompanies.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ public function getCompany($id, $options = [])
7777
return $this->client->get($path, $options);
7878
}
7979

80+
81+
/**
82+
* Returns a list of Users belonging to a single Company based on the Intercom ID.
83+
*
84+
* @see https://developers.intercom.com/reference#list-company-users
85+
* @param string $id
86+
* @param array $options
87+
* @return stdClass
88+
* @throws Exception
89+
*/
90+
public function getCompanyUsers($id, $options = [])
91+
{
92+
$path = $this->companyUsersPath($id);
93+
return $this->client->get($path, $options);
94+
}
95+
8096
/**
8197
* @param string $id
8298
* @return string
@@ -85,4 +101,13 @@ public function companyPath($id)
85101
{
86102
return 'companies/' . $id;
87103
}
104+
105+
/**
106+
* @param string $id
107+
* @return string
108+
*/
109+
public function companyUsersPath($id)
110+
{
111+
return 'companies/' . $id . '/users';
112+
}
88113
}

test/IntercomCompaniesTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,20 @@ public function testCompanyGetById()
4949
$users = new IntercomCompanies($stub);
5050
$this->assertEquals('foo', $users->getCompany("foo"));
5151
}
52+
53+
public function testCompanyGetUsers()
54+
{
55+
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
56+
$stub->method('get')->willReturn('foo');
57+
58+
$companies = new IntercomCompanies($stub);
59+
$this->assertEquals('foo', $companies->getCompanyUsers("foo"));
60+
}
61+
62+
public function testCompanyUsersPath()
63+
{
64+
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
65+
$users = new IntercomCompanies($stub);
66+
$this->assertEquals('companies/foo/users', $users->companyUsersPath("foo"));
67+
}
5268
}

0 commit comments

Comments
 (0)