Commits

Anonymous committed a0aa8e7

new branch

Comments (0)

Files changed (16)

as3snapi-core/as3snapi-core.iml

     <configurations>
       <configuration name="as3snapi-core" output-type="Library" output-file="as3snapi-core.swc" output-folder="/srv/www/production/as3snapi-core">
         <dependencies target-player="11.1">
-          <sdk name="flex_sdk" />
+          <sdk name="4.5" />
         </dependencies>
         <compiler-options />
         <packaging-air-desktop />
       <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
     </content>
     <orderEntry type="sourceFolder" forTests="false" />
-    <orderEntry type="jdk" jdkName="flex_sdk" jdkType="__CompositeFlexSdk__" />
+    <orderEntry type="jdk" jdkName="4.5" jdkType="__CompositeFlexSdk__" />
   </component>
 </module>
 

as3snapi-core/pom.xml

     <parent>
         <groupId>as3snapi</groupId>
         <artifactId>as3snapi</artifactId>
-        <version>1.0.5-SNAPSHOT</version>
+        <version>1.0.6-SNAPSHOT</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
 
     </build>
 
     <dependencies>
-        <!--
-        <dependency>
-            <groupId>drewbourne</groupId>
-            <artifactId>mockolate-as3</artifactId>
-            <version>0.12.2</version>
-            <type>swc</type>
-            <scope>test</scope>
-        </dependency>
 
-        <dependency>
-            <groupId>drewbourne</groupId>
-            <artifactId>hamcrest-as3</artifactId>
-            <version>1.1.3</version>
-            <type>swc</type>
-            <scope>test</scope>
-        </dependency>
-        -->
     </dependencies>
 
 </project>

as3snapi-core/src/as3snapi/ConnectionFactory.as

 import as3snapi.base.features.requester.FeatureHttpRequester;
 import as3snapi.base.features.requester.IFeatureHttpRequester;
 import as3snapi.base.plugins.BusFactoryEvent;
-import as3snapi.base.plugins.IBusModule;
 import as3snapi.utils.EnumUtils;
-import as3snapi.utils.bus.BusImpl;
 import as3snapi.utils.bus.IMutableBus;
 
 import flash.utils.clearTimeout;
     private var flashVars:FlashVars;
     private var networkModules:Vector.<INetworkModule> = new <INetworkModule>[];
     private var networkConfigs:Vector.<INetworkConfig> = new <INetworkConfig>[];
-    private var busModules:Vector.<IBusModule> = new <IBusModule>[];
-
+    private var busFactory:IBusFactory;
 
     /**
      *
      * @param networkModules спсиок модулей для используемых соцсетей
      * @param busModules список модулей для навешивания дополнительных возможностей на шину
      */
-    public function ConnectionFactory(flashVars:* = null, networkConfigs:Vector.<INetworkConfig> = null, networkModules:Vector.<INetworkModule> = null, busModules:Vector.<IBusModule> = null) {
+    public function ConnectionFactory(flashVars:* = null, networkConfigs:Vector.<INetworkConfig> = null, networkModules:Vector.<INetworkModule> = null, busFactory:IBusFactory = null) {
         if (flashVars != null) {
             setFlashVars(flashVars);
         }
         if (networkConfigs != null) {
-            for each(var config:INetworkConfig in networkConfigs) {
-                installNetworkConfig(config);
-            }
+            this.networkConfigs = networkConfigs;
         }
         if (networkModules != null) {
-            for each(var module:INetworkModule in networkModules) {
-                installNetworkModule(module);
-            }
+            this.networkModules = networkModules;
         }
-        if (busModules != null) {
-            for each(var busModule:IBusModule in busModules) {
-                installBusModule(busModule);
-            }
-        }
+        this.busFactory = busFactory || new DefaultBusFactory()
     }
 
     public function setFlashVars(flashVars:*):void {
         return flashVars;
     }
 
-    public function installBusModule(busModule:IBusModule):void {
-        busModules.push(busModule);
-    }
-
-    public function installNetworkModule(networkModule:INetworkModule):void {
-        networkModules.push(networkModule);
-    }
-
-    public function installNetworkConfig(config:INetworkConfig):void {
-        networkConfigs.push(config);
-    }
-
-
     public function createConnection(handler:INetworkConnectHandler):void {
-        var bus:IMutableBus = new BusImpl();
-
-        // Pre configure  bus
-        var busModue:IBusModule;
-        for each (busModue in busModules) {
-            busModue.install(bus);
-        }
-
+        var bus:IMutableBus = busFactory.createBus();
         // Add default features
         bus.addFeatureIfNotExist(IFeatureEventDispatcher, new FeatureEventDispatcher());
         bus.addFeatureIfNotExist(IFeatureLog, new FeatureLogNULL());
         bus.addFeatureIfNotExist(IFeatureFlashVarsGetter, new FeatureFlashVarsGetter(flashVars, bus));
         bus.addFeatureIfNotExist(IFeatureHttpRequester, new FeatureHttpRequester(bus));
         bus.addFeatureIfNotExist(IFeatureJavaScript, new FeatureJavaScript(bus));
-
+        bus.dispatchEvent(new BusFactoryEvent(BusFactoryEvent.BASIC_FEATURES_ADDED));
+        // log
         logFlashVars(bus);
-
-        bus.dispatchEvent(new BusFactoryEvent(BusFactoryEvent.BASIC_FEATURES_ADDED));
-
         // Detect
-        for each(var config:INetworkConfig in networkConfigs) {
-            for each(var networkModule:INetworkModule in networkModules) {
+        for each(var networkModule:INetworkModule in networkModules) {
+            for each(var config:INetworkConfig in networkConfigs) {
                 var context:INetworkModuleContext = new NetworkModuleContext(bus, config);
                 if (networkModule.isAvailable(context)) {
                     bus.addFeatureIfNotExist(IFeatureConfigGetter, new FeatureConfig(config));
 
     private function logFlashVars(bus:IMutableBus):void {
         var log:IFeatureLog = bus.getFeature(IFeatureLog);
-        log.log("FlashVars: ");
-        log.log("" + flashVars);
+        log.log("FlashVars: " + flashVars);
     }
 
     private function logFeatures(bus:IMutableBus):void {

as3snapi-core/src/as3snapi/DefaultBusFactory.as

+/**
+ * @author nitrobin
+ */
+package as3snapi {
+import as3snapi.base.plugins.IBusModule;
+import as3snapi.utils.bus.BusImpl;
+import as3snapi.utils.bus.IMutableBus;
+
+public class DefaultBusFactory implements IBusFactory {
+    private var busModules:Vector.<IBusModule> = new <IBusModule>[];
+
+    public function DefaultBusFactory(busModules:Vector.<IBusModule> = null) {
+        if (busModules != null) {
+            for each(var busModule:IBusModule in busModules) {
+                this.busModules.push(busModule);
+            }
+        }
+    }
+
+    public function createBus():IMutableBus {
+        var bus:IMutableBus = new BusImpl();
+        var busModue:IBusModule;
+        for each (busModue in busModules) {
+            busModue.install(bus);
+        }
+        return bus;
+    }
+}
+}

as3snapi-core/src/as3snapi/IBusFactory.as

+/**
+ * @author nitrobin
+ */
+package as3snapi {
+import as3snapi.utils.bus.IMutableBus;
+
+public interface IBusFactory {
+    function createBus():IMutableBus;
+}
+}

as3snapi-core/src/as3snapi/base/features/flashvars/FlashVars.as

         return defaultValue;
     }
 
+    public function getInt(key:String, defaultValue:int = 0):int {
+        if (key in flashVars) {
+            try {
+                return int(flashVars[key]);
+            } catch (e:Error) {
+                return defaultValue;
+            }
+        }
+        return defaultValue;
+    }
+
     public function toString():String {
         return JsonUtils.encode(flashVars);
     }

as3snapi-core/src/as3snapi/networks/mock/ConfigMock.as

  * Настройки для оффлайновой mock-сети на основе заранее подготовленных данных
  */
 public class ConfigMock extends NetworkConfigBase implements INetworkConfig {
-    private var data:Object;
-    private var dataUrl:String;
+    private var snapshot:Object;
+    private var snapshotUrl:String;
+    private var available:Boolean = true;
 
     public function ConfigMock() {
     }
 
-    public function setData(data:Object):ConfigMock {
-        this.data = data;
+    public function setSnapshot(snapshot:Object):ConfigMock {
+        this.snapshot = snapshot;
         return this;
     }
 
-    public function getData():Object {
-        return data;
+    public function getSnapshot():Object {
+        return snapshot;
     }
 
-    public function setDataUrl(dataUrl:String):ConfigMock {
-        this.dataUrl = dataUrl;
+    /**
+     * Урл JSON файла со снимком для соц сети
+     * @param snapshotUrl
+     * @return
+     */
+    public function setSnapshotUrl(snapshotUrl:String):ConfigMock {
+        this.snapshotUrl = snapshotUrl;
         return this;
     }
 
     public function getDataUrl():String {
-        return dataUrl;
+        return snapshotUrl;
     }
 
+    public function setAvailable(available:Boolean):ConfigMock {
+        this.available = available;
+        return this;
+    }
+
+    public function isAvailable():Boolean {
+        return available;
+    }
 }
 }

as3snapi-core/src/as3snapi/networks/mock/ModuleMock.as

 
     public function isAvailable(context:INetworkModuleContext):Boolean {
         var flashVars:FlashVars = context.getFlashVars();
-        return flashVars.isEmpty() && (context.getConfig() is ConfigMock);
+        var config:ConfigMock = context.getConfig() as ConfigMock;
+        return (config != null) && config.isAvailable();
     }
 
     public function install(context:INetworkModuleContext):void {
         var bus:IMutableBus = context.getBus();
-
         var api:MockApiImpl = new MockApiImpl(context);
         bus.addFeature(IFeatureMockApi, api);
         SocialFeaturesInstallHelper.installBasicFeatures(bus, api);

as3snapi-core/src/as3snapi/networks/mock/SnapshotBuilder.as

+/**
+ * @author nitrobin
+ */
+package as3snapi.networks.mock {
+public class SnapshotBuilder {
+    private var snapshot:Object;
+
+    public function SnapshotBuilder(snapshot:Object = null) {
+        this.snapshot = snapshot || {};
+    }
+
+    public function build():Object {
+        return snapshot;
+    }
+
+    public function setShortNetworkId(shortNetworkId:String):SnapshotBuilder {
+        snapshot.shortNetworkId = shortNetworkId;
+        return this;
+    }
+
+    public function setUserId(userId:String):SnapshotBuilder {
+        snapshot.userId = userId;
+        setProfile(userId);
+        return this;
+    }
+
+    public function setInviterId(inviterId:String):SnapshotBuilder {
+        snapshot.inviterId = inviterId;
+        setProfile(inviterId);
+        return this;
+    }
+
+    public function setAppId(appId:String):SnapshotBuilder {
+        snapshot.appId = appId;
+        return this;
+    }
+
+    public function setAppFriendsUids(appFriendsUids:Array):SnapshotBuilder {
+        snapshot.appFriendsUids = appFriendsUids;
+        for each(var uid:String in appFriendsUids) {
+            setProfile(uid);
+        }
+        return this;
+    }
+
+    public function setFriendsUids(friendsUids:Array):SnapshotBuilder {
+        snapshot.friendsUids = friendsUids;
+        for each(var uid:String in friendsUids) {
+            setProfile(uid);
+        }
+        return this;
+    }
+
+    public function setProfile(userId:String, fullName:String = null):SnapshotBuilder {
+        var profiles:Object = snapshot.profiles || {};
+        profiles[userId] = {
+            userId:userId,
+            fullName:fullName || ("user" + userId)
+        };
+        snapshot.profiles = profiles;
+        return this;
+    }
+
+    public static function helloWorld():SnapshotBuilder {
+        return new SnapshotBuilder()
+                .setShortNetworkId("mock")
+                .setUserId("1")
+                .setInviterId("2")
+                .setFriendsUids(["2", "3", "4"])
+                .setAppFriendsUids(["2", "3"]);
+    }
+
+}
+}

as3snapi-core/src/as3snapi/networks/mock/features/IFeatureMockApi.as

 package as3snapi.networks.mock.features {
 public interface IFeatureMockApi {
-    function getMockaData():Object;
+    function getMockSnapshot():Object;
 }
 }

as3snapi-core/src/as3snapi/networks/mock/impl/MockApiImpl.as

         IFeatureFriendUids,
         IFeatureAsyncInit {
     private var config:ConfigMock;
-    private var data:Object;
+    private var snapshot:Object;
 
     private var httpRequester:IFeatureHttpRequester;
 
     public function MockApiImpl(context:INetworkModuleContext) {
         this.config = ConfigMock(context.getConfig());
-        this.data = config.getData();
+        this.snapshot = config.getSnapshot();
         this.httpRequester = context.getHttpRequester();
     }
 
     public function getShortNetworkId():String {
-        return data.shortNetworkId;
+        return snapshot.shortNetworkId;
     }
 
     public function getAppId():String {
-        return data.appId;
+        return snapshot.appId;
     }
 
     public function getUserId():String {
-        return data.userId;
+        return snapshot.userId;
     }
 
     public function getRefererId():String {
-        return data.refererId;
+        return snapshot.refererId;
     }
 
     public function getProfiles(uids:Array, handler:IProfilesHandler):void {
-        if (data.profiles) {
+        if (snapshot.profiles) {
             var profiles:Array = [];
             for each(var uid:String in uids) {
-                var u:Object = data.profiles[uid];
+                var u:Object = snapshot.profiles[uid];
                 profiles.push(parseProfile(u, uid));
             }
             handler.onSuccess(profiles);
     }
 
     public function getAppFriendUids(handler:IIdsHandler):void {
-        handler.onSuccess(data.appFriendsUids || []);
+        handler.onSuccess(snapshot.appFriendsUids || []);
     }
 
     public function getFriendUids(handler:IIdsHandler):void {
-        handler.onSuccess(data.friendsUids || []);
+        handler.onSuccess(snapshot.friendsUids || []);
     }
 
     public function init(handler:IAsyncInitHandler):void {
-        if (data == null) {
+        if (snapshot == null) {
             var dataUrl:String = config.getDataUrl();
             if (dataUrl == null) {
-                handler.onFail("Empty data")
+                handler.onFail("Empty snapshot")
             } else {
                 httpRequester.doRequestJson(dataUrl, null, URLRequestMethod.GET, function (r:Object):void {
-                    data = r;
+                    snapshot = r;
                     handler.onSuccess("ok");
                 }, function (r:Object):void {
                     handler.onFail(r);
         }
     }
 
-    public function getMockaData():Object {
-        return data;
+    public function getMockSnapshot():Object {
+        return snapshot;
     }
 }
 }

as3snapi-sandbox/as3snapi-sandbox.iml

               <dependency linkage="Merged" />
             </entry>
           </entries>
-          <sdk name="flex_sdk" />
+          <sdk name="4.5" />
         </dependencies>
         <compiler-options>
           <option name="additionalOptions" value="-static-link-runtime-shared-libraries=true" />
     </content>
     <orderEntry type="module" module-name="as3snapi-core" />
     <orderEntry type="sourceFolder" forTests="false" />
-    <orderEntry type="jdk" jdkName="flex_sdk" jdkType="__CompositeFlexSdk__" />
+    <orderEntry type="jdk" jdkName="4.5" jdkType="__CompositeFlexSdk__" />
   </component>
 </module>
 

as3snapi-sandbox/pom.xml

     <parent>
         <groupId>as3snapi</groupId>
         <artifactId>as3snapi</artifactId>
-        <version>1.0.5-SNAPSHOT</version>
+        <version>1.0.6-SNAPSHOT</version>
         <relativePath>../pom.xml</relativePath>
     </parent>
 

as3snapi-sandbox/src/HelloWorld.as

                 stage.loaderInfo.parameters, // Передача FlashVars
                 new <INetworkConfig>[ // Настройки соцсетей
                     new ConfigVkcom(),
-                    new ConfigMock().setData(MOCK_DATA), // Указываем снимок данных
+                    new ConfigMock().setSnapshot(MOCK_DATA), // Указываем снимок данных
                 ],
                 new <INetworkModule>[ // Подключение модулей соцсетей
                     new ModuleVkcom(),

as3snapi-sandbox/src/sandbox/AppController.as

 package sandbox {
 import as3snapi.ConnectionFactory;
+import as3snapi.DefaultBusFactory;
 import as3snapi.IConnectionFactory;
 import as3snapi.api.INetworkConnectHandler;
 import as3snapi.api.INetworkConnection;
 import as3snapi.networks.mock.ConfigMock;
 import as3snapi.networks.mock.MockDataCapture;
 import as3snapi.networks.mock.ModuleMock;
+import as3snapi.networks.mock.SnapshotBuilder;
 import as3snapi.networks.odnoklassnikiru.ConfigOdnoklassnikiru;
 import as3snapi.networks.odnoklassnikiru.ModuleOdnoklassnikiru;
 import as3snapi.networks.vkcom.ConfigVkcom;
 public class AppController implements INetworkConnectHandler {
     private var view:MainPanel;
     private var connection:INetworkConnection;
-    private var mockData:Object = {
-        shortNetworkId:"mock",
-        userId:1,
-        inviterId:2,
-        asppId:123,
-        profiles:{1:{fullName:"test1"}, 2:{fullName:"test1"}, 3:{fullName:"test1"}},
-        appFriendsUids:[2],
-        friendsUids:[2, 3]
-    };
 
     public function AppController(view:MainPanel) {
         this.view = view;
                     new ConfigMailru(props.MAILRU_PRIVATE_KEY),
                     new ConfigOdnoklassnikiru(props.ODNOKLASSNIKI_SECRET_KEY),
                     new ConfigFbcom(props.FACEBOOK_APP_ID),
-                    new ConfigMock().setData(mockData)//.setDataUrl("mock.json.html"),
+                    new ConfigMock().setSnapshot(SnapshotBuilder.helloWorld().build())//.setDataUrl("mock.json.html"),
                 ],
                 new <INetworkModule>[
                     new ModuleVkcom(),
                     new ModuleFbcom(),
                     new ModuleMock(),
                 ],
-                new <IBusModule>[
-                    new BusModuleLogHook(view.log, view.apiLog, view.eventLog)
-                ]
-        );
+                new DefaultBusFactory(
+                        new <IBusModule>[
+                            new BusModuleLogHook(view.log, view.apiLog, view.eventLog)
+                        ]));
         log("try connecting...");
         logLine();
         try {
     <modelVersion>4.0.0</modelVersion>
     <groupId>as3snapi</groupId>
     <artifactId>as3snapi</artifactId>
-    <version>1.0.5-SNAPSHOT</version>
+    <version>1.0.6-SNAPSHOT</version>
     <packaging>pom</packaging>
     <name>as3snapi - All</name>