DDPClient
public class DDPClient: NSObject
DDPClient is the base class for communicating with a server using the DDP protocol
-
Undocumented
Declaration
Swift
public class DDPClient: NSObject
-
Undocumented
Declaration
Swift
public class DDPClient: NSObject
-
Boolean value that determines whether the
Declaration
Swift
public var allowSelfSignedSSL:Bool = false
-
Sets the log level. The default value is .None. Possible values: .Verbose, .Debug, .Info, .Warning, .Error, .Severe, .None
Declaration
Swift
public var logLevel = XCGLogger.LogLevel.None
-
Creates a random String id
Declaration
Swift
public func getId() -> String
-
Makes a DDP connection to the server
Declaration
Swift
public func connect(url:String, callback:DDPConnectedCallback?)
Parameters
url
The String url to connect to, ex.
wss://todos.meteor.com/websocket
callback
A closure that takes a String argument with the value of the websocket session token
-
Executes a method on the server. If a callback is passed, the callback is asynchronously executed when the method has completed. The callback takes two arguments: result and error. It the method call is successful, result contains the return value of the method, if any. If the method fails, error contains information about the error.
Declaration
Swift
public func method(name: String, params: AnyObject?, callback: DDPMethodCallback?) -> String
Parameters
name
The name of the method
params
An object containing method arguments, if any
callback
The closure to be executed when the method has been executed
-
Sends a subscription request to the server.
Declaration
Swift
public func sub(name: String, params: [AnyObject]?) -> String
Parameters
name
The name of the subscription
params
An object containing method arguments, if any
-
Sends a subscription request to the server. If a callback is passed, the callback asynchronously runs when the client receives a ‘ready’ message indicating that the initial subset of documents contained in the subscription has been sent by the server.
Declaration
Swift
public func sub(name:String, params: [AnyObject]?, callback: DDPCallback?) -> String
Parameters
name
The name of the subscription
params
An object containing method arguments, if any
callback
The closure to be executed when the server sends a ‘ready’ message
-
Sends an unsubscribe request to the server. - parameter name: The name of the subscription - parameter callback: The closure to be executed when the server sends a ‘ready’ message
Declaration
Swift
public func unsub(withName name: String) -> [String]
Parameters
name
The name of the subscription
callback
The closure to be executed when the server sends a ‘ready’ message
-
Sends an unsubscribe request to the server. If a callback is passed, the callback asynchronously runs when the client receives a ‘ready’ message indicating that the subset of documents contained in the subscription have been removed.
Declaration
Swift
public func unsub(withId id: String, callback: DDPCallback?)
Parameters
name
The name of the subscription
callback
The closure to be executed when the server sends a ‘ready’ message
-
Executes when a subscription is ready.
Declaration
Swift
public func subscriptionIsReady(subscriptionId: String, subscriptionName:String) {}
Parameters
subscriptionId
A String representation of the hash of the subscription name
subscriptionName
The name of the subscription
-
Executes when a subscription is removed.
Declaration
Swift
public func subscriptionWasRemoved(subscriptionId:String, subscriptionName:String) {}
Parameters
subscriptionId
A String representation of the hash of the subscription name
subscriptionName
The name of the subscription
-
Executes when the server has sent a new document.
Declaration
Swift
public func documentWasAdded(collection:String, id:String, fields:NSDictionary?)
Parameters
collection
The name of the collection that the document belongs to
id
The document’s unique id
fields
The documents properties
-
Executes when the server sends a message to remove a document.
Declaration
Swift
public func documentWasRemoved(collection:String, id:String)
Parameters
collection
The name of the collection that the document belongs to
id
The document’s unique id
-
Executes when the server sends a message to update a document.
Declaration
Swift
public func documentWasChanged(collection:String, id:String, fields:NSDictionary?, cleared:[String]?)
Parameters
collection
The name of the collection that the document belongs to
id
The document’s unique id
fields
Optional object with EJSON values containing the fields to update
cleared
Optional array of strings (field names to delete)
-
Executes when the server sends a message indicating that the result of a method has changed.
Declaration
Swift
public func methodWasUpdated(methods:[String])
Parameters
methods
An array of strings (ids passed to ‘method’, all of whose writes have been reflected in data messages)
-
Executes when the client receives an error message from the server. Such a message is used to represent errors raised by the method or subscription, as well as an attempt to subscribe to an unknown subscription or call an unknown method.
Declaration
Swift
public func didReceiveErrorMessage(message: DDPError)
Parameters
message
A DDPError object with information about the error
-
Sends a subscription request to the server.
Declaration
Swift
public func subscribe(name:String) -> String { return sub(name, params:nil) }
Parameters
name
The name of the subscription
-
Sends a subscription request to the server.
Declaration
Swift
public func subscribe(name:String, params:[AnyObject]) -> String { return sub(name, params:params) }
Parameters
name
The name of the subscription
params
An object containing method arguments, if any
-
Sends a subscription request to the server. If a callback is passed, the callback asynchronously runs when the client receives a ‘ready’ message indicating that the initial subset of documents contained in the subscription has been sent by the server.
Declaration
Swift
public func subscribe(name:String, params:[AnyObject]?, callback: DDPCallback?) -> String { return sub(name, params:params, callback:callback) }
Parameters
name
The name of the subscription
params
An object containing method arguments, if any
callback
The closure to be executed when the server sends a ‘ready’ message
-
Sends a subscription request to the server. If a callback is passed, the callback asynchronously runs when the client receives a ‘ready’ message indicating that the initial subset of documents contained in the subscription has been sent by the server.
Declaration
Swift
public func subscribe(name:String, callback: DDPCallback?) -> String { return sub(name, params:nil, callback:callback) }
Parameters
name
The name of the subscription
callback
The closure to be executed when the server sends a ‘ready’ message
-
Asynchronously inserts a document into a collection on the server
Declaration
Swift
public func insert(collection: String, document: NSArray, callback: DDPMethodCallback?) -> String
Parameters
collection
The name of the collection
document
An NSArray of documents to insert
callback
A closure with result and error arguments describing the result of the operation
-
Asynchronously inserts a document into a collection on the server
Declaration
Swift
public func insert(collection: String, document: NSArray) -> String
Parameters
collection
The name of the collection
document
An NSArray of documents to insert
-
Synchronously inserts a document into a collection on the server. Cannot be used on the main queue.
Declaration
Swift
public func insert(sync collection: String, document: NSArray) -> Result
Parameters
collection
The name of the collection
document
An NSArray of documents to insert
-
Asynchronously updates a document into a collection on the server
Declaration
Swift
public func update(collection: String, document: NSArray, callback: DDPMethodCallback?) -> String
Parameters
collection
The name of the collection
document
An NSArray of documents to update
callback
A closure with result and error arguments describing the result of the operation
-
Asynchronously updates a document on the server
Declaration
Swift
public func update(collection: String, document: NSArray) -> String
Parameters
collection
The name of the collection
document
An NSArray of documents to update
-
Synchronously updates a document on the server. Cannot be used on the main queue
Declaration
Swift
public func update(sync collection: String, document: NSArray) -> Result
Parameters
collection
The name of the collection
document
An NSArray of documents to update
-
Asynchronously removes a document on the server
Declaration
Swift
public func remove(collection: String, document: NSArray, callback: DDPMethodCallback?) -> String
Parameters
collection
The name of the collection
document
An NSArray of documents to remove
callback
A closure with result and error arguments describing the result of the operation
-
Asynchronously removes a document into a collection on the server
Declaration
Swift
public func remove(collection: String, document: NSArray) -> String
Parameters
collection
The name of the collection
document
An NSArray of documents to remove
-
Synchronously removes a document into a collection on the server. Cannot be used on the main queue.
Declaration
Swift
public func remove(sync collection: String, document: NSArray) -> Result
Parameters
collection
The name of the collection
document
An NSArray of documents to remove
-
Undocumented
Declaration
Swift
public class DDPClient: NSObject
-
Logs a user into the server using an email and password
Declaration
Swift
public func loginWithPassword(email: String, password: String, callback: DDPMethodCallback?)
Parameters
email
An email string
password
A password string
callback
A closure with result and error parameters describing the outcome of the operation
-
Logs a user into the server using a username and password
Declaration
Swift
public func loginWithUsername(username: String, password: String, callback: DDPMethodCallback?)
Parameters
username
A username string
password
A password string
callback
A closure with result and error parameters describing the outcome of the operation
-
Attempts to login a user with a token, if one exists
Declaration
Swift
public func loginWithToken(callback: DDPMethodCallback?) -> Bool
Parameters
callback
A closure with result and error parameters describing the outcome of the operation
-
Undocumented
Declaration
Swift
public class DDPClient: NSObject
-
Invokes a Meteor method to create a user account with a given email and password on the server
Declaration
Swift
public func signupWithEmail(email: String, password: String, callback: ((result:AnyObject?, error:DDPError?) -> ())?)
-
Invokes a Meteor method to create a user account with a given email and password, and a NSDictionary containing a user profile
Declaration
Swift
public func signupWithEmail(email: String, password: String, profile: NSDictionary, callback: ((result:AnyObject?, error:DDPError?) -> ())?)
-
Invokes a Meteor method to create a user account with a given username, email and password, and a NSDictionary containing a user profile
Declaration
Swift
public func signupWithUsername(username: String, password: String, email: String?, profile: NSDictionary?, callback: ((result:AnyObject?, error:DDPError?) -> ())?)
-
Returns the client userId, if it exists
Declaration
Swift
public func userId() -> String?
-
Returns the client’s username or email, if it exists
Declaration
Swift
public func user() -> String?
-
Logs a user out and removes their account data from NSUserDefaults
Declaration
Swift
public func logout()
-
Logs a user out and removes their account data from NSUserDefaults. When it completes, it posts a notification: DDP_USER_DID_LOGOUT on the main queue
Declaration
Swift
public func logout(callback:DDPMethodCallback?)
Parameters
callback
A closure with result and error parameters describing the outcome of the operation
-
Automatically attempts to resume a prior session, if one exists
Declaration
Swift
public func resume(url:String, callback:DDPCallback?)
Parameters
url
The server url
-
Connects and logs in with an email address and password in one action
Declaration
Swift
public convenience init(url: String, email: String, password: String, callback: DDPMethodCallback?)
Parameters
url
String url, ex. wss://todos.meteor.com/websocket
email
String email address
password
String password
callback
A closure with result and error parameters describing the outcome of the operation
-
Returns true if the user is logged in, and false otherwise
Declaration
Swift
public func loggedIn() -> Bool