Skip to content

Commit

Permalink
Add support for listing users of a company (Fixes: #285) (#287)
Browse files Browse the repository at this point in the history
* Add support for listing users of a company

* Remove unneeded method and add to readme

* Remove unneeded test
  • Loading branch information
Timothy Lim authored and GabrielAnca committed Oct 14, 2019
1 parent ceb9067 commit b9947b5
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/IntercomCompanies.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -85,4 +101,13 @@ public function companyPath($id)
{
return 'companies/' . $id;
}

/**
* @param string $id
* @return string
*/
public function companyUsersPath($id)
{
return 'companies/' . $id . '/users';
}
}
16 changes: 16 additions & 0 deletions test/IntercomCompaniesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}

0 comments on commit b9947b5

Please sign in to comment.