コード例 #1
0
    api = new reste(),
    constant = require('./constants'),
    logger = require('./logger');

api.config({
    debug: false, // allows logging to console of ::REST:: messages
    autoValidateParams: false, // set to true to throw errors if <param> url properties are not passed
    timeout: 4000,
    url: "https://api.parse.com/1/",
    requestHeaders: {
        "X-Parse-Application-Id": Ti.App.Properties.getString('com.sensimity.ti.parse_appId', Alloy.CFG.parse.appId),
        "X-Parse-REST-API-Key": Ti.App.Properties.getString('com.sensimity.ti.parse_apiKey', Alloy.CFG.parse.apiKey),
        "Content-Type": "application/json"
    },
    methods: [{
        name: "addInstallation",
        post: "installations"
    }, {
        name: "updateInstallation",
        put: "installations/<objectId>"
    }],
    onError: function(e) {
        logger.info('There was an error accessing the API > ' + JSON.stringify(e.error));
    },
    onLoad: function(e, callback) {
        callback(e);
    }
});

function registerPush(params, success, error) {
    if (!Ti.Network.getOnline()) {
        logger.error('No push channels registration was issued, device is offline');
コード例 #2
0
ファイル: isy.js プロジェクト: kgividen/xControl
exports.init = function() {
    //This is the saved connection object set by the user
    var conn = Ti.App.Properties.getObject('conn_current');
    if (!conn) {
        return false;
    } else {
        connection.baseURL = conn.method + '://' + conn.server + ':' + conn.port + '/rest/';
        var authString = conn.username + ':' + conn.password;
        var b64encodedAuthString = Ti.Utils.base64encode(authString.toString());
        
        connection.headers = {
        	'Accept':'application/xml', 
        	'Authorization':'Basic ' + b64encodedAuthString
        };
        connection.connectiontype = 'GET';
        connection.username = conn.username; //This is so we can throw an error and let them know what the user was.

	    api.config({
		    debug: false, // allows logging to console of ::REST:: messages
		    autoValidateParams: false, // set to true to throw errors if <param> url properties are not passed
		    timeout: 10000,
		    url: connection.baseURL,
		    requestHeaders: connection.headers,
		    methods: [{
		        name: "getDeviceStatus",
		        get: "status/<address>",
		        onError: function(e, callback){
		            Ti.API.info("There was an error getting the status!");
		        }
		    },{
		        name: "getNodes",
		        get: "nodes",
		        onError: function(e, callback){
		            Ti.API.info("There was an error getting the nodes!");
		            var dialog = Ti.UI.createAlertDialog({
    					message: 'There was an error getting the devices.  Please verify your connection information.',
						ok: 'Ok',
				  	});
				  	dialog.addEventListener('click', function(e){
					  	Alloy.Globals.PW.hideIndicator();	  
				  	});
				  	dialog.show();
		        }
		    },{
		        name: "deviceFastOn",
		        get: "nodes/<address>/cmd/DFON",
		        onError: function(e, callback){
		            Ti.API.info("There was an error setting device fast on!");
		        }
		    },{
		        name: "deviceFastOff",
		        get: "nodes/<address>/cmd/DFOF",
		        onError: function(e, callback){
		            Ti.API.info("There was an error setting device fast off!");
		        }
		    },{
		        name: "deviceOn",
		        get: "nodes/<address>/cmd/DON/<level>",
		        onError: function(e, callback){
		            Ti.API.info("There was an error setting device on!");
		       }
		    },{
		        name: "deviceOff",
		        get: "nodes/<address>/cmd/DOF",
		        onError: function(e, callback){
		            Ti.API.info("There was an error setting device off!");
		       }
		    },{
		        name: "runProgram",
		        get: "programs/<id>/run/<runType>",
		        onError: function(e, callback){
		            Ti.API.info("There was an error running program");
		       }
		    },{
		        name: "enableProgram",
		        get: "programs/<id>/enable",
		        onError: function(e, callback){
		            Ti.API.info("There was an error enabling program");
		       }
	        },{
		        name: "disableProgram",
		        get: "programs/<id>/disable",
		        onError: function(e, callback){
		            Ti.API.info("There was an error disabling program");
		       }
	        }
		    ],
		    onError: function(e) {
		        Ti.API.info("There was an error accessing the API");
		    },
		    onLoad: function(e, callback) {
		        callback(e);
		    }
		});
		
    	return true;
    }
};