Move getAccessToken logic to the connection
authorAndy Allan <gravitystorm@gmail.com>
Tue, 19 Oct 2010 10:10:18 +0000 (10:10 +0000)
committerAndy Allan <gravitystorm@gmail.com>
Tue, 19 Oct 2010 10:10:18 +0000 (10:10 +0000)
net/systemeD/halcyon/connection/Connection.as
net/systemeD/halcyon/connection/XMLConnection.as
net/systemeD/potlatch2/save/SaveManager.as

index a2bbc68..22696c9 100755 (executable)
@@ -6,6 +6,7 @@ package net.systemeD.halcyon.connection {
     import flash.events.Event;
        import net.systemeD.halcyon.Globals;
        import net.systemeD.halcyon.connection.actions.*;
+    import org.iotashan.oauth.*;
 
        public class Connection extends EventDispatcher {
 
@@ -366,6 +367,7 @@ package net.systemeD.halcyon.connection {
            public function uploadChanges():void {}
         public function fetchUserTraces(refresh:Boolean=false):void {}
         public function fetchTrace(id:Number, callback:Function):void {}
+        public function getAccessToken(data:Object):OAuthToken { return null; } //todo make private and remove import org.ioshtan etc
     }
 
 }
index 30d3915..951f083 100644 (file)
@@ -60,6 +60,22 @@ package net.systemeD.halcyon.connection {
                authToken = OAuthToken(id);
            }
 
+        override public function getAccessToken(data:Object):OAuthToken {
+            var key:String = Connection.getParam("oauth_token", null);
+            var secret:String = Connection.getParam("oauth_token_secret", null);
+
+            if ( key == null || secret == null ) {
+                //var data:Object = SharedObject.getLocal("access_token").data;
+                key = data["oauth_token"];
+                secret = data["oauth_token_secret"];
+            }
+
+            if ( key == null || secret == null )
+                return null;
+            else
+                return new OAuthToken(key, secret);
+        }
+
         private var httpStatus:int = 0;
         
         private function recordStatus(event:HTTPStatusEvent):void {
index 1a72797..77e4f33 100644 (file)
@@ -30,10 +30,11 @@ package net.systemeD.potlatch2.save {
         }
 
         private function save(callback:Function):void {
+            var conn:Connection = Connection.getConnectionInstance();
             if ( consumer == null )
                 consumer = getConsumer();
             if ( accessToken == null )
-                accessToken = getAccessToken();
+                accessToken = conn.getAccessToken(SharedObject.getLocal("access_token").data);
         
             if ( accessToken == null )
                 getNewToken(callback);
@@ -41,22 +42,6 @@ package net.systemeD.potlatch2.save {
                 callback();
         }
 
-        private function getAccessToken():OAuthToken {
-            var key:String = Connection.getParam("oauth_token", null);
-            var secret:String = Connection.getParam("oauth_token_secret", null);
-            
-            if ( key == null || secret == null ) {
-                var data:Object = SharedObject.getLocal("access_token").data;
-                key = data["oauth_token"];
-                secret = data["oauth_token_secret"];
-            }
-            
-            if ( key == null || secret == null )
-                return null;
-            else    
-                return new OAuthToken(key, secret);
-        }
-
         private function getConsumer():OAuthConsumer {
             var key:String = Connection.getParam("oauth_consumer_key", null);
             var secret:String = Connection.getParam("oauth_consumer_secret", null);