ServiceClass representation of a web service call. Summary | Class representation of a web service call. | | | | | | | | Creates an instance of the mojo.service.Service class. | | Retreives the name of the web service. | | Sets the name for the web service. | | Retrieves the Uri for the web service. | | Sets the Uri for the web service. | | Retrieves the options for the web service call. | | Sets the options for the web service call. | | Fires the web service request, and triggers onResponse or onError callback methods on the caller depending on success or failure respectively. |
mojo. service. Service constants| VALID_METHODS | A list of HTTP methods acceptable as configuration when instantiating a new mojo.service.Service object. | | DEFAULT_PARAMS | The default configuration for a mojo.service.Service object. |
constructor| constructor: function( | name, | | uri, | | paramsObj | ) |
|
Creates an instance of the mojo.service.Service class. Parameters| name | {string} | | uri | {string} | | paramsObj | {object} |
Example// instantiate a new JSON service that caches for 60 seconds var jsonService = new mojo.service.Service("getRSS", "/json/rssFeed", {format: 'json', cache: true, cacheExpiry: 60});
// instantiate a new text transport service that does not cache var textService = new mojo.service.Service("getHTMlFragment", "/html/fragment.html", {format: 'text', cache: false});
// instantiate a new XML service that does not make inferences about what nodes should form part of an array of nodes var xmlService = new mojo.service.Service("getAtom", "/xml/atomFeed", {format: 'xml', inferArrays: false});
getNameRetreives the name of the web service. Returns{string} Name of the service. Examplevar service = new mojo.service.Service("getRSS", "/json/rssFeed", {format: 'json', cache: true}); var name = service.getName(); // returns "getRSS"
setNameSets the name for the web service. Parameters| name | {string} The name of the service. |
Example// instantiate a new service var service = new mojo.service.Service("getRSS", "/json/rssFeed", {format: 'json', cache: true}); service.setName("getNews"); // changes name from "getRSS" to "getNews"
getUriRetrieves the Uri for the web service. Uri returned will include TrimPath variable syntax if inserted. Returns{string} uri Example// instantiate a new service var service = new mojo.service.Service("getRSS", "/json/rssFeed", {format: 'json', cache: true}); var uri = service.getUri(); // returns "/json/rssFeed"
setUriSets the Uri for the web service. TrimPath variable syntax can be inserted to allow for dynamic Uri generation when invoking service call. ParametersExample// instantiate a new service var service = new mojo.service.Service("getRSS", "/json/rssFeed", {format: 'json', cache: true}); service.setUri("/json/rssFeed/${id}"); // add dynamic variable to Uri
getParamsRetrieves the options for the web service call. If options are not explicitly set, default option values will be returned. Returns{object} Parameter Object. Example// instantiate a new service var service = new mojo.service.Service("getRSS", "/json/rssFeed", {format: 'json', cache: true}); var options = service.getParams(); // returns {json:true, cache:true, method:"GET", cacheExpiry:0, retry: 1}
setParams| setParams: function( | paramsObj | ) |
|
Sets the options for the web service call. Parameters| paramsObj | {object} Parameters to be sent to the service. |
Example// instantiate a new service var service = new mojo.service.Service("getRSS", "/json/rssFeed", {format: 'json', cache: true}); service.setParams({cache: false}); // changes cache to false. All other defined options remain unchanged.
invoke| invoke: function( | paramsObj, | | callerObj | ) |
|
Fires the web service request, and triggers onResponse or onError callback methods on the caller depending on success or failure respectively. Optional service parameters are sent with the web service request, and are used to generate a dynamic Uri for the call when TrimPath syntax is used (if TrimPath.parseTemplate is available). Parameters| paramsObj | {object} Parameters to send to the service. | | callerObj | {object} Command object to pass to the service. |
Example// instantiate a new service var service = new mojo.service.Service("getRSS", "/json/rssFeed/${id}", {format: 'json', cache: true}); var caller = { onResponse: function(data) { alert("success!"); }, onError: function(error) { alert("error"); } } service.invoke({id: "cnn"}, caller); // generates Uri "/json/rssFeed/cnn" based on the service parameters passed in. //Triggers callback methods onResponse or onError
|