Last active
April 25, 2016 09:52
-
-
Save tomasharkema/7f1e06808068bf648bcad6cc6a1f59a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol Method { | |
associatedtype ReturnType | |
static var name: String { get } | |
var parameters: [AnyObject]? { get } | |
} | |
extension METDDPClient { | |
func callMethod<T : Method>(method: T) -> Promise<T.ReturnType, MeteorError> { | |
return callMethodWithNamePromise(T.name, parameters: method.parameters) | |
} | |
} | |
protocol SubscriptionRequest { | |
static var name: String { get } | |
var parameters: [AnyObject]? { get } | |
} | |
extension METDDPClient { | |
func addSubscription<T : SubscriptionRequest>(request: T) -> Promise<METSubscription, MeteorError> { | |
return addSubscriptionPromise(T.name, parameters: request.parameters) | |
} | |
} | |
// Examples | |
struct RegisterPushToken { | |
let deviceId: String | |
let token: String | |
let tokenType: String | |
} | |
extension RegisterPushToken: Method { | |
typealias ReturnType = Bool | |
static var name: String { return "RegisterPushToken" } | |
var parameters: [AnyObject]? { | |
return [deviceId, | |
["token": token, | |
"tokenType": tokenType]] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment