2 // CombinedCommand.swift
5 // Created by Hori,Masaki on 2017/01/09.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 enum CombineType: Int {
18 extension Notification.Name {
19 static let CombinedDidCange = Notification.Name("com.masakih.KCD.Notification.CombinedDidCange")
22 class CombinedCommand: JSONCommand {
23 static let userInfoKey = "com.masakih.KCD.Notification.CombinedDidCange.CombinedType"
24 override class func canExecuteAPI(_ api: String) -> Bool {
25 if api == "/kcsapi/api_req_hensei/combined" { return true }
29 override func execute() {
30 if api == "/kcsapi/api_port/port" {
31 if let t = data["api_combined_flag"].int {
32 CombineType(rawValue: t)
33 .map { postNotification(withType: $0) }
35 postNotification(withType: .cancel)
40 parameter["api_combined_type"]
42 .flatMap { CombineType(rawValue: $0) }
43 .map { postNotification(withType: $0) }
46 private func postNotification(withType type: CombineType) {
47 let userInfo = [CombinedCommand.userInfoKey: type]
50 .post(name: .CombinedDidCange, object: self, userInfo: userInfo)