-
Notifications
You must be signed in to change notification settings - Fork 4
/
OneSignal.php
72 lines (62 loc) · 1.49 KB
/
OneSignal.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* Created by PhpStorm.
* User: rocketman
* Date: 23.06.16
* Time: 12:39
*/
namespace rocketfirm\onesignal;
use rocketfirm\onesignal\helpers\Notifications;
use rocketfirm\onesignal\helpers\Player;
use yii\base\Component;
use yii\base\Exception;
class OneSignal extends Component
{
public $appId;
public $apiKey;
/**
* Initializing OneSignal component
*
* @return void
* @throws Exception
*/
public function init()
{
if (empty($this->appId)) {
throw new Exception('Configure onesignal appId!');
}
if (empty($this->apiKey)) {
throw new Exception('Configure onesignal apiKey!');
}
}
/**
* Work with player API
*
* @param bool|int $id ID of player to edit/view
* or false for common methods
*
* @return Player
*/
public function players($id = false)
{
$player = new Player(
['appId' => $this->appId, 'apiKey' => $this->apiKey, 'id' => $id]
);
return $player;
}
/**
* Work with notifications API
*
* @param bool|int $id ID of notification to edit/view
* or false for common methods
*
* @return Notifications
*/
public function notifications($id = false)
{
$notification = new Notifications(
['appId' => $this->appId, 'apiKey' => $this->apiKey, 'id' => $id]
);
return $notification;
}
}