Skip to content

Instantly share code, notes, and snippets.

@saranicole
Created June 29, 2011 12:54
Show Gist options
  • Save saranicole/1053766 to your computer and use it in GitHub Desktop.
Save saranicole/1053766 to your computer and use it in GitHub Desktop.
Building Killer Applications with Flash - Demo 3 of 3: A Polished App
package Axeda.Controller.Services
{
import RiaBus.Controller.Core.ApplicationManager;
import com.adobe.utils.StringUtil;
import mx.rpc.AsyncToken;
import mx.rpc.http.HTTPService;
public class RestService {
private var _url
:String;
public function RestService(url:String="") {
_url = url;
if (!StringUtil.endsWith(_url, "/")) _url += "/";
}
public function Execute(operation:String,
parameters:Object=null,
method:String=HttpMethod.GET,
result:String=HttpResult.OBJECT,
contentType:String=HttpContentType.FORM)
:AsyncToken
{
var httpService:HTTPService = new HTTPService();
httpService.method = method;
httpService.resultFormat = result;
httpService.showBusyCursor = true;
if (parameters) {
httpService.request = parameters;
httpService.contentType = contentType;
}
httpService.url = getServiceUrl(operation);
return httpService.send();
}
private function getServiceUrl(operation:String)
:String
{
var fullUrl:String = _url + operation;
var sessionId:String = ApplicationManager.Instance.context.getAttribute("SessionId");
if (sessionId) fullUrl += ((fullUrl.indexOf('?') >= 0) ? "&" : "?") + "sessionid=" + sessionId;
return fullUrl;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment