-
-
-

UsergridClient

-
-
-
public class UsergridClient: NSObject, NSCoding
- -
-
-

The UsergridClient class is the base handler for making client connections to and managing relationships with Usergrid’s API.

- -
-
-
- -
    -
  • -
    - - - - config - -
    -
    -
    -
    -
    -
    -

    The configuration object used by the client.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public let config: UsergridClientConfig
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - appId - -
    -
    -
    -
    -
    -
    -

    The application identifier.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public var appId : String { return config.appId }
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - orgId - -
    -
    -
    -
    -
    -
    -

    The organization identifier.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public var orgId : String { return config.orgId }
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - baseUrl - -
    -
    -
    -
    -
    -
    -

    The base URL that all calls will be made with.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public var baseUrl : String { return config.baseUrl }
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - clientAppURL - -
    -
    -
    -
    -
    -
    -

    The constructed URL string based on the UsergridClient’s baseUrl, orgId, and appId.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public var clientAppURL : String { return "\(baseUrl)/\(orgId)/\(appId)" }
    - -
    -
    -
    -
    -
  • -
  • - -
    -
    -
    -
    -
    -

    Whether or not the current user will be saved and restored from the keychain.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public var persistCurrentUserInKeychain: Bool
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - currentUser - -
    -
    -
    -
    -
    -
    -

    The currently logged in UsergridUser.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    internal(set) public var currentUser: UsergridUser? = nil
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - userAuth - -
    -
    -
    -
    -
    -
    -

    The UsergridUserAuth which consists of the token information from the currentUser property.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public var userAuth: UsergridUserAuth? { return currentUser?.auth }
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - appAuth - -
    -
    -
    -
    -
    -
    -

    The application level UsergridAppAuth object. Can be set manually but must call authenticateApp to retrive token.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public var appAuth: UsergridAppAuth?
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - authMode - -
    -
    -
    -
    -
    -
    -

    The UsergridAuthMode value used to determine what type of token will be sent, if any.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public var authMode: UsergridAuthMode
    - -
    -
    -
    -
    -
  • -
-
-
- -
    -
  • -
    - - - - init(orgId:appId:) - -
    -
    -
    -
    -
    -
    -

    Initializes instances of UsergridClient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public convenience init(orgId: String, appId:String)
    - -
    -
    -
    -

    Parameters

    - - - - - - - - - - - -
    - - orgId - - -
    -

    The organization identifier.

    - -
    -
    - - appId - - -
    -

    The application identifier.

    - -
    -
    -
    -
    -

    Return Value

    -

    The new instance of UsergridClient.

    - -
    -
    -
    -
  • -
  • - -
    -
    -
    -
    -
    -

    Initializes instances of UsergridClient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public convenience init(orgId: String, appId:String, baseUrl:String)
    - -
    -
    -
    -

    Parameters

    - - - - - - - - - - - - - - - -
    - - orgId - - -
    -

    The organization identifier.

    - -
    -
    - - appId - - -
    -

    The application identifier.

    - -
    -
    - - baseUrl - - -
    -

    The base URL that all calls will be made with.

    - -
    -
    -
    -
    -

    Return Value

    -

    The new instance of UsergridClient.

    - -
    -
    -
    -
  • -
  • -
    - - - - init(configuration:) - -
    -
    -
    -
    -
    -
    -

    Initializes instances of UsergridClient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public init(configuration:UsergridClientConfig)
    - -
    -
    -
    -

    Parameters

    - - - - - - - -
    - - configuration - - -
    -

    The configuration for the client to be set up with.

    - -
    -
    -
    -
    -

    Return Value

    -

    The new instance of UsergridClient.

    - -
    -
    -
    -
  • -
-
-
- -
    -
  • -
    - - - - init(coder:) - -
    -
    -
    -
    -
    -
    -

    NSCoding protocol initializer.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public required init?(coder aDecoder: NSCoder)
    - -
    -
    -
    -

    Parameters

    - - - - - - - -
    - - aDecoder - - -
    -

    The decoder.

    - -
    -
    -
    -
    -

    Return Value

    -

    A decoded UsergridClient object.

    - -
    -
    -
    -
  • -
  • -
    - - - - encodeWithCoder(_:) - -
    -
    -
    -
    -
    -
    -

    NSCoding protocol encoder.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func encodeWithCoder(aCoder: NSCoder)
    - -
    -
    -
    -

    Parameters

    - - - - - - - -
    - - aCoder - - -
    -

    The encoder.

    - -
    -
    -
    -
    -
    -
  • -
-
-
- -
    -
  • - -
    -
    -
    -
    -
    -

    Sets the push token for the given notifier ID and performs a PUT request to update the shared UsergridDevice instance.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func applyPushToken(pushToken: NSData, notifierID: String, completion: UsergridResponseCompletion? = nil)
    - -
    -
    -
    -

    Parameters

    - - - - - - - - - - - - - - - -
    - - pushToken - - -
    -

    The push token from Apple.

    - -
    -
    - - notifierID - - -
    -

    The Usergrid notifier ID.

    - -
    -
    - - completion - - -
    -

    The completion block.

    - -
    -
    -
    -
    -
    -
  • -
  • - -
    -
    -
    -
    -
    -

    Sets the push token for the given notifier ID and performs a PUT request to update the given UsergridDevice instance.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func applyPushToken(device: UsergridDevice, pushToken: NSData, notifierID: String, completion: UsergridResponseCompletion? = nil)
    - -
    -
    -
    -

    Parameters

    - - - - - - - - - - - - - - - - - - - -
    - - device - - -
    -

    The UsergridDevice object.

    - -
    -
    - - pushToken - - -
    -

    The push token from Apple.

    - -
    -
    - - notifierID - - -
    -

    The Usergrid notifier ID.

    - -
    -
    - - completion - - -
    -

    The completion block.

    - -
    -
    -
    -
    -
    -
  • -
-
-
- -
    -
  • -
    - - - - authForRequests() - -
    -
    -
    -
    -
    -
    -

    Determines the UsergridAuth object that will be used for all outgoing requests made.

    - -

    If there is a valid temporary UsergridAuth set by the functions usingAuth or usingToken it will return that.

    - -

    If there is a UsergridUser logged in and the token of that user is valid then it will return that.

    - -

    Otherwise, if the authMode is .App, and the UsergridAppAuth of the client is set and the token is valid it will return that.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func authForRequests() -> UsergridAuth?
    - -
    -
    -
    -

    Return Value

    -

    The UsergridAuth if one is found or nil if not.

    - -
    -
    -
    -
  • -
  • -
    - - - - usingAuth(_:) - -
    -
    -
    -
    -
    -
    -

    Sets the client’s tempAuth property using the passed in UsergridAuth.

    - -

    This will cause the next CRUD method performed by the client to use the tempAuth property once and will then reset.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func usingAuth(auth:UsergridAuth) -> Self
    - -
    -
    -
    -

    Parameters

    - - - - - - - -
    - - auth - - -
    -

    The UsergridAuth object to temporarily use for authentication.

    - -
    -
    -
    -
    -

    Return Value

    -

    Self

    - -
    -
    -
    -
  • -
  • -
    - - - - usingToken(_:) - -
    -
    -
    -
    -
    -
    -

    Sets the client’s tempAuth property using the passed in token.

    - -

    This will cause the next CRUD method performed by the client to use the tempAuth property once and will then reset.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func usingToken(token:String) -> Self
    - -
    -
    -
    -

    Parameters

    - - - - - - - -
    - - auth - - -
    -

    The access token to temporarily use for authentication.

    - -
    -
    -
    -
    -

    Return Value

    -

    Self

    - -
    -
    -
    -
  • -
  • -
    - - - - authenticateApp(_:) - -
    -
    -
    -
    -
    -
    -

    Authenticates with the UsergridAppAuth that is contained this instance of UsergridCient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func authenticateApp(completion: UsergridAppAuthCompletionBlock? = nil)
    - -
    -
    -
    -

    Parameters

    - - - - - - - -
    - - completion - - -
    -

    The completion block that will be called after authentication has completed.

    - -
    -
    -
    -
    -
    -
  • -
  • - -
    -
    -
    -
    -
    -

    Authenticates with the UsergridAppAuth that is passed in.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func authenticateApp(appAuth: UsergridAppAuth, completion: UsergridAppAuthCompletionBlock? = nil)
    - -
    -
    -
    -

    Parameters

    - - - - - - - - - - - -
    - - auth - - -
    -

    The UsergridAppAuth that will be authenticated.

    - -
    -
    - - completion - - -
    -

    The completion block that will be called after authentication has completed.

    - -
    -
    -
    -
    -
    -
  • -
  • - -
    -
    -
    -
    -
    -

    Authenticates with the UsergridUserAuth that is passed in.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func authenticateUser(userAuth: UsergridUserAuth, completion: UsergridUserAuthCompletionBlock? = nil)
    - -
    -
    -
    -

    Parameters

    - - - - - - - - - - - -
    - - auth - - -
    -

    The UsergridUserAuth that will be authenticated.

    - -
    -
    - - completion - - -
    -

    The completion block that will be called after authentication has completed.

    - -
    -
    -
    -
    -
    -
  • -
  • - -
    -
    -
    -
    -
    -

    Authenticates with the UsergridUserAuth that is passed in.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func authenticateUser(userAuth: UsergridUserAuth, setAsCurrentUser: Bool, completion: UsergridUserAuthCompletionBlock? = nil)
    - -
    -
    -
    -

    Parameters

    - - - - - - - - - - - - - - - -
    - - auth - - -
    -

    The UsergridUserAuth that will be authenticated.

    - -
    -
    - - setAsCurrentUser - - -
    -

    If the authenticated user should be set as the UsergridClient.currentUser.

    - -
    -
    - - completion - - -
    -

    The completion block that will be called after authentication has completed.

    - -
    -
    -
    -
    -
    -
  • -
  • - -
    -
    -
    -
    -
    -

    Changes the given UsergridUser’s current password.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func resetPassword(user: UsergridUser, old:String, new:String, completion:UsergridUserResetPasswordCompletion? = nil)
    - -
    -
    -
    -

    Parameters

    - - - - - - - - - - - - - - - - - - - -
    - - user - - -
    -

    The user.

    - -
    -
    - - old - - -
    -

    The old password.

    - -
    -
    - - new - - -
    -

    The new password.

    - -
    -
    - - completion - - -
    -

    The optional completion block.

    - -
    -
    -
    -
    -
    -
  • -
  • -
    - - - - logoutCurrentUser(_:) - -
    -
    -
    -
    -
    -
    -

    Logs out the current user locally and remotely.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func logoutCurrentUser(completion:UsergridResponseCompletion? = nil)
    - -
    -
    -
    -

    Parameters

    - - - - - - - -
    - - completion - - -
    -

    The completion block that will be called after logout has completed.

    - -
    -
    -
    -
    -
    -
  • -
  • - -
    -
    -
    -
    -
    -

    Logs out the user remotely with the given tokens.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func logoutUserAllTokens(uuidOrUsername:String, completion:UsergridResponseCompletion? = nil)
    - -
    -
    -
    -

    Parameters

    - - - - - - - -
    - - completion - - -
    -

    The completion block that will be called after logout has completed.

    - -
    -
    -
    -
    -
    -
  • -
  • - -
    -
    -
    -
    -
    -

    Logs out a user with the give UUID or username using the shared instance of UsergridCient.

    - -

    Passing in a token will log out the user for just that token. Passing in nil for the token will logout the user for all tokens.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func logoutUser(uuidOrUsername:String, token:String?, completion:UsergridResponseCompletion? = nil)
    - -
    -
    -
    -

    Parameters

    - - - - - - - -
    - - completion - - -
    -

    The completion block that will be called after logout has completed.

    - -
    -
    -
    -
    -
    -
  • -
-
-
- -
    -
  • - -
    -
    -
    -
    -
    -

    Starts the UsergridRequest sending process.

    - -
    -

    Note

    -

    This method should only be used when you construct your own UsergridRequest objects.

    - -
    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public func sendRequest(request:UsergridRequest, completion:UsergridResponseCompletion? = nil)
    - -
    -
    -
    -

    Parameters

    - - - - - - - - - - - -
    - - request - - -
    -

    The UsergridRequest object to send.

    - -
    -
    - - completion - - -
    -

    The optional completion block that will be called once the request has completed.

    - -
    -
    -
    -
    -
    -
  • -
-
-
-
- - - -

GET

-
-
-