Skip to content

Commit

Permalink
Merge pull request #82 from ckin-it/master
Browse files Browse the repository at this point in the history
Adding new API methods
  • Loading branch information
berkayk authored Nov 8, 2018
2 parents a3c0de6 + 2d051fa commit 5e880ba
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/OneSignalClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class OneSignalClient

const ENDPOINT_NOTIFICATIONS = "/notifications";
const ENDPOINT_PLAYERS = "/players";
const ENDPOINT_APPS = "/apps";

protected $client;
protected $headers;
Expand Down Expand Up @@ -109,6 +110,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';
}
Expand Down Expand Up @@ -347,6 +352,46 @@ 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();

if(!$app_id)
$app_id = $this->appId;

return $this->get(self::ENDPOINT_APPS . '/'.$app_id);
}

public function getApps() {
$this->requiresUserAuth();
$this->usesJSON();

return $this->get(self::ENDPOINT_APPS);
}

/**
* Creates a user/player
*
Expand All @@ -371,6 +416,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
*
Expand Down

0 comments on commit 5e880ba

Please sign in to comment.