home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / com / althea / client / shufflr / model / PostCommandProxy.as < prev    next >
Encoding:
Text File  |  2010-06-23  |  14.3 KB  |  361 lines

  1. package com.althea.client.shufflr.model
  2. {
  3.    import com.althea.client.shufflr.ApplicationFacade;
  4.    import com.althea.client.shufflr.controller.errors.ApplicationError;
  5.    import com.facebook.events.FacebookEvent;
  6.    import mx.logging.LogEventLevel;
  7.    import mx.rpc.AsyncToken;
  8.    import mx.rpc.Fault;
  9.    import mx.rpc.IResponder;
  10.    import mx.rpc.events.FaultEvent;
  11.    import mx.rpc.http.HTTPService;
  12.    import org.puremvc.as3.multicore.patterns.proxy.Proxy;
  13.    
  14.    public class PostCommandProxy extends Proxy implements IResponder
  15.    {
  16.       public static const NAME:String = "PostCommandProxy";
  17.       
  18.       private var _attachment:Object = new Object();
  19.       
  20.       private var username:String;
  21.       
  22.       private var _shareOnFB:Boolean = false;
  23.       
  24.       private var service:HTTPService;
  25.       
  26.       public function PostCommandProxy(param1:Object = null)
  27.       {
  28.          super(NAME,param1);
  29.          this.service = new HTTPService();
  30.          this.service.method = "POST";
  31.          this.service.requestTimeout = 20;
  32.       }
  33.       
  34.       public function sendInvite(param1:String, param2:String) : void
  35.       {
  36.          var _loc3_:Object = new Object();
  37.          this.service.url = NavMapProxy.serverUrl + "/users/invites";
  38.          _loc3_["email"] = param1;
  39.          _loc3_["invite_text"] = param2;
  40.          var _loc4_:AsyncToken = this.service.send(_loc3_);
  41.          _loc4_.dataType = "emailInvite";
  42.          _loc4_.addResponder(this);
  43.       }
  44.       
  45.       public function reportBrokenLink(param1:String) : void
  46.       {
  47.          this.service.url = NavMapProxy.serverUrl + "videos/broken_link/" + param1;
  48.          var _loc2_:Object = new Object();
  49.          _loc2_["viewed"] = 1;
  50.          var _loc3_:AsyncToken = this.service.send(_loc2_);
  51.          _loc3_.addResponder(this);
  52.       }
  53.       
  54.       public function feedback(param1:String, param2:String) : void
  55.       {
  56.          this.service.url = NavMapProxy.serverUrl + "users/feedbacks";
  57.          var _loc3_:Object = {};
  58.          _loc3_["feedback[component]"] = param1;
  59.          _loc3_["feedback[content]"] = param2;
  60.          var _loc4_:AsyncToken = this.service.send(_loc3_);
  61.          _loc4_.dataType = "feedback";
  62.          _loc4_.addResponder(this);
  63.       }
  64.       
  65.       private function sendQuestionnaireNote(param1:Object) : void
  66.       {
  67.          var _loc2_:String = param1.result.rss.channel.status;
  68.          this.sendNotification(ApplicationFacade.HIDE_QUESTIONNAIRE);
  69.       }
  70.       
  71.       public function result(param1:Object) : void
  72.       {
  73.          var authValid:String = null;
  74.          var dataType:String = null;
  75.          var rpcEvent:Object = param1;
  76.          try
  77.          {
  78.             authValid = rpcEvent.result.rss.channel.status;
  79.             dataType = rpcEvent.token.dataType;
  80.             if(authValid == "success")
  81.             {
  82.                switch(dataType)
  83.                {
  84.                   case "bookmark":
  85.                      this.sendNotification(ApplicationFacade.POST_BOOKMARK_SUCCESS);
  86.                      break;
  87.                   case "comment":
  88.                      this.sendNotification(ApplicationFacade.POST_COMMENT_SUCCESS);
  89.                      break;
  90.                   case "share":
  91.                      this.sendNotification(ApplicationFacade.POST_SHARE_SUCCESS);
  92.                      break;
  93.                   case "rate":
  94.                      this.sendNotification(ApplicationFacade.POST_RATING_SUCCESS);
  95.                      break;
  96.                   case "follow":
  97.                      this.sendNotification(ApplicationFacade.POST_FOLLOW_SUCCESS,rpcEvent.result.rss.channel.friend.id);
  98.                      break;
  99.                   case "shortcut":
  100.                      this.sendNotification(ApplicationFacade.POST_SHORTCUT_SUCCESS);
  101.                      break;
  102.                   case "feedback":
  103.                      this.sendNotification(ApplicationFacade.FEEDBACK_SUCCESS);
  104.                      break;
  105.                   case "editprofile":
  106.                      this.sendNotification(ApplicationFacade.EDIT_PROFILE_SUCCESS);
  107.                      break;
  108.                   case "changepassword":
  109.                      this.sendNotification(ApplicationFacade.CHANGE_PASSWORD_SUCCESS);
  110.                      break;
  111.                   case "recoverPassword":
  112.                      this.sendNotification(ApplicationFacade.PASSWORD_RECOVERY_SUCCESS);
  113.                      break;
  114.                   case "fbKeys":
  115.                      this.sendNotification(ApplicationFacade.FACEBOOK_KEYS_SUCCESS);
  116.                      break;
  117.                   case "questionnaire":
  118.                      this.sendQuestionnaireNote(rpcEvent);
  119.                      break;
  120.                   case "emailInvite":
  121.                      this.sendNotification(ApplicationFacade.EMAIL_INVITE_SUCCESS);
  122.                }
  123.             }
  124.             else
  125.             {
  126.                if(rpcEvent.result.rss.channel.error == "invalid session")
  127.                {
  128.                   this.sendNotification(ApplicationFacade.LOGOUT);
  129.                }
  130.                switch(dataType)
  131.                {
  132.                   case "bookmark":
  133.                      this.sendNotification(ApplicationFacade.POST_BOOKMARK_FAILURE);
  134.                      break;
  135.                   case "comment":
  136.                      this.sendNotification(ApplicationFacade.POST_COMMENT_FAILURE);
  137.                      break;
  138.                   case "share":
  139.                      this.sendNotification(ApplicationFacade.POST_SHARE_FAILURE);
  140.                      break;
  141.                   case "rate":
  142.                      this.sendNotification(ApplicationFacade.POST_RATING_FAILURE);
  143.                      break;
  144.                   case "follow":
  145.                      this.sendNotification(ApplicationFacade.POST_FOLLOW_FAILURE);
  146.                      break;
  147.                   case "shortcut":
  148.                      this.sendNotification(ApplicationFacade.POST_SHORTCUT_FAILURE);
  149.                      break;
  150.                   case "feedback":
  151.                      this.sendNotification(ApplicationFacade.FEEDBACK_FAILURE);
  152.                      break;
  153.                   case "editprofile":
  154.                      this.sendNotification(ApplicationFacade.EDIT_PROFILE_FAILURE);
  155.                      break;
  156.                   case "changepassword":
  157.                      this.sendNotification(ApplicationFacade.CHANGE_PASSWORD_FAILURE);
  158.                      break;
  159.                   case "recoverPassword":
  160.                      this.sendNotification(ApplicationFacade.PASSWORD_RECOVERY_FAILURE);
  161.                      break;
  162.                   case "fbKeys":
  163.                      this.sendNotification(ApplicationFacade.FACEBOOK_KEYS_FAILURE);
  164.                      break;
  165.                   case "questionnaire":
  166.                      this.sendNotification(ApplicationFacade.QUESTIONNAIRE_FAILURE);
  167.                      break;
  168.                   case "emailInvite":
  169.                      this.sendNotification(ApplicationFacade.EMAIL_INVITE_FAILURE);
  170.                }
  171.             }
  172.          }
  173.          catch(errObj:Error)
  174.          {
  175.             trace(errObj.message);
  176.          }
  177.       }
  178.       
  179.       public function recoverPassword(param1:String) : void
  180.       {
  181.          var _loc2_:Object = new Object();
  182.          this.service.url = NavMapProxy.serverUrl + "/users/passwords/reset";
  183.          _loc2_["login"] = param1;
  184.          var _loc3_:AsyncToken = this.service.send(_loc2_);
  185.          _loc3_.dataType = "recoverPassword";
  186.          _loc3_.addResponder(this);
  187.       }
  188.       
  189.       public function rate(param1:String, param2:Number) : void
  190.       {
  191.          this.service.url = NavMapProxy.serverUrl + "users/rated/videos/" + param1;
  192.          var _loc3_:Object = {};
  193.          _loc3_["rate[value]"] = param2;
  194.          var _loc4_:AsyncToken = this.service.send(_loc3_);
  195.          _loc4_.dataType = "rate";
  196.          _loc4_.addResponder(this);
  197.       }
  198.       
  199.       public function createShortcut(param1:String) : void
  200.       {
  201.          this.service.url = NavMapProxy.serverUrl + "users/shortcuts";
  202.          var _loc2_:Object = {};
  203.          _loc2_["shortcut[path]"] = param1;
  204.          var _loc3_:AsyncToken = this.service.send(_loc2_);
  205.          _loc3_.dataType = "shortcut";
  206.          _loc3_.addResponder(this);
  207.       }
  208.       
  209.       public function postComment(param1:String, param2:String) : void
  210.       {
  211.          this.service.url = NavMapProxy.serverUrl + "users/commented/videos/" + param1;
  212.          var _loc3_:Object = {};
  213.          _loc3_["comment[comment]"] = param2;
  214.          var _loc4_:AsyncToken = this.service.send(_loc3_);
  215.          _loc4_.dataType = "comment";
  216.          _loc4_.addResponder(this);
  217.       }
  218.       
  219.       public function fault(param1:Object) : void
  220.       {
  221.          var _loc2_:Fault = FaultEvent(param1).fault;
  222.          var _loc3_:String = param1.token.dataType;
  223.          switch(_loc3_)
  224.          {
  225.             case "bookmark":
  226.                this.sendNotification(ApplicationFacade.POST_BOOKMARK_TIMEOUT);
  227.                break;
  228.             case "comment":
  229.                this.sendNotification(ApplicationFacade.POST_COMMENT_TIMEOUT);
  230.                break;
  231.             case "share":
  232.                this.sendNotification(ApplicationFacade.POST_SHARE_TIMEOUT);
  233.                break;
  234.             case "rate":
  235.                this.sendNotification(ApplicationFacade.POST_RATING_TIMEOUT);
  236.                break;
  237.             case "follow":
  238.                this.sendNotification(ApplicationFacade.POST_FOLLOW_TIMEOUT);
  239.                break;
  240.             case "shortcut":
  241.                this.sendNotification(ApplicationFacade.POST_SHORTCUT_TIMEOUT);
  242.                break;
  243.             case "feedback":
  244.                this.sendNotification(ApplicationFacade.FEEDBACK_TIMEOUT);
  245.                break;
  246.             case "editprofile":
  247.                this.sendNotification(ApplicationFacade.EDIT_PROFILE_TIMEOUT);
  248.                break;
  249.             case "changepassword":
  250.                this.sendNotification(ApplicationFacade.CHANGE_PASSWORD_TIMEOUT);
  251.                break;
  252.             case "recoverPassword":
  253.                this.sendNotification(ApplicationFacade.PASSWORD_RECOVERY_FAILURE);
  254.                break;
  255.             case "fbKeys":
  256.                this.sendNotification(ApplicationFacade.FACEBOOK_KEYS_FAILURE);
  257.                break;
  258.             case "questionnaire":
  259.                this.sendNotification(ApplicationFacade.QUESTIONNAIRE_TIMEOUT);
  260.                break;
  261.             case "emailInvite":
  262.                this.sendNotification(ApplicationFacade.EMAIL_INVITE_TIMEOUT);
  263.          }
  264.          var _loc4_:ApplicationError = new ApplicationError(LogEventLevel.ERROR,9000,"authError");
  265.          sendNotification(ApplicationFacade.ERROR,_loc4_,"authError");
  266.       }
  267.       
  268.       public function changePassword(param1:String, param2:String) : void
  269.       {
  270.          var _loc3_:Object = new Object();
  271.          this.service.url = NavMapProxy.serverUrl + "/users/profile";
  272.          _loc3_["type"] = "password_edit";
  273.          _loc3_["user[verify_password]"] = param1;
  274.          _loc3_["user[new_password]"] = param2;
  275.          var _loc4_:AsyncToken = this.service.send(_loc3_);
  276.          _loc4_.dataType = "changepassword";
  277.          _loc4_.addResponder(this);
  278.       }
  279.       
  280.       public function videoViewed(param1:String, param2:int) : void
  281.       {
  282.          this.service.url = NavMapProxy.serverUrl + "users/viewed/videos/" + param1;
  283.          var _loc3_:Object = new Object();
  284.          _loc3_["view[privacy]"] = param2.toString();
  285.          var _loc4_:AsyncToken = this.service.send(_loc3_);
  286.          _loc4_.dataType = "videoviewed";
  287.          _loc4_.addResponder(this);
  288.       }
  289.       
  290.       protected function onPublishPost(param1:FacebookEvent) : void
  291.       {
  292.          trace("Facebook: Post published");
  293.          this.sendNotification(ApplicationFacade.POST_SHARE_SUCCESS);
  294.       }
  295.       
  296.       public function follow(param1:Number) : void
  297.       {
  298.          this.service.url = NavMapProxy.serverUrl + "users/connections/" + param1.toString();
  299.          var _loc2_:Object = {};
  300.          _loc2_["temp"] = "";
  301.          var _loc3_:AsyncToken = this.service.send(_loc2_);
  302.          _loc3_.dataType = "follow";
  303.          _loc3_.addResponder(this);
  304.       }
  305.       
  306.       public function share(param1:String, param2:String, param3:Boolean) : void
  307.       {
  308.          this.service.url = NavMapProxy.serverUrl + "users/shared/videos/" + param1;
  309.          var _loc4_:Object = {};
  310.          _loc4_["share[note]"] = param2;
  311.          _loc4_["share_on_fb"] = param3.toString();
  312.          var _loc5_:AsyncToken = this.service.send(_loc4_);
  313.          _loc5_.dataType = "share";
  314.          _loc5_.addResponder(this);
  315.       }
  316.       
  317.       public function sendFbKeys(param1:String, param2:String, param3:String) : void
  318.       {
  319.          var _loc4_:Object = new Object();
  320.          this.service.url = NavMapProxy.serverUrl + "/users/fb_info/extended_permissions";
  321.          _loc4_["fb_info[session_secret]"] = param1;
  322.          _loc4_["fb_info[session_key]"] = param2;
  323.          _loc4_["fb_info[uid]"] = param3;
  324.          var _loc5_:AsyncToken = this.service.send(_loc4_);
  325.          _loc5_.dataType = "fbKeys";
  326.          _loc5_.addResponder(this);
  327.       }
  328.       
  329.       public function sendQuestionnaire(param1:Array) : void
  330.       {
  331.          this.service.url = NavMapProxy.serverUrl + "users/fav_categories";
  332.          var _loc2_:Object = {};
  333.          _loc2_["fav_categories"] = param1.toString();
  334.          var _loc3_:AsyncToken = this.service.send(_loc2_);
  335.          _loc3_.dataType = "questionnaire";
  336.          _loc3_.addResponder(this);
  337.       }
  338.       
  339.       public function bookmark(param1:String, param2:String, param3:int) : void
  340.       {
  341.          this.service.url = NavMapProxy.serverUrl + "users/bookmarked/videos/" + param1;
  342.          var _loc4_:Object = {};
  343.          _loc4_["bookmark[tags]"] = param2;
  344.          _loc4_["bookmark[privacy]"] = param3.toString();
  345.          var _loc5_:AsyncToken = this.service.send(_loc4_);
  346.          _loc5_.dataType = "bookmark";
  347.          _loc5_.addResponder(this);
  348.       }
  349.       
  350.       public function editProfile(param1:Object) : void
  351.       {
  352.          this.service.url = NavMapProxy.serverUrl + "/users/profile";
  353.          param1["type"] = "info_edit";
  354.          var _loc2_:AsyncToken = this.service.send(param1);
  355.          _loc2_.dataType = "editprofile";
  356.          _loc2_.addResponder(this);
  357.       }
  358.    }
  359. }
  360.  
  361.