OSDN Git Service

7782a0acb0c3f923c0bff2540508995beea800e2
[kcd/KCD.git] / KCD / NyukyoDockMapper.swift
1 //
2 //  NyukyoDockMapper.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/02/24.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 final class NyukyoDockMapper: JSONMapper {
12     
13     let apiResponse: APIResponse
14     let configuration: MappingConfiguration<NyukyoDock>
15     
16     required init(_ apiResponse: APIResponse) {
17         
18         self.apiResponse = apiResponse
19         self.configuration = MappingConfiguration(entity: NyukyoDock.entity,
20                                                   dataKeys: NyukyoDockMapper.dataKeys(apiResponse),
21                                                   editorStore: ServerDataStore.oneTimeEditor())
22     }
23     
24     
25     private enum DeckAPI: String {
26         
27         case getMemberNDock = "/kcsapi/api_get_member/ndock"
28         case port = "/kcsapi/api_port/port"
29     }
30     
31     private class func dataKeys(_ apiResponse: APIResponse) -> [String] {
32         
33         guard let deckApi = DeckAPI(rawValue: apiResponse.api) else { return ["api_data"] }
34         
35         switch deckApi {
36         case .port: return ["api_data", "api_ndock"]
37             
38         case .getMemberNDock: return ["api_data"]
39         }
40     }
41 }