OSDN Git Service

MappingConfigurationのプロパティを変更
[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 fileprivate enum DeckAPI: String {
12     case getMemberNDock = "/kcsapi/api_get_member/ndock"
13     case port = "/kcsapi/api_port/port"
14 }
15
16 fileprivate func dataKeys(_ apiResponse: APIResponse) -> [String] {
17     guard let deckApi = DeckAPI(rawValue: apiResponse.api)
18         else { return ["api_data"] }
19     switch deckApi {
20     case .port: return ["api_data", "api_ndock"]
21     default: return ["api_data"]
22     }
23 }
24
25 class NyukyoDockMapper: JSONMapper {
26     typealias ObjectType = NyukyoDock
27
28     let apiResponse: APIResponse
29     let configuration: MappingConfiguration<NyukyoDock>
30     
31     required init(_ apiResponse: APIResponse) {
32         self.apiResponse = apiResponse
33         self.configuration = MappingConfiguration(entity: NyukyoDock.entity,
34                                                   dataKeys: dataKeys(apiResponse),
35                                                   editorStore: ServerDataStore.oneTimeEditor())
36     }
37 }