Skip to content

Commit b552b7e

Browse files
committed
Merge pull request #105 from simcen/master
Added support to delete device
1 parent d876ad4 commit b552b7e

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/Devices.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,29 @@ public function update($id, array $data)
100100
return $this->api->request('PUT', '/players/'.$id, [], json_encode($data));
101101
}
102102

103+
/**
104+
* Delete existing registered device from your application.
105+
*
106+
* OneSignal supports DELETE on the players API endpoint which is not documented in their official documentation
107+
* Reference: https://documentation.onesignal.com/docs/handling-personal-data#section-deleting-users-or-other-data-from-onesignal
108+
*
109+
* Application auth key must be set.
110+
*
111+
* @param string $id Device ID
112+
*
113+
* @return array
114+
*/
115+
public function delete($id)
116+
{
117+
$query = [
118+
'app_id' => $this->api->getConfig()->getApplicationId(),
119+
];
120+
121+
return $this->api->request('DELETE', '/players/'.$id.'?'.http_build_query($query), [
122+
'Authorization' => 'Basic '.$this->api->getConfig()->getApplicationAuthKey(),
123+
]);
124+
}
125+
103126
/**
104127
* Call on new device session in your app.
105128
*

tests/OneSignal/Tests/DevicesTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@ public function testUpdate()
7070
$this->assertEquals($expectedRequest, $this->devices->update($fakeId, ['data' => 'myData']));
7171
}
7272

73+
public function testDelete()
74+
{
75+
$fakeId = 1234;
76+
$expectedRequest = [
77+
'DELETE',
78+
'/players/'.$fakeId.'?app_id=fakeApplicationId',
79+
['Authorization' => 'Basic fakeApplicationAuthKey'],
80+
null,
81+
];
82+
83+
$this->assertEquals($expectedRequest, $this->devices->delete($fakeId));
84+
}
85+
7386
public function testOnSession()
7487
{
7588
$fakeId = 1234;

0 commit comments

Comments
 (0)