From 790b51ffdcd1635cefacef4f5c63650d02dfd483 Mon Sep 17 00:00:00 2001 From: loox Date: Thu, 5 Jul 2018 17:32:54 +0200 Subject: [PATCH 1/4] Adding support for getApp / getApps in OneSignalClient --- src/OneSignalClient.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 30f2022..953ea06 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -10,6 +10,7 @@ class OneSignalClient const ENDPOINT_NOTIFICATIONS = "/notifications"; const ENDPOINT_PLAYERS = "/players"; + const ENDPOINT_APPS = "/apps"; protected $client; protected $headers; @@ -298,6 +299,23 @@ public function getNotification($notification_id, $app_id = null) { return $this->get(self::ENDPOINT_NOTIFICATIONS . '/'.$notification_id . '?app_id='.$app_id); } + public function getApp($app_id = null) { + $this->requiresAuth(); + $this->usesJSON(); + + if(!$app_id) + $app_id = $this->appId; + + return $this->get(self::ENDPOINT_APPS . '/'.$app_id); + } + + public function getApps() { + $this->requiresAuth(); + $this->usesJSON(); + + return $this->get(self::ENDPOINT_APPS); + } + /** * Creates a user/player * From 6dcf4316dbf6393bd09cf1487ed7336d04177a24 Mon Sep 17 00:00:00 2001 From: loox Date: Thu, 5 Jul 2018 17:43:45 +0200 Subject: [PATCH 2/4] adding requiresUserAuth method --- src/OneSignalClient.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 953ea06..e4199b0 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -71,6 +71,10 @@ private function requiresAuth() { $this->headers['headers']['Authorization'] = 'Basic '.$this->restApiKey; } + private function requiresUserAuth() { + $this->headers['headers']['Authorization'] = 'Basic '.$this->userAuthKey; + } + private function usesJSON() { $this->headers['headers']['Content-Type'] = 'application/json'; } @@ -300,7 +304,7 @@ public function getNotification($notification_id, $app_id = null) { } public function getApp($app_id = null) { - $this->requiresAuth(); + $this->requiresUserAuth(); $this->usesJSON(); if(!$app_id) @@ -310,7 +314,7 @@ public function getApp($app_id = null) { } public function getApps() { - $this->requiresAuth(); + $this->requiresUserAuth(); $this->usesJSON(); return $this->get(self::ENDPOINT_APPS); From b3830e15aa6645ba1a52bf9d962feae9c8fe40a4 Mon Sep 17 00:00:00 2001 From: loox Date: Fri, 6 Jul 2018 11:46:00 +0200 Subject: [PATCH 3/4] Adding getNotifications method to OneSignalClient --- src/OneSignalClient.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index e4199b0..5899e23 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -303,6 +303,29 @@ public function getNotification($notification_id, $app_id = null) { return $this->get(self::ENDPOINT_NOTIFICATIONS . '/'.$notification_id . '?app_id='.$app_id); } + public function getNotifications($app_id = null, $limit = null, $offset = null) { + $this->requiresAuth(); + $this->usesJSON(); + + $endpoint = self::ENDPOINT_NOTIFICATIONS; + + if(!$app_id) { + $app_id = $this->appId; + } + + $endpoint.='?app_id='.$app_id; + + if($limit) { + $endpoint.="&limit=".$limit; + } + + if($offset) { + $endpoint.="&offset=".$$offset; + } + + return $this->get($endpoint); + } + public function getApp($app_id = null) { $this->requiresUserAuth(); $this->usesJSON(); From 2d051fa40e7b4251cc6e7179b4ec7d7728394110 Mon Sep 17 00:00:00 2001 From: loox Date: Tue, 10 Jul 2018 15:34:31 +0200 Subject: [PATCH 4/4] Adding CSV export --- src/OneSignalClient.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/OneSignalClient.php b/src/OneSignalClient.php index 5899e23..662f7ba 100644 --- a/src/OneSignalClient.php +++ b/src/OneSignalClient.php @@ -367,6 +367,16 @@ public function editPlayer(Array $parameters) { return $this->sendPlayer($parameters, 'PUT', self::ENDPOINT_PLAYERS . '/' . $parameters['id']); } + public function requestPlayersCSV($app_id = null, Array $parameters = null) { + $this->requiresAuth(); + $this->usesJSON(); + + $endpoint = self::ENDPOINT_PLAYERS."/csv_export?"; + $endpoint .= "app_id" . $app_id?$app_id:$this->appId; + + return $this->sendPlayer($parameters, 'POST', $endpoint); + } + /** * Create or update a by $method value *