Class Index | File Index

Classes


Class com.gContactSync.HttpRequest


Defined in: HttpRequest.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Sets up an HTTP request.
Field Summary
Field Attributes Field Name and Description
 
Content types
Method Summary
Method Attributes Method Name and Description
 
Adds a content override to the header in case a firewall blocks DELETE or PUT requests.
 
addHeaderItem(aLabel, aValue)
Adds a header label/value pair to the arrays of header information
 
send()
Sends the HTTP Request with the information stored in the object.
Class Detail
com.gContactSync.HttpRequest()
Sets up an HTTP request.
The constructor is not all that useful so extend this class if you must make repetitive HTTP requests.

You may setup callbacks based on different HTTP status codes:
  • 0 (offline): use mOnError
  • 200 (OK): use mOnSuccess
  • 201 (CREATED): use mOnCreated
  • 401 (UNAUTHORIZED): use mOn401
  • <anything else>: use mOnError

Sample usage:
// Create and setup a new HttpRequest
var myHttpRequest   = new com.gContactSync.HttpRequest();
myHttpRequest.mUrl  = "http://www.pirules.org";
myHttpRequest.mType = "GET";
myHttpRequest.addHeaderItem("Content-length", 0);
// setup the callbacks
myHttpRequest.mOnSuccess = function myRequestSuccess(aHttpReq) {
  com.gContactSync.alert("Request succeeded.  Content:\n\n" + aHttpReq.statusText);
};
myHttpRequest.mOnOffline = function myRequestOffline(aHttpReq) {
  com.gContactSync.alert("You are offline");
};
myHttpRequest.mOnError   = function myRequestError(aHttpReq) {
  com.gContactSync.alert("Request failed...Status: " + aHttpReq.status); 
};
// send the request
myHttpRequest.send();
Field Detail
CONTENT_TYPES
Content types
Method Detail
addContentOverride(aType)
Adds a content override to the header in case a firewall blocks DELETE or PUT requests.
Parameters:
aType
{string} The type of override. Must be DELETE or PUT.

addHeaderItem(aLabel, aValue)
Adds a header label/value pair to the arrays of header information
Parameters:
aLabel
{string} The label for the header.
aValue
{string} The value for the header.

send()
Sends the HTTP Request with the information stored in the object.
Note: Setup everything, including the callbacks for different statuses including mOnSuccess, mOnError, mOnFail, and mOnCreated first.
See the class documentation for a sample request.

Documentation generated by JsDoc Toolkit 2.1.0 on Fri May 06 2011 09:24:18 GMT-0400 (EDT)