Skip to content

Commit ac2ef62

Browse files
Jaspaulchoran
authored andcommitted
Introduces the ability to permanently delete a user (#251)
This change introduces a new `archiveUser` method, and updates the `deleteUser` method to alias it. Additionally the change introduces a new `permanentlyDeleteUser` that leverages a `POST` to `user_delete_requests` to initiate a permanent delete from the intercom api. Addresses: #249
1 parent d436554 commit ac2ef62

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

src/IntercomUsers.php

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,47 @@ public function scrollUsers($options = [])
9090
/**
9191
* Deletes a single User based on the Intercom ID.
9292
*
93-
* @see https://developers.intercom.com/reference#delete-a-user
93+
* @see https://developers.intercom.com/reference#archive-a-user
9494
* @param string $id
9595
* @param array $options
9696
* @return mixed
9797
* @throws \GuzzleHttp\Exception\GuzzleException
9898
*/
99-
public function deleteUser($id, $options = [])
99+
public function archiveUser($id, $options = [])
100100
{
101101
$path = $this->userPath($id);
102102
return $this->client->delete($path, $options);
103103
}
104104

105+
/**
106+
* Deletes a single User based on the Intercom ID.
107+
*
108+
* @see https://developers.intercom.com/reference#archive-a-user
109+
* @param string $id
110+
* @param array $options
111+
* @return mixed
112+
* @throws \GuzzleHttp\Exception\GuzzleException
113+
*/
114+
public function deleteUser($id, $options = [])
115+
{
116+
return $this->archiveUser($id, $options);
117+
}
118+
119+
/**
120+
* Permanently deletes a single User based on the Intercom ID.
121+
*
122+
* @see https://developers.intercom.com/reference#delete-users
123+
* @param string $id
124+
* @return mixed
125+
* @throws \GuzzleHttp\Exception\GuzzleException
126+
*/
127+
public function permanentlyDeleteUser($id)
128+
{
129+
return $this->client->post('user_delete_requests', [
130+
'intercom_user_id' => $id
131+
]);
132+
}
133+
105134
/**
106135
* @param string $id
107136
* @return string

test/IntercomUsersTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,31 @@ public function testUserGet()
3636
$users = new IntercomUsers($stub);
3737
$this->assertEquals('foo', $users->getUsers([]));
3838
}
39+
40+
public function testArchiveUser()
41+
{
42+
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
43+
$stub->method('delete')->willReturn('foo');
44+
45+
$users = new IntercomUsers($stub);
46+
$this->assertEquals('foo', $users->archiveUser(''));
47+
}
48+
49+
public function testDeleteUser()
50+
{
51+
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
52+
$stub->method('delete')->willReturn('foo');
53+
54+
$users = new IntercomUsers($stub);
55+
$this->assertEquals('foo', $users->deleteUser(''));
56+
}
57+
58+
public function testPermanentlyDeleteUser()
59+
{
60+
$stub = $this->getMockBuilder('Intercom\IntercomClient')->disableOriginalConstructor()->getMock();
61+
$stub->method('post')->willReturn('foo');
62+
63+
$users = new IntercomUsers($stub);
64+
$this->assertEquals('foo', $users->permanentlyDeleteUser(''));
65+
}
3966
}

0 commit comments

Comments
 (0)