OSDN Git Service

guard の書き方を統一した
[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     typealias ObjectType = NyukyoDock
14
15     let apiResponse: APIResponse
16     let configuration: MappingConfiguration<NyukyoDock>
17     
18     required init(_ apiResponse: APIResponse) {
19         
20         self.apiResponse = apiResponse
21         self.configuration = MappingConfiguration(entity: NyukyoDock.entity,
22                                                   dataKeys: NyukyoDockMapper.dataKeys(apiResponse),
23                                                   editorStore: ServerDataStore.oneTimeEditor())
24     }
25     
26     
27     private enum DeckAPI: String {
28         
29         case getMemberNDock = "/kcsapi/api_get_member/ndock"
30         case port = "/kcsapi/api_port/port"
31     }
32     
33     private class func dataKeys(_ apiResponse: APIResponse) -> [String] {
34         
35         guard let deckApi = DeckAPI(rawValue: apiResponse.api) else { return ["api_data"] }
36         
37         switch deckApi {
38         case .port: return ["api_data", "api_ndock"]
39             
40         case .getMemberNDock: return ["api_data"]
41         }
42     }
43 }