Skip to content

Commit b9215dd

Browse files
authored
Merge pull request #281 from intercom/AP/customer-search
Add customer search
2 parents 9329293 + 01d257b commit b9215dd

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,16 @@ $client->leads->scrollLeads();
172172

173173
See [here](https://github.com/intercom/intercom-php#scroll) for more info on using the scroll parameter
174174

175+
## Customers
176+
177+
```php
178+
/** Search for customers */
179+
$client->customers->search([
180+
"query" => ['field' => 'name', 'operator' => '=', 'value' => 'Alice'],
181+
"sort" => ["field" => "name", "order" => "ascending"],
182+
"pagination" => ["per_page" => 10]
183+
]);
184+
175185
## Visitors
176186

177187
Retrieve `user_id` of a visitor via [the JavaScript API](https://developers.intercom.com/docs/intercom-javascript#section-intercomgetvisitorid)

src/IntercomClient.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ class IntercomClient
5656
*/
5757
public $users;
5858

59+
/**
60+
* @var IntercomCustomers $customers
61+
*/
62+
public $customers;
63+
5964
/**
6065
* @var IntercomEvents $events
6166
*/
@@ -131,6 +136,7 @@ class IntercomClient
131136
public function __construct($appIdOrToken, $password = null, $extraRequestHeaders = [])
132137
{
133138
$this->users = new IntercomUsers($this);
139+
$this->customers = new IntercomCustomers($this);
134140
$this->events = new IntercomEvents($this);
135141
$this->companies = new IntercomCompanies($this);
136142
$this->messages = new IntercomMessages($this);

src/IntercomCustomers.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Intercom;
4+
5+
use Http\Client\Exception;
6+
use stdClass;
7+
8+
class IntercomCustomers
9+
{
10+
11+
/**
12+
* @var IntercomClient
13+
*/
14+
private $client;
15+
16+
/**
17+
* IntercomCustomers constructor.
18+
*
19+
* @param IntercomClient $client
20+
*/
21+
public function __construct($client)
22+
{
23+
$this->client = $client;
24+
}
25+
26+
/**
27+
* Search Customers
28+
*
29+
* @see https://developers.intercom.com/intercom-api-reference/v0/reference#customers
30+
* @param array query
31+
* @return stdClass
32+
* @throws Exception
33+
*/
34+
public function search($query)
35+
{
36+
return $this->client->post('customers/search', $query);
37+
}
38+
}

test/IntercomCustomersTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Intercom\Test;
4+
5+
use Intercom\IntercomCustomers;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class IntercomCustomersTest extends TestCase
9+
{
10+
public function testCustomerSearch()
11+
{
12+
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
13+
$stub->method('post')->willReturn('foo');
14+
15+
$customers = new IntercomCustomers($stub);
16+
$this->assertEquals('foo', $customers->search(["query" => []]));
17+
}
18+
}

0 commit comments

Comments
 (0)