Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion config/onesignal.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
<?php

return array(
/*
|--------------------------------------------------------------------------
| One Signal API URL
|--------------------------------------------------------------------------
|
|
*/
//'api_url' => 'YOUR-API-URL-HERE', // or empty for https://onesignal.com/api/v1

/*
|--------------------------------------------------------------------------
| One Signal App Id
Expand All @@ -20,4 +29,4 @@
*/
'rest_api_key' => 'YOUR-REST-API-KEY-HERE',
'user_auth_key' => 'YOUR-USER-AUTH-KEY'
);
);
18 changes: 10 additions & 8 deletions src/OneSignalClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class OneSignalClient
protected $appId;
protected $restApiKey;
protected $userAuthKey;
protected $apiUrl;
protected $additionalParams;

/**
Expand Down Expand Up @@ -69,11 +70,12 @@ public function callback(Callable $requestCallback)
return $this;
}

public function __construct($appId, $restApiKey, $userAuthKey)
public function __construct($appId, $restApiKey, $userAuthKey, $apiUrl = null)
{
$this->appId = $appId;
$this->restApiKey = $restApiKey;
$this->userAuthKey = $userAuthKey;
$this->apiUrl = $apiUrl ?: self::API_URL;

$this->client = new Client([
'handler' => $this->createGuzzleHandler(),
Expand Down Expand Up @@ -499,29 +501,29 @@ private function sendPlayer(Array $parameters, $method, $endpoint)

public function post($endPoint) {
if($this->requestAsync === true) {
$promise = $this->client->postAsync(self::API_URL . $endPoint, $this->headers);
$promise = $this->client->postAsync($this->apiUrl . $endPoint, $this->headers);
return (is_callable($this->requestCallback) ? $promise->then($this->requestCallback) : $promise);
}
return $this->client->post(self::API_URL . $endPoint, $this->headers);
return $this->client->post($this->apiUrl . $endPoint, $this->headers);
}

public function put($endPoint) {
if($this->requestAsync === true) {
$promise = $this->client->putAsync(self::API_URL . $endPoint, $this->headers);
$promise = $this->client->putAsync($this->apiUrl . $endPoint, $this->headers);
return (is_callable($this->requestCallback) ? $promise->then($this->requestCallback) : $promise);
}
return $this->client->put(self::API_URL . $endPoint, $this->headers);
return $this->client->put($this->apiUrl . $endPoint, $this->headers);
}

public function get($endPoint) {
return $this->client->get(self::API_URL . $endPoint, $this->headers);
return $this->client->get($this->apiUrl . $endPoint, $this->headers);
}

public function delete($endPoint) {
if($this->requestAsync === true) {
$promise = $this->client->deleteAsync(self::API_URL . $endPoint, $this->headers);
$promise = $this->client->deleteAsync($this->apiUrl . $endPoint, $this->headers);
return (is_callable($this->requestCallback) ? $promise->then($this->requestCallback) : $promise);
}
return $this->client->delete(self::API_URL . $endPoint, $this->headers);
return $this->client->delete($this->apiUrl . $endPoint, $this->headers);
}
}
11 changes: 9 additions & 2 deletions src/OneSignalServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,19 @@ public function boot()
public function register()
{
$this->app->singleton('onesignal', function ($app) {
$config = isset($app['config']['services']['onesignal']) ? $app['config']['services']['onesignal'] : null;
$config = isset($app['config']['services']['onesignal'])
? $app['config']['services']['onesignal']
: null;

if (is_null($config)) {
$config = $app['config']['onesignal'] ?: $app['config']['onesignal::config'];
}

$client = new OneSignalClient($config['app_id'], $config['rest_api_key'], $config['user_auth_key']);
$apiUrl = isset($config['api_url'])
? $config['api_url']
: null;

$client = new OneSignalClient($config['app_id'], $config['rest_api_key'], $config['user_auth_key'], $apiUrl);

return $client;
});
Expand Down
5 changes: 3 additions & 2 deletions tests/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
$client = new Berkayk\OneSignal\OneSignalClient(
getenv('APP_ID'),
getenv('REST_API_KEY'),
getenv('USER_AUTH_KEY'));
getenv('USER_AUTH_KEY'),
getenv('API_URL'));

echo $client->testCredentials();
$client->sendNotificationToUser(".","4bc5da02-1722-4fee-943d-c8b5ccd507a2");
$client->sendNotificationToUser("Test",getenv('USER_ID') ?: "4bc5da02-1722-4fee-943d-c8b5ccd507a2");