5 // Created by Hori,Masaki on 2017/02/24.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 fileprivate enum BasicAPI: String {
12 case getMemberBasic = "/kcsapi/api_get_member/basic"
13 case port = "/kcsapi/api_port/port"
16 fileprivate func dataKey(_ apiResponse: APIResponse) -> String {
17 guard let basicApi = BasicAPI(rawValue: apiResponse.api)
18 else { return "api_data" }
20 case .port: return "api_data.api_basic"
21 default: return "api_data"
25 class BasicMapper: JSONMapper {
26 typealias ObjectType = Basic
28 let apiResponse: APIResponse
29 let configuration: MappingConfiguration<Basic>
31 required init(_ apiResponse: APIResponse) {
32 self.apiResponse = apiResponse
33 self.configuration = MappingConfiguration(entity: Basic.entity,
34 dataKey: dataKey(apiResponse),
35 editorStore: ServerDataStore.oneTimeEditor())
39 let j = apiResponse.json as NSDictionary
40 guard let data = j.value(forKeyPath: configuration.dataKey) as? [String: Any]
41 else { return print("json is wrong") }
43 let store = ServerDataStore.oneTimeEditor()
44 guard let basic = store.basic() ?? store.createBasic()
45 else { return print("Can not Get Basic") }
46 registerElement(data, to: basic)