Skip to content

Instantly share code, notes, and snippets.

@FCO
Created October 24, 2015 18:24
Show Gist options
  • Save FCO/2e28939da129b75a5ac2 to your computer and use it in GitHub Desktop.
Save FCO/2e28939da129b75a5ac2 to your computer and use it in GitHub Desktop.
var CommandWS = require("CommandWS.js");
function TWS(url) {
this.cws = new CommandWS(url);
this.apiKey = null,
this.authKey = null;
this.cws.on("open", function() {
this.setApiKey("1234");
this.login("smokemachine", "12345", function(error, cmd) {
// you are logged in!
// or there's a error
if(error) throw error;
console.log("we are logged in!");
cws.custom.subscribePhotolink(function(error, photolink) {
alert(JSON.stringify(photolink));
});
setTimeout(function() {
cws.custom.clickTrackmotion(1);
}, 1000);
setTimeout(function() {
cws.custom.logout();
}, 3000);
});
});
}
TWS.prototype = {
setApiKey: function(api_key) {cws.stash.api_key = api_key},
login: function(user_name, password, cb) {
this.cws.cmd.login({
api_key: cws.stash.api_key,
user_name: user_name,
password: password,
model: "iPad"
}, function(response) {
if("auth_key" in response.data)
this.auth_key = response.data.auth_key;
if(cb) cb.call(this, response.error, response.data);
}.bind(this));
},
logout: function(cb) {
this.cws.cmd.logout({
api_key: this.api_key,
auth_key: this.auth_key,
}, function(response) {
if(cb) cb.call(this, response.error, response.data);
}.bind(this));
},
subscribePhotolink: function(cb) {
this.cws.cmd.photolink({
api_key: this.api_key,
auth_key: this.auth_key,
}, function(response) {
if(cb) cb.call(this, response.error, response.data);
}.bind(this));
},
cws.custom.clickTrackmotion = function(trackmotion, cb) {
this.cws.cmd.click_trackmotion({
api_key: this.api_key,
auth_key: this.auth_key,
trackmotion: trackmotion
}, function(response) {
if(cb) cb.call(this, response.error, response.data);
}.bind(this));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment