forked from andrewscofield/parse.com-php-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parsePush.php
93 lines (80 loc) · 2.22 KB
/
parsePush.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
class parsePush extends parseRestClient{
public $channels;
public $channel;
public $expiration_time;
public $expiration_time_intreval;
public $content_available;
public $type;
public $title;
public $where;
private $_globalMsg;
public function __construct($globalMsg=''){
if($globalMsg != ''){
$this->_globalMsg = $globalMsg;
}
parent::__construct();
}
public function __set($name,$value){
if($name != 'channel' || $name != 'channels' || $name != 'expiration_time' || $name != 'expiration_interval' || $name != 'type' || $name != 'data' || $name != 'where'){
$this->data[$name] = $value;
}
}
public function send(){
if($this->_globalMsg != ''){
$request = $this->request(array(
'method' => 'POST',
'requestUrl' => 'push',
'data' => array(
'channel' => '',
'data' => array(
'alert' => $this->_globalMsg
)
),
));
return $request;
}
else{
if(count($this->data) > 0){
if($this->channel == '' && empty($this->channels) && empty($this->where)){
$this->throwError('A push Channel must be set when not using Advanced Targeting');
}
$params = array(
'method' => 'POST',
'requestUrl' => 'push',
'data' => array(
'data' => $this->data
)
);
if(!empty($this->channels)){
$params['data']['channels'] = $this->channels;
}
if(!empty($this->channel)){
$params['data']['channel'] = $this->channel;
}
if(!empty($this->expiration_time)){
$params['data']['expiration_time'] = $this->expiration_time;
}
if(!empty($this->expiration_time_interval)){
$params['data']['expiration_interval'] = $this->expiration_interval;
}
if(!empty($this->content_available)){
//changed back to content-available... underscores are much easier to deal with in PHP
$params['data']['content-available'] = $this->content_available;
}
if(!empty($this->type)){
$params['data']['type'] = $this->type;
}
if(!empty($this->where)){
$params['data']['where'] = $this->where;
}
$request = $this->request($params);
return $request;
}
else{
$this->throwError('No push data has been set, you must set at least data. Please see the docs. ');
}
}
}
}
?>