2 // CombinedCommand.swift
5 // Created by Hori,Masaki on 2017/01/09.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 enum CombineType: Int {
19 extension Notification.Name {
21 static let CombinedDidCange = Notification.Name("com.masakih.KCD.Notification.CombinedDidCange")
24 final class CombinedCommand: JSONCommand {
26 static let userInfoKey = "com.masakih.KCD.Notification.CombinedDidCange.CombinedType"
28 override class func canExecuteAPI(_ api: String) -> Bool {
30 if api == "/kcsapi/api_req_hensei/combined" { return true }
35 override func execute() {
37 if api == "/kcsapi/api_port/port" {
39 if let t = data["api_combined_flag"].int {
41 CombineType(rawValue: t).map(postNotification(withType:))
45 postNotification(withType: .cancel)
51 parameter["api_combined_type"]
53 .flatMap { CombineType(rawValue: $0) }
54 .map(postNotification(withType:))
57 private func postNotification(withType type: CombineType) {
59 let userInfo = [CombinedCommand.userInfoKey: type]
61 NotificationCenter.default.post(name: .CombinedDidCange, object: self, userInfo: userInfo)