Skip to content

Commit 5e880ba

Browse files
authored
Merge pull request #82 from ckin-it/master
Adding new API methods
2 parents a3c0de6 + 2d051fa commit 5e880ba

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/OneSignalClient.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class OneSignalClient
1717

1818
const ENDPOINT_NOTIFICATIONS = "/notifications";
1919
const ENDPOINT_PLAYERS = "/players";
20+
const ENDPOINT_APPS = "/apps";
2021

2122
protected $client;
2223
protected $headers;
@@ -109,6 +110,10 @@ private function requiresAuth() {
109110
$this->headers['headers']['Authorization'] = 'Basic '.$this->restApiKey;
110111
}
111112

113+
private function requiresUserAuth() {
114+
$this->headers['headers']['Authorization'] = 'Basic '.$this->userAuthKey;
115+
}
116+
112117
private function usesJSON() {
113118
$this->headers['headers']['Content-Type'] = 'application/json';
114119
}
@@ -347,6 +352,46 @@ public function getNotification($notification_id, $app_id = null) {
347352
return $this->get(self::ENDPOINT_NOTIFICATIONS . '/'.$notification_id . '?app_id='.$app_id);
348353
}
349354

355+
public function getNotifications($app_id = null, $limit = null, $offset = null) {
356+
$this->requiresAuth();
357+
$this->usesJSON();
358+
359+
$endpoint = self::ENDPOINT_NOTIFICATIONS;
360+
361+
if(!$app_id) {
362+
$app_id = $this->appId;
363+
}
364+
365+
$endpoint.='?app_id='.$app_id;
366+
367+
if($limit) {
368+
$endpoint.="&limit=".$limit;
369+
}
370+
371+
if($offset) {
372+
$endpoint.="&offset=".$$offset;
373+
}
374+
375+
return $this->get($endpoint);
376+
}
377+
378+
public function getApp($app_id = null) {
379+
$this->requiresUserAuth();
380+
$this->usesJSON();
381+
382+
if(!$app_id)
383+
$app_id = $this->appId;
384+
385+
return $this->get(self::ENDPOINT_APPS . '/'.$app_id);
386+
}
387+
388+
public function getApps() {
389+
$this->requiresUserAuth();
390+
$this->usesJSON();
391+
392+
return $this->get(self::ENDPOINT_APPS);
393+
}
394+
350395
/**
351396
* Creates a user/player
352397
*
@@ -371,6 +416,16 @@ public function editPlayer(Array $parameters) {
371416
return $this->sendPlayer($parameters, 'PUT', self::ENDPOINT_PLAYERS . '/' . $parameters['id']);
372417
}
373418

419+
public function requestPlayersCSV($app_id = null, Array $parameters = null) {
420+
$this->requiresAuth();
421+
$this->usesJSON();
422+
423+
$endpoint = self::ENDPOINT_PLAYERS."/csv_export?";
424+
$endpoint .= "app_id" . $app_id?$app_id:$this->appId;
425+
426+
return $this->sendPlayer($parameters, 'POST', $endpoint);
427+
}
428+
374429
/**
375430
* Create or update a by $method value
376431
*

0 commit comments

Comments
 (0)