Last active
August 29, 2015 14:13
-
-
Save snatchev/eacdfb4ad9fe58a22d83 to your computer and use it in GitHub Desktop.
cloudcode-zeropush.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* simple API wrapper for Parse Cloud Code and ZeroPush */ | |
ZeroPush = { | |
authToken: 'your-server-auth-token', | |
verifyCredentials: function(){ | |
this.request('GET', '/verify_credentials'); | |
}, | |
register: function(params){ | |
this.request('POST', '/register', params); | |
}, | |
notify: function(params){ | |
this.request('POST', '/notify', params); | |
}, | |
broadcast: function(params){ | |
this.request('POST', '/broadcast', params); | |
}, | |
request: function(verb, path, params){ | |
Parse.Cloud.httpRequest({ | |
method: verb, | |
url: 'https://api.zeropush.com' + path, | |
headers: { | |
'Content-Type': 'application/json;charset=utf-8', | |
'Authorization': 'Token token="' + this.authToken + '"' | |
}, | |
body: params, | |
success: function(httpResponse) { | |
console.log(httpResponse.text); | |
}, | |
error: function(httpResponse) { | |
console.error('Request failed with response code ' + httpResponse.status); | |
} | |
}); | |
} | |
} | |
ZeroPush.authToken = 'your server auth token' | |
ZeroPush.verifyCredentials(); //console should log success response | |
ZeroPush.register({device_token: 'abcdef', channel: 'player-1'}) | |
ZeroPush.broadcast({channel: 'player-1', alert: 'hello, player-1'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment