Skip to content

Commit 2dfc3e0

Browse files
author
Kevin Antoine
authored
Merge pull request #195 from intercom/AK/add-update-methods-for-users-and-leads
Ak/add update methods for users and leads
2 parents 6fa19f1 + 64593d4 commit 2dfc3e0

File tree

5 files changed

+62
-8
lines changed

5 files changed

+62
-8
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,18 @@ If you are building a third party application you can get your OAuth token by [s
4646
## Users
4747

4848
```php
49-
// Create/update a user
49+
// Create a user
5050
$client->users->create([
5151
"email" => "[email protected]",
5252
"custom_attributes" => ['foo' => 'bar']
5353
]);
5454

55+
// Update a user (Note: This method is an alias to the create method. In practice you can use create to update users if you wish)
56+
$client->users->update([
57+
"email" => "[email protected]",
58+
"custom_attributes" => ['foo' => 'bar']
59+
]);
60+
5561
// Delete a user by ID
5662
$client->users->deleteUser("570680a8a1bcbca8a90001b9");
5763

@@ -89,13 +95,19 @@ $client->users->getUsers([]);
8995
## Leads
9096

9197
```php
92-
// Create/update a lead
98+
// Create a lead
9399
// See more options here: https://developers.intercom.io/reference#create-lead
94100
$client->leads->create([
95101
"email" => "[email protected]",
96102
"custom_attributes" => ['foo' => 'bar']
97103
]);
98104

105+
// Update a lead (Note: This method is an alias to the create method. In practice you can use create to update leads if you wish)
106+
$client->leads->update([
107+
"email" => "[email protected]",
108+
"custom_attributes" => ['foo' => 'bar']
109+
]);
110+
99111
// List leads
100112
// See more options here: https://developers.intercom.io/reference#list-leads
101113
$client->leads->getLeads([]);

src/IntercomLeads.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ public function create($options)
2828
return $this->client->post("contacts", $options);
2929
}
3030

31+
/**
32+
* Creates Lead.
33+
* @see https://developers.intercom.io/reference#create-lead
34+
* @param array $options
35+
* @return mixed
36+
* @throws \GuzzleHttp\Exception\GuzzleException
37+
*/
38+
public function update($options)
39+
{
40+
return $this->create($options);
41+
}
42+
3143
/**
3244
* Lists Leads.
3345
* @see https://developers.intercom.io/reference#list-leads

src/IntercomUsers.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ public function create($options)
2828
return $this->client->post("users", $options);
2929
}
3030

31+
/**
32+
* Creates a User.
33+
* @see https://developers.intercom.io/reference#create-or-update-user
34+
* @param array $options
35+
* @return mixed
36+
* @throws \GuzzleHttp\Exception\GuzzleException
37+
*/
38+
public function update($options)
39+
{
40+
return $this->create($options);
41+
}
42+
3143
/**
3244
* Lists Users.
3345
* @see https://developers.intercom.io/reference#list-users
@@ -53,14 +65,14 @@ public function getUser($id, $options = [])
5365
$path = $this->userPath($id);
5466
return $this->client->get($path, $options);
5567
}
56-
68+
5769
/**
5870
* Gets a list of Users through the user scroll API.
5971
* @see https://developers.intercom.com/reference#iterating-over-all-users
6072
* @param array $options
6173
* @return mixed
6274
* @throws \GuzzleHttp\Exception\GuzzleException
63-
*/
75+
*/
6476
public function scrollUsers($options = [])
6577
{
6678
return $this->client->get('users/scroll', $options);

test/IntercomLeadsTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ public function testLeadCreate()
1212
$this->assertEquals('foo', $leads->create([]));
1313
}
1414

15+
public function testLeadUpdate()
16+
{
17+
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
18+
$stub->method('post')->willReturn('foo');
19+
20+
$leads = new IntercomLeads($stub);
21+
$this->assertEquals('foo', $leads->update([]));
22+
}
23+
1524
public function testLeadsList()
1625
{
1726
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();

test/IntercomUsersTest.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,25 @@ public function testUserCreate()
1414
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
1515
$stub->method('post')->willReturn('foo');
1616

17-
$events = new IntercomUsers($stub);
18-
$this->assertEquals('foo', $events->create([]));
17+
$users = new IntercomUsers($stub);
18+
$this->assertEquals('foo', $users->create([]));
19+
}
20+
21+
public function testUserUpdate()
22+
{
23+
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
24+
$stub->method('post')->willReturn('foo');
25+
26+
$users = new IntercomUsers($stub);
27+
$this->assertEquals('foo', $users->update([]));
1928
}
2029

2130
public function testUserGet()
2231
{
2332
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
2433
$stub->method('get')->willReturn('foo');
2534

26-
$events = new IntercomUsers($stub);
27-
$this->assertEquals('foo', $events->getUsers([]));
35+
$users = new IntercomUsers($stub);
36+
$this->assertEquals('foo', $users->getUsers([]));
2837
}
2938
}

0 commit comments

Comments
 (0)