OSDN Git Service

Doutakuを導入
[kcd/KCD.git] / KCD / DeckMapper.swift
1 //
2 //  DeckMapper.swift
3 //  KCD
4 //
5 //  Created by Hori,Masaki on 2017/02/23.
6 //  Copyright © 2017年 Hori,Masaki. All rights reserved.
7 //
8
9 import Cocoa
10
11 final class DeckMapper: JSONMapper {
12         
13     let apiResponse: APIResponse
14     let configuration: MappingConfiguration<Deck>
15     
16     required init(_ apiResponse: APIResponse) {
17         
18         self.apiResponse = apiResponse
19         self.configuration = MappingConfiguration(entity: Deck.entity,
20                                                   dataKeys: DeckMapper.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 .port: return ["api_data", "api_deck_port"]
29             
30         case .ship3, .shipDeck: return ["api_data", "api_deck_data"]
31             
32         case .ship2: return ["api_data_deck"]
33             
34         case .powerup: return ["api_data", "api_deck"]
35             
36         case .deck, .deckPort, .presetSelect: return ["api_data"]
37             
38         default: return Logger.shared.log("Missing API: \(apiResponse.api)", value: ["api_data"])
39         }
40     }
41 }