OSDN Git Service

BasicMapperを作成
authormasakih <masakih@users.sourceforge.jp>
Fri, 24 Feb 2017 14:19:44 +0000 (23:19 +0900)
committermasakih <masakih@users.sourceforge.jp>
Fri, 24 Feb 2017 14:19:44 +0000 (23:19 +0900)
KCD.xcodeproj/project.pbxproj
KCD/BasicMapper.swift [new file with mode: 0644]
KCD/HMMemberBasicCommand.swift

index 07b2a93..f68c432 100644 (file)
                F47C3EB01E60500700D97449 /* MaterialMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47C3EAF1E60500700D97449 /* MaterialMapper.swift */; };
                F47C3EB21E60616E00D97449 /* NyukyoDockMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47C3EB11E60616E00D97449 /* NyukyoDockMapper.swift */; };
                F47C3EB41E606C4300D97449 /* ResetSortie.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47C3EB31E606C4300D97449 /* ResetSortie.swift */; };
+               F47C3EB61E60766000D97449 /* BasicMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = F47C3EB51E60766000D97449 /* BasicMapper.swift */; };
                F490977B1E19C3910085A45D /* HMSuppliesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F490977A1E19C3910085A45D /* HMSuppliesView.swift */; };
                F490977D1E19DF390085A45D /* HMSlotItemFrameView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F490977C1E19DF390085A45D /* HMSlotItemFrameView.swift */; };
                F490977F1E19ED400085A45D /* HMStrengthenListItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F490977E1E19ED400085A45D /* HMStrengthenListItemView.swift */; };
                F47C3EAF1E60500700D97449 /* MaterialMapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MaterialMapper.swift; sourceTree = "<group>"; };
                F47C3EB11E60616E00D97449 /* NyukyoDockMapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NyukyoDockMapper.swift; sourceTree = "<group>"; };
                F47C3EB31E606C4300D97449 /* ResetSortie.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ResetSortie.swift; sourceTree = "<group>"; };
+               F47C3EB51E60766000D97449 /* BasicMapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicMapper.swift; sourceTree = "<group>"; };
                F490977A1E19C3910085A45D /* HMSuppliesView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSuppliesView.swift; sourceTree = "<group>"; };
                F490977C1E19DF390085A45D /* HMSlotItemFrameView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMSlotItemFrameView.swift; sourceTree = "<group>"; };
                F490977E1E19ED400085A45D /* HMStrengthenListItemView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HMStrengthenListItemView.swift; sourceTree = "<group>"; };
                                F47C3EA51E5F050D00D97449 /* MasterSlotItemMapper.swift */,
                                F47C3EA71E5F06E700D97449 /* MasterSlotItemEquipTypeMapper.swift */,
                                F47C3EA91E5F085B00D97449 /* MasterMissionMapper.swift */,
+                               F47C3EB51E60766000D97449 /* BasicMapper.swift */,
                                F47C3EAB1E5F1AD900D97449 /* ShipMapper.swift */,
                                F47C3EAD1E5F26E900D97449 /* DeckMapper.swift */,
                                F47C3EAF1E60500700D97449 /* MaterialMapper.swift */,
                                F44BC71D1E29DF32004644E3 /* HMMemberNDockCommand.swift in Sources */,
                                F42CFE1E1E3CCCC2000B4F9B /* HMKCResource.swift in Sources */,
                                F4D05BCE1E0D50D300688D66 /* HMBrowserContentAdjuster.swift in Sources */,
+                               F47C3EB61E60766000D97449 /* BasicMapper.swift in Sources */,
                                F4D05BD01E0D667600688D66 /* HMBookmarkListViewController.swift in Sources */,
                                F44BC6C51E222279004644E3 /* HMPortNotifyCommand.swift in Sources */,
                                F4D05BD71E0F696C00688D66 /* HMRepairListViewController.swift in Sources */,
diff --git a/KCD/BasicMapper.swift b/KCD/BasicMapper.swift
new file mode 100644 (file)
index 0000000..ce124c2
--- /dev/null
@@ -0,0 +1,46 @@
+//
+//  BasicMapper.swift
+//  KCD
+//
+//  Created by Hori,Masaki on 2017/02/24.
+//  Copyright © 2017年 Hori,Masaki. All rights reserved.
+//
+
+import Cocoa
+
+fileprivate enum BasicAPI: String {
+    case getMemberBasic = "/kcsapi/api_get_member/basic"
+    case port = "/kcsapi/api_port/port"
+}
+
+fileprivate func dataKey(_ apiResponse: HMAPIResponse) -> String {
+    guard let basicApi = BasicAPI(rawValue: apiResponse.api)
+        else { return "api_data" }
+    switch basicApi {
+    case .port: return "api_data.api_basic"
+    default: return "api_data"
+    }
+}
+
+class BasicMapper: JSONMapper {
+    required init(_ apiResponse: HMAPIResponse) {
+        self.apiResponse = apiResponse
+        self.configuration = MappingConfiguration(entityName: "Basic",
+                                                  dataKey: dataKey(apiResponse),
+                                                  editorStore: HMServerDataStore.oneTimeEditor())
+    }
+    
+    let apiResponse: HMAPIResponse
+    let configuration: MappingConfiguration
+    
+    func commit() {
+        let j = apiResponse.json as NSDictionary
+        guard let data = j.value(forKeyPath: configuration.dataKey) as? [String:Any]
+            else { return print("json is wrong") }
+        
+        let store = HMServerDataStore.oneTimeEditor()
+        guard let basic = store.basic() ?? store.createBasic()
+            else { return print("Can not Get Basic") }
+        registerElement(data, to: basic)
+    }
+}
index f98000d..457d402 100644 (file)
@@ -20,13 +20,14 @@ class HMMemberBasicCommand: HMJSONCommand {
         return "api_data.api_basic"
     }
     override func execute() {
-        let j = json as NSDictionary
-        guard let data = j.value(forKeyPath: dataKey) as? [String:Any]
-            else { return print("json is wrong") }
-        
-        let store = HMServerDataStore.oneTimeEditor()
-        guard let basic = store.basic() ?? store.createBasic()
-            else { return print("Can not Get Basic") }
-        registerElement(data, to: basic)
+//        let j = json as NSDictionary
+//        guard let data = j.value(forKeyPath: dataKey) as? [String:Any]
+//            else { return print("json is wrong") }
+//        
+//        let store = HMServerDataStore.oneTimeEditor()
+//        guard let basic = store.basic() ?? store.createBasic()
+//            else { return print("Can not Get Basic") }
+//        registerElement(data, to: basic)
+        BasicMapper(apiResponse).commit()
     }
 }