From b9947b53596317effe3e3bd1e5acb9a79cb92a9e Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Mon, 14 Oct 2019 17:11:55 +0800 Subject: [PATCH] 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 --- README.md | 7 +++++++ src/IntercomCompanies.php | 25 +++++++++++++++++++++++++ test/IntercomCompaniesTest.php | 16 ++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/README.md b/README.md index edec005..1f3da91 100644 --- a/README.md +++ b/README.md @@ -304,6 +304,13 @@ $client->companies->getCompanies([]); /** Get a company by ID */ $client->companies->getCompany("531ee472cce572a6ec000006"); + +/** List users belonging to a company by ID */ +$client->companies->getCompanyUsers("531ee472cce572a6ec000006"); + +/** List users belonging to a company by company_id */ +$client->companies->getCompanies(["type" => "user", "company_id" => "3"]); + ``` ## Admins diff --git a/src/IntercomCompanies.php b/src/IntercomCompanies.php index 6230a97..72524e7 100644 --- a/src/IntercomCompanies.php +++ b/src/IntercomCompanies.php @@ -77,6 +77,22 @@ public function getCompany($id, $options = []) return $this->client->get($path, $options); } + + /** + * Returns a list of Users belonging to a single Company based on the Intercom ID. + * + * @see https://developers.intercom.com/reference#list-company-users + * @param string $id + * @param array $options + * @return stdClass + * @throws Exception + */ + public function getCompanyUsers($id, $options = []) + { + $path = $this->companyUsersPath($id); + return $this->client->get($path, $options); + } + /** * @param string $id * @return string @@ -85,4 +101,13 @@ public function companyPath($id) { return 'companies/' . $id; } + + /** + * @param string $id + * @return string + */ + public function companyUsersPath($id) + { + return 'companies/' . $id . '/users'; + } } diff --git a/test/IntercomCompaniesTest.php b/test/IntercomCompaniesTest.php index 01eaa6a..17ce83a 100644 --- a/test/IntercomCompaniesTest.php +++ b/test/IntercomCompaniesTest.php @@ -49,4 +49,20 @@ public function testCompanyGetById() $users = new IntercomCompanies($stub); $this->assertEquals('foo', $users->getCompany("foo")); } + + public function testCompanyGetUsers() + { + $stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock(); + $stub->method('get')->willReturn('foo'); + + $companies = new IntercomCompanies($stub); + $this->assertEquals('foo', $companies->getCompanyUsers("foo")); + } + + public function testCompanyUsersPath() + { + $stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock(); + $users = new IntercomCompanies($stub); + $this->assertEquals('companies/foo/users', $users->companyUsersPath("foo")); + } }