OSDN Git Service

コード整形
[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 fileprivate enum KenzoDockAPI: String {
12     
13     case getMemberKDock = "/kcsapi/api_get_member/kdock"
14     case kousyouGetShip = "/kcsapi/api_req_kousyou/getship"
15     case getMemberRequireInfo = "/kcsapi/api_get_member/require_info"
16 }
17
18 fileprivate func dataKeys(_ apiResponse: APIResponse) -> [String] {
19     
20     guard let kenzoDockApi = KenzoDockAPI(rawValue: apiResponse.api)
21         else { return ["api_data"] }
22     
23     switch kenzoDockApi {
24     case .kousyouGetShip: return ["api_data", "api_kdock"]
25         
26     case .getMemberRequireInfo: return ["api_data", "api_kdock"]
27         
28     default: return ["api_data"]
29     }
30 }
31
32 final class KenzoDockMapper: JSONMapper {
33     
34     typealias ObjectType = KenzoDock
35     
36     let apiResponse: APIResponse
37     let configuration: MappingConfiguration<KenzoDock>
38     
39     required init(_ apiResponse: APIResponse) {
40         
41         self.apiResponse = apiResponse
42         self.configuration = MappingConfiguration(entity: KenzoDock.entity,
43                                                   dataKeys: dataKeys(apiResponse),
44                                                   editorStore: ServerDataStore.oneTimeEditor())
45     }
46 }