home *** CD-ROM | disk | FTP | other *** search
- package com.facebook.air
- {
- import com.adobe.crypto.MD5;
- import com.adobe.serialization.json.JSON;
- import flash.events.Event;
- import flash.events.EventDispatcher;
- import flash.events.IOErrorEvent;
- import flash.events.SecurityErrorEvent;
- import flash.net.URLLoader;
- import flash.net.URLLoaderDataFormat;
- import flash.net.URLRequest;
- import flash.net.URLRequestMethod;
- import flash.net.URLVariables;
-
- public class JSONCall extends EventDispatcher
- {
- protected var sessionData:SessionData;
-
- protected var apiKey:String;
-
- protected var req:URLRequest;
-
- protected var loader:URLLoader;
-
- public function JSONCall(param1:SessionData, param2:String)
- {
- super();
- this.sessionData = param1;
- this.apiKey = param2;
- this.req = new URLRequest("http://api.facebook.com/restserver.php");
- this.req.contentType = "application/x-www-form-urlencoded";
- this.req.method = URLRequestMethod.GET;
- this.loader = new URLLoader();
- this.loader.dataFormat = URLLoaderDataFormat.TEXT;
- this.loader.addEventListener(Event.COMPLETE,this.onComplete);
- this.loader.addEventListener(IOErrorEvent.IO_ERROR,this.onIOError);
- this.loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onSecurityError);
- }
-
- protected function onIOError(param1:IOErrorEvent) : void
- {
- dispatchEvent(param1);
- }
-
- protected function onSecurityError(param1:SecurityErrorEvent) : void
- {
- dispatchEvent(param1);
- }
-
- protected function onComplete(param1:Event) : void
- {
- var _loc3_:* = undefined;
- var _loc2_:String = this.loader.data;
- if(_loc2_.indexOf("<") != 0)
- {
- _loc3_ = com.adobe.serialization.json.JSON.decode(_loc2_);
- if(_loc3_.constructor == Object && Boolean(_loc3_.error_code))
- {
- dispatchEvent(new JSONEvent(JSONEvent.FAILURE,_loc3_));
- }
- else
- {
- dispatchEvent(new JSONEvent(JSONEvent.SUCCESS,_loc3_));
- }
- }
- else
- {
- dispatchEvent(new JSONEvent(JSONEvent.FAILURE));
- }
- }
-
- public function call(param1:String, param2:Object = null) : void
- {
- var _loc4_:String = null;
- var _loc5_:Array = null;
- var _loc6_:String = null;
- var _loc3_:URLVariables = new URLVariables();
- for(_loc4_ in param2)
- {
- _loc3_[_loc4_] = param2[_loc4_];
- }
- _loc3_.v = "1.0";
- _loc3_.format = "JSON";
- _loc3_.method = param1;
- _loc3_.api_key = this.apiKey;
- _loc3_.call_id = new Date().time.toString();
- _loc3_.session_key = this.sessionData.session_key;
- _loc5_ = new Array();
- for(_loc6_ in _loc3_)
- {
- _loc5_.push(_loc6_ + "=" + _loc3_[_loc6_]);
- }
- _loc5_.sort();
- _loc3_.sig = MD5.hash(_loc5_.join("") + this.sessionData.secret);
- this.req.data = _loc3_;
- this.loader.load(this.req);
- }
- }
- }
-
-