forked from leancloud/javascript-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush.js
More file actions
63 lines (54 loc) · 2 KB
/
Copy pathpush.js
File metadata and controls
63 lines (54 loc) · 2 KB
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
/**
* 每位工程师都有保持代码优雅的义务
* Each engineer has a duty to keep the code elegant
**/
const AVRequest = require('./request').request;
module.exports = function(AV) {
AV.Installation = AV.Object.extend("_Installation");
/**
* Contains functions to deal with Push in AV
* @name AV.Push
* @namespace
*/
AV.Push = AV.Push || {};
/**
* Sends a push notification.
* @param {Object} data - The data of the push notification. Valid fields
* are:
* <ol>
* <li>channels - An Array of channels to push to.</li>
* <li>push_time - A Date object for when to send the push.</li>
* <li>expiration_time - A Date object for when to expire
* the push.</li>
* <li>expiration_interval - The seconds from now to expire the push.</li>
* <li>where - A AV.Query over AV.Installation that is used to match
* a set of installations to push to.</li>
* <li>cql - A CQL statement over AV.Installation that is used to match
* a set of installations to push to.</li>
* <li>data - The data to send as part of the push</li>
* <ol>
* @param {Object} options An object that has an optional success function,
* that takes no arguments and will be called on a successful push, and
* an error function that takes a AVError and will be called if the push
* failed.
*/
AV.Push.send = function(data, options) {
if (data.where) {
data.where = data.where.toJSON().where;
}
if(data.where && data.cql){
throw "Both where and cql can't be set";
}
if (data.push_time) {
data.push_time = data.push_time.toJSON();
}
if (data.expiration_time) {
data.expiration_time = data.expiration_time.toJSON();
}
if (data.expiration_time && data.expiration_time_interval) {
throw "Both expiration_time and expiration_time_interval can't be set";
}
var request = AVRequest('push', null, null, 'POST', data);
return request._thenRunCallbacks(options);
};
};