Skip to content

Commit

Permalink
Merge pull request #281 from intercom/AP/customer-search
Browse files Browse the repository at this point in the history
Add customer search
  • Loading branch information
apassant authored Jul 31, 2019
2 parents 9329293 + 01d257b commit b9215dd
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ $client->leads->scrollLeads();

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

## Customers

```php
/** Search for customers */
$client->customers->search([
"query" => ['field' => 'name', 'operator' => '=', 'value' => 'Alice'],
"sort" => ["field" => "name", "order" => "ascending"],
"pagination" => ["per_page" => 10]
]);

## Visitors

Retrieve `user_id` of a visitor via [the JavaScript API](https://developers.intercom.com/docs/intercom-javascript#section-intercomgetvisitorid)
Expand Down
6 changes: 6 additions & 0 deletions src/IntercomClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ class IntercomClient
*/
public $users;

/**
* @var IntercomCustomers $customers
*/
public $customers;

/**
* @var IntercomEvents $events
*/
Expand Down Expand Up @@ -131,6 +136,7 @@ class IntercomClient
public function __construct($appIdOrToken, $password = null, $extraRequestHeaders = [])
{
$this->users = new IntercomUsers($this);
$this->customers = new IntercomCustomers($this);
$this->events = new IntercomEvents($this);
$this->companies = new IntercomCompanies($this);
$this->messages = new IntercomMessages($this);
Expand Down
38 changes: 38 additions & 0 deletions src/IntercomCustomers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Intercom;

use Http\Client\Exception;
use stdClass;

class IntercomCustomers
{

/**
* @var IntercomClient
*/
private $client;

/**
* IntercomCustomers constructor.
*
* @param IntercomClient $client
*/
public function __construct($client)
{
$this->client = $client;
}

/**
* Search Customers
*
* @see https://developers.intercom.com/intercom-api-reference/v0/reference#customers
* @param array query
* @return stdClass
* @throws Exception
*/
public function search($query)
{
return $this->client->post('customers/search', $query);
}
}
18 changes: 18 additions & 0 deletions test/IntercomCustomersTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Intercom\Test;

use Intercom\IntercomCustomers;
use PHPUnit\Framework\TestCase;

class IntercomCustomersTest extends TestCase
{
public function testCustomerSearch()
{
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
$stub->method('post')->willReturn('foo');

$customers = new IntercomCustomers($stub);
$this->assertEquals('foo', $customers->search(["query" => []]));
}
}

0 comments on commit b9215dd

Please sign in to comment.