Skip to content

Commit ce1c399

Browse files
authored
Merge pull request #197 from mass5/add_rest_api_url_to_config
Migrate from legacy API keys
2 parents 0fa625a + 7785ba6 commit ce1c399

File tree

5 files changed

+16
-11
lines changed

5 files changed

+16
-11
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ your OneSignal authorization keys.
6161

6262
## Configuration
6363

64-
You need to fill in your OneSignal *App ID* and *REST API Key* inside your
64+
You need to fill in your OneSignal *REST API URL* *App ID* and *REST API Key* inside your
6565
.env file like this:
6666
```
67+
ONESIGNAL_REST_API_URL=https://api.onesignal.com
6768
ONESIGNAL_APP_ID=xxxxxxxxxxxxxxxxxxxx
6869
ONESIGNAL_REST_API_KEY=xxxxxxxxxxxxxxxxxx
6970
```

config/onesignal.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
|
1919
|
2020
*/
21+
'rest_api_url' => env('ONESIGNAL_REST_API_URL', 'https://api.onesignal.com'),
2122
'rest_api_key' => env('ONESIGNAL_REST_API_KEY'),
2223
'user_auth_key' => env('USER_AUTH_KEY'),
2324

src/OneSignalClient.php

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
class OneSignalClient
1515
{
16-
const API_URL = "https://onesignal.com/api/v1";
1716

1817
const ENDPOINT_NOTIFICATIONS = "/notifications";
1918
const ENDPOINT_PLAYERS = "/players";
@@ -22,6 +21,7 @@ class OneSignalClient
2221
protected $client;
2322
protected $headers;
2423
protected $appId;
24+
protected $restApiUrl;
2525
protected $restApiKey;
2626
protected $userAuthKey;
2727
protected $additionalParams;
@@ -71,13 +71,15 @@ public function callback(Callable $requestCallback)
7171

7272
/**
7373
* @param $appId
74+
* @param $restApiUrl
7475
* @param $restApiKey
7576
* @param $userAuthKey
7677
* @param int $guzzleClientTimeout
7778
*/
78-
public function __construct($appId, $restApiKey, $userAuthKey, $guzzleClientTimeout = 0)
79+
public function __construct($appId, $restApiUrl, $restApiKey, $userAuthKey, $guzzleClientTimeout = 0)
7980
{
8081
$this->appId = $appId;
82+
$this->restApiUrl = $restApiUrl;
8183
$this->restApiKey = $restApiKey;
8284
$this->userAuthKey = $userAuthKey;
8385

@@ -506,29 +508,29 @@ private function sendPlayer(Array $parameters, $method, $endpoint)
506508

507509
public function post($endPoint) {
508510
if($this->requestAsync === true) {
509-
$promise = $this->client->postAsync(self::API_URL . $endPoint, $this->headers);
511+
$promise = $this->client->postAsync($this->restApiUrl . $endPoint, $this->headers);
510512
return (is_callable($this->requestCallback) ? $promise->then($this->requestCallback) : $promise);
511513
}
512-
return $this->client->post(self::API_URL . $endPoint, $this->headers);
514+
return $this->client->post($this->restApiUrl . $endPoint, $this->headers);
513515
}
514516

515517
public function put($endPoint) {
516518
if($this->requestAsync === true) {
517-
$promise = $this->client->putAsync(self::API_URL . $endPoint, $this->headers);
519+
$promise = $this->client->putAsync($this->restApiUrl . $endPoint, $this->headers);
518520
return (is_callable($this->requestCallback) ? $promise->then($this->requestCallback) : $promise);
519521
}
520-
return $this->client->put(self::API_URL . $endPoint, $this->headers);
522+
return $this->client->put($this->restApiUrl . $endPoint, $this->headers);
521523
}
522524

523525
public function get($endPoint) {
524-
return $this->client->get(self::API_URL . $endPoint, $this->headers);
526+
return $this->client->get($this->restApiUrl . $endPoint, $this->headers);
525527
}
526528

527529
public function delete($endPoint) {
528530
if($this->requestAsync === true) {
529-
$promise = $this->client->deleteAsync(self::API_URL . $endPoint, $this->headers);
531+
$promise = $this->client->deleteAsync($this->restApiUrl . $endPoint, $this->headers);
530532
return (is_callable($this->requestCallback) ? $promise->then($this->requestCallback) : $promise);
531533
}
532-
return $this->client->delete(self::API_URL . $endPoint, $this->headers);
534+
return $this->client->delete($this->restApiUrl . $endPoint, $this->headers);
533535
}
534536
}

src/OneSignalServiceProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function register()
3636
$config = $app['config']['onesignal'] ?: $app['config']['onesignal::config'];
3737
}
3838

39-
return new OneSignalClient($config['app_id'], $config['rest_api_key'], $config['user_auth_key'] , $config['guzzle_client_timeout']);
39+
return new OneSignalClient($config['app_id'], $config['rest_api_url'], $config['rest_api_key'], $config['user_auth_key'] , $config['guzzle_client_timeout']);
4040
});
4141

4242
$this->app->alias('onesignal', 'Berkayk\OneSignal\OneSignalClient');

tests/test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
$client = new Berkayk\OneSignal\OneSignalClient(
99
getenv('APP_ID'),
10+
getenv('REST_API_URL'),
1011
getenv('REST_API_KEY'),
1112
getenv('USER_AUTH_KEY'));
1213

0 commit comments

Comments
 (0)