Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.