OSDN Git Service

2067dbb7239f73b4f6f0e661f70d343e3959cee5
[kcd/KCD.git] / KCD / KenzoDockMapper.swift
1 //
2 //  KenzoDockMapper.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/02/25.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 final class KenzoDockMapper: JSONMapper {
12         
13     let apiResponse: APIResponse
14     let configuration: MappingConfiguration<KenzoDock>
15     
16     required init(_ apiResponse: APIResponse) {
17         
18         self.apiResponse = apiResponse
19         self.configuration = MappingConfiguration(entity: KenzoDock.entity,
20                                                   dataKeys: KenzoDockMapper.dataKeys(apiResponse),
21                                                   editorStore: ServerDataStore.oneTimeEditor())
22     }
23     
24     private class func dataKeys(_ apiResponse: APIResponse) -> [String] {
25         
26         switch apiResponse.api.endpoint {
27             
28         case .getShip, .requireInfo: return ["api_data", "api_kdock"]
29                         
30         case .kdock: return ["api_data"]
31             
32         default:
33             
34             Logger.shared.log("Missing API: \(apiResponse.api)")
35             
36             return ["api_data"]
37         }
38     }
39 }