Skip to content

Commit

Permalink
Merge pull request #105 from simcen/master
Browse files Browse the repository at this point in the history
Added support to delete device
  • Loading branch information
norkunas committed Dec 17, 2018
1 parent d876ad4 commit b552b7e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Devices.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,29 @@ public function update($id, array $data)
return $this->api->request('PUT', '/players/'.$id, [], json_encode($data));
}

/**
* Delete existing registered device from your application.
*
* OneSignal supports DELETE on the players API endpoint which is not documented in their official documentation
* Reference: https://documentation.onesignal.com/docs/handling-personal-data#section-deleting-users-or-other-data-from-onesignal
*
* Application auth key must be set.
*
* @param string $id Device ID
*
* @return array
*/
public function delete($id)
{
$query = [
'app_id' => $this->api->getConfig()->getApplicationId(),
];

return $this->api->request('DELETE', '/players/'.$id.'?'.http_build_query($query), [
'Authorization' => 'Basic '.$this->api->getConfig()->getApplicationAuthKey(),
]);
}

/**
* Call on new device session in your app.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/OneSignal/Tests/DevicesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ public function testUpdate()
$this->assertEquals($expectedRequest, $this->devices->update($fakeId, ['data' => 'myData']));
}

public function testDelete()
{
$fakeId = 1234;
$expectedRequest = [
'DELETE',
'/players/'.$fakeId.'?app_id=fakeApplicationId',
['Authorization' => 'Basic fakeApplicationAuthKey'],
null,
];

$this->assertEquals($expectedRequest, $this->devices->delete($fakeId));
}

public function testOnSession()
{
$fakeId = 1234;
Expand Down

0 comments on commit b552b7e

Please sign in to comment.