Or how to turn this:
into this:
#!/usr/bin/env node | |
// the pathname of the url without the leading '/' is used as softoken pin | |
// so make the call with http://localhost:8000/<softoken-pin> | |
const https = require('https'), | |
fs = require("fs"), | |
url = require('url'), | |
exec = require('child_process').exec; |
// create model factory, pass in Alloy global object | |
var MODELS = new (require('models').MODELS)(Alloy); | |
var person = new MODELS.Person({ | |
"name" : "Reina Saunders", | |
"age" : 2 | |
}); | |
person.save(null, { | |
"success" : function(_m, _r) { |
Ti Agent is light-weight progressive ajax API crafted for flexibility, readability, and a low learning curve after being frustrated with many of the existing request APIs.
request
.post('/api/pet')
.data({ name: 'Manny', species: 'cat' })
.set('X-API-Key', 'foobar')
.set('Accept', 'application/json')
.end(function(res){
var get_file = function(url, callback) { | |
var xhr = Ti.Network.createHTTPClient({ | |
onload: function(e) { | |
// this function is called when data is returned from the server and available for use | |
// this.responseText holds the raw text return of the message (used for text/JSON) | |
// this.responseXML holds any returned XML (including SOAP) | |
// this.responseData holds any returned binary data | |
console.log('downloaded '+ url); | |
callback({ |
function doClickMenu(evt){ | |
alert(evt.source.title); | |
} | |
// we need to do some things to the Window once it is properly instanciated, so we add an event listener to its OPEN event | |
$.win.addEventListener('open',function(){ | |
var actionBar = $.win.activity.actionBar; // get a handle to the action bar | |
actionBar.title='My App'; // change the App Title | |
actionBar.displayHomeAsUp=true; // Show the "angle" pointing back | |
actionBar.onHomeIconItemSelected = function() { // what to do when the "home" icon is pressed |
var win1 = Titanium.UI.createWindow({ | |
title:'Tab 1', | |
backgroundColor:'#fff', | |
layout: 'vertical' | |
}); | |
var bt1 = Ti.UI.createButton({title: 'send message (method 1)', top: 200}); | |
bt1.addEventListener('click', function(e) |
/* Window and View Styling */ | |
'.container': { | |
height: Ti.UI.FILL, | |
width: Ti.UI.FILL, | |
backgroundColor: 'white' | |
} | |
/* TabGroup styling */ | |
'#tabGroup':{ |
Ti.include('overrideTabs.js'); | |
/* | |
This is a typical new project -- a tab group with three tabs. | |
*/ | |
var tabGroup = Ti.UI.createTabGroup(); | |
/* | |
Tab 1. |
var win1 = Titanium.UI.createWindow({ | |
title:'Tab 1', | |
backgroundColor:'#fff', | |
layout: 'vertical' | |
}); | |
var bt1 = Ti.UI.createButton({title: 'send message (method 1)', top: 200}); | |
bt1.addEventListener('click', function(e) |