OSDN Git Service

CoreDataの不要なプロパティを削除
[kcd/KCD.git] / KCD / NyukyoDockMapper.swift
index 2f1481c..1ee4a0d 100644 (file)
@@ -8,30 +8,33 @@
 
 import Cocoa
 
-fileprivate enum DeckAPI: String {
-    case getMemberNDock = "/kcsapi/api_get_member/ndock"
-    case port = "/kcsapi/api_port/port"
-}
-
-fileprivate func dataKey(_ apiResponse: APIResponse) -> String {
-    guard let deckApi = DeckAPI(rawValue: apiResponse.api)
-        else { return "api_data" }
-    switch deckApi {
-    case .port: return "api_data.api_ndock"
-    default: return "api_data"
-    }
-}
-
-class NyukyoDockMapper: JSONMapper {
-    typealias ObjectType = NyukyoDock
-
+final class NyukyoDockMapper: JSONMapper {
+    
     let apiResponse: APIResponse
     let configuration: MappingConfiguration<NyukyoDock>
     
     required init(_ apiResponse: APIResponse) {
+        
         self.apiResponse = apiResponse
-        self.configuration = MappingConfiguration(entity: NyukyoDock.entity,
-                                                  dataKey: dataKey(apiResponse),
-                                                  editorStore: ServerDataStore.oneTimeEditor())
+        self.configuration = MappingConfiguration(entity: NyukyoDock.self,
+                                                  dataKeys: NyukyoDockMapper.dataKeys(apiResponse),
+                                                  editorStore: ServerDataStore.oneTimeEditor(),
+                                                  ignoreKeys: ["api_member_id"])
+    }
+    
+    private class func dataKeys(_ apiResponse: APIResponse) -> [String] {
+        
+        switch apiResponse.api.endpoint {
+            
+        case .port: return ["api_data", "api_ndock"]
+            
+        case .ndock: return ["api_data"]
+            
+        default:
+            
+            Logger.shared.log("Missing API: \(apiResponse.api)")
+            
+            return ["api_data"]
+        }
     }
 }