Skip to content

Instantly share code, notes, and snippets.

@aaronksaunders
Created October 13, 2011 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronksaunders/1283040 to your computer and use it in GitHub Desktop.
Save aaronksaunders/1283040 to your computer and use it in GitHub Desktop.
nativehttpqueue module for appcelerator titanium
var nativehttpqueue = require('com.clearlyinnovative.nativeHttpQueue');
/**
additional paramater(s) supported per request
Paramaters
----------
"username" : "<username>"
"password" : "<password>"
"domain" : "<domain>" domain for NTLM
"userAgent" : "<user-agent>" change default user-agent
- headers can be passed as a map and will be assigned to the request
Response Data
-------------
Content can be returned directly to a file located in the application data
directory or you will get back a blob that contains the data.
Events
------
- event is fired for the success and failure for each request
- event is fired when the queue is finished processing
all requests.
*/
var x = [{
"url" : "http://www.ibm.com",
"destfile" : "/testci.html",
"headers" : {
"Accept" : "application/json"
}
}, {
"url" : "http://www.clearlyinnovative.com",
"destfile" : "/testci.html",
}];
nativehttpqueue.fillQueue(x);
// called for each item in the queue
nativehttpqueue.addEventListener("requestComplete", function(d) {
Ti.API.debug("url " + d.url);
Ti.API.debug("status " + d.status);
Ti.API.debug("destfile " + d.destfile);
Ti.API.debug("contents (TiBlob) " + d.contents);
});
// called for each item in the queue
nativehttpqueue.addEventListener("requestFailed", function(d) {
Ti.API.debug("ERROR: " + d.error);
Ti.API.debug("returned object: " + JSON.stringify(d));
});
// called when queue is completed
nativehttpqueue.addEventListener("queueFinished", function(d) {
Ti.API.debug(JSON.stringify(d));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment