Skip to content

Commit

Permalink
get playes, one player, edit and create new player on onesignal
Browse files Browse the repository at this point in the history
  • Loading branch information
stojankukrika committed Apr 19, 2018
1 parent 819c3b6 commit 09ed83b
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 4 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,39 @@ You can send a custom message with
OneSignal::sendNotificationCustom($parameters);

### Sending a Custom Notification

### Sending a async Custom Notification
You can send a async custom message with

OneSignal::async()->sendNotificationCustom($parameters);

Please refer to https://documentation.onesignal.com/reference for all customizable parameters.

### Create Player(add user into onesignal)
You can send request with

OneSignal::createPlayer($parameters);

Please refer to https://documentation.onesignal.com/reference#add-a-device for all customizable parameters.

### Edit Player(edit user in onesignal)
You can send request editPlayer (add in array $parameters value with 'id' params)

OneSignal::editPlayer($parameters);

Please refer to https://documentation.onesignal.com/reference#edit-device for all customizable parameters.

### View device
You can send request with

OneSignal::getPlayer($device_id);

Please refer to https://documentation.onesignal.com/reference#view-device for all customizable parameters.

### Get all Players(users from onesignal)
You can send request with

OneSignal::getAllPlayers($limit, $offset);

Please refer to https://documentation.onesignal.com/reference#view-devices for all customizable parameters.

48 changes: 44 additions & 4 deletions src/OneSignalClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,35 @@ public function editPlayer(Array $parameters) {
return $this->sendPlayer($parameters, 'PUT', self::ENDPOINT_PLAYERS . '/' . $parameters['id']);
}

/**
* Get list of all users/players
*
* @param int $limit
* @param int $offset
* @return mixed
*/
public function getAllPlayers($limit=300, $offset=0) {
$params = array(
'app_id' => $this->appId,
'limit' => $limit,
'offset' => $offset
);
return $this->sendPlayer($params, 'GET', self::ENDPOINT_PLAYERS . '?' . http_build_query($params));
}

/**
* Get list of all users/players
*
* @param string $id
* @return mixed
*/
public function getPlayer($id) {
$params = array(
'app_id' => $this->appId,
);
return $this->sendPlayer($params, 'GET', self::ENDPOINT_PLAYERS . '/'.$id.'?' . http_build_query($params));
}

/**
* Create or update a by $method value
*
Expand All @@ -285,11 +314,15 @@ private function sendPlayer(Array $parameters, $method, $endpoint)
$this->requiresAuth();
$this->usesJSON();

$parameters['app_id'] = $this->appId;
$this->headers['body'] = json_encode($parameters);

$method = strtolower($method);
return $this->{$method}($endpoint);

if ($method=='get') {
$this->headers['headers']['Authorization'] = 'Basic '.$this->restApiKey;
return $this->{$method}($endpoint,$this->headers);
}else{
$this->headers['body'] = json_encode($parameters);
return $this->{$method}($endpoint);
}
}

public function post($endPoint) {
Expand All @@ -307,4 +340,11 @@ public function put($endPoint) {
}
return $this->client->put(self::API_URL . $endPoint, $this->headers);
}

public function get($endPoint, $headers) {
$client = new Client([
'defaults' => $headers
]);
return $client->get(self::API_URL . $endPoint, $headers);
}
}

0 comments on commit 09ed83b

Please sign in to comment.