-
-
-

Usergrid

-
-
-
public class Usergrid: NSObject
- -
-
-

The Usergrid class acts as a static shared instance manager for the UsergridClient class.

- -

The methods and variables in this class are all static and therefore you will never need or want to initialize an instance of the Usergrid class.

- -

Use of this class depends on initialization of the shared instance of the UsergridClient object. Because of this, before using any of the static methods -provided you will need to call one of the shared instance initialization methods. Failure to do so will result in failure from all methods.

- -
-
-
- -
    -
  • -
    - - - - isInitialized - -
    -
    -
    -
    -
    -
    -

    Used to determine if the shared instance of the UsergridClient has been initialized.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static var isInitialized : Bool  { return Usergrid._sharedClient != nil }
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - sharedInstance - -
    -
    -
    -
    -
    -
    -

    A shared instance of UsergridClient, used by the Usergrid static methods and acts as the default UsergridClient -within the UsergridSDK library.

    - -
    -

    Warning

    - You must call one of the Usergrid.initSharedInstance methods before this or any other Usergrid static methods are valid. - -
    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static var sharedInstance : UsergridClient
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - appId - -
    -
    -
    -
    -
    -
    -

    The application identifier the shared instance of UsergridClient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static var appId : String { return Usergrid.sharedInstance.appId }
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - orgId - -
    -
    -
    -
    -
    -
    -

    The organization identifier of the shared instance of UsergridClient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static var orgId : String { return Usergrid.sharedInstance.orgId }
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - baseUrl - -
    -
    -
    -
    -
    -
    -

    The base URL that all calls will be made with of the shared instance of UsergridClient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static var baseUrl : String { return Usergrid.sharedInstance.baseUrl }
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - clientAppURL - -
    -
    -
    -
    -
    -
    -

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

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static var clientAppURL : String { return Usergrid.sharedInstance.clientAppURL }
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - currentUser - -
    -
    -
    -
    -
    -
    -

    The currently logged in UsergridUser of the shared instance of UsergridClient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static var currentUser: UsergridUser?  { return Usergrid.sharedInstance.currentUser }
    - -
    -
    -
    -
    -
  • -
  • - -
    -
    -
    -
    -
    -

    Whether or not the current user will be saved and restored from the keychain using the shared instance of UsergridClient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static var persistCurrentUserInKeychain: Bool
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - userAuth - -
    -
    -
    -
    -
    -
    -

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

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static var userAuth: UsergridUserAuth?  { return Usergrid.sharedInstance.userAuth }
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - appAuth - -
    -
    -
    -
    -
    -
    -

    The application level UsergridAppAuth object of the shared instance of UsergridClient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static var appAuth: UsergridAppAuth?
    - -
    -
    -
    -
    -
  • -
  • -
    - - - - authFallback - -
    -
    -
    -
    -
    -
    -

    The UsergridAuthFallback value used to determine what type of token will be sent of the shared instance of UsergridClient, if any.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static var authFallback: UsergridAuthFallback
    - -
    -
    -
    -
    -
  • -
-
-
- -
    -
  • - -
    -
    -
    -
    -
    -

    Initializes the Usergrid.sharedInstance of UsergridClient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static func initSharedInstance(orgId orgId : String, appId: String) -> UsergridClient
    - -
    -
    -
    -

    Parameters

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

    The organization identifier.

    - -
    -
    - - appId - - -
    -

    The application identifier.

    - -
    -
    -
    -
    -

    Return Value

    -

    The shared instance of UsergridClient.

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

    Initializes the Usergrid.sharedInstance of UsergridClient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static func initSharedInstance(orgId orgId : String, appId: String, baseUrl: String) -> UsergridClient
    - -
    -
    -
    -

    Parameters

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

    The organization identifier.

    - -
    -
    - - appId - - -
    -

    The application identifier.

    - -
    -
    - - baseUrl - - -
    -

    The base URL that all calls will be made with.

    - -
    -
    -
    -
    -

    Return Value

    -

    The shared instance of UsergridClient.

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

    Initializes the Usergrid.sharedInstance of UsergridClient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static func initSharedInstance(configuration configuration: UsergridClientConfig) -> UsergridClient
    - -
    -
    -
    -

    Parameters

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

    The configuration for the client to be set up with.

    - -
    -
    -
    -
    -

    Return Value

    -

    The shared instance of UsergridClient.

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

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

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static 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 using the shared instance of UsergridCient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static 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.

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

    Sets the shared UsergridClient’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 static func usingAuth(auth:UsergridAuth) -> UsergridClient
    - -
    -
    -
    -

    Parameters

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

    The UsergridAuth object to temporarily use for authentication.

    - -
    -
    -
    -
    -

    Return Value

    -

    The shared instance of UsergridClient

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

    Sets the shared UsergridClient’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 static func usingToken(token:String) -> UsergridClient
    - -
    -
    -
    -

    Parameters

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

    The access token to temporarily use for authentication.

    - -
    -
    -
    -
    -

    Return Value

    -

    The shared instance of UsergridClient

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

    Determines the UsergridAuth object that will be used for all outgoing requests made by the shared instance of UsergridClient.

    - -

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

    - -

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

    - -
    -
    -

    Declaration

    -
    -

    Swift

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

    Return Value

    -

    The UsergridAuth if one is found or nil if not.

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

    Authenticates with the UsergridAppAuth that is contained within the shared instance of UsergridCient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static 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 using the shared instance of UsergridCient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static func authenticateApp(auth: 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 using the shared instance of UsergridCient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static func authenticateUser(auth: 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 using the shared instance of UsergridCient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static 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.

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

    Logs out the current user of the shared instance locally and remotely.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static 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 using the shared instance of UsergridCient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static 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 static 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 using the shared instance of UsergridCient.

    - -
    -

    Note

    -

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

    - -
    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static 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

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

    Gets a single UsergridEntity of a given type with a specific UUID/name using the shared instance of UsergridCient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static func GET(type: String, uuidOrName: String, completion: UsergridResponseCompletion? = nil)
    - -
    -
    -
    -

    Parameters

    - - - - - - - - - - - - - - - -
    - - type - - -
    -

    The UsergridEntity type.

    - -
    -
    - - uuidOrName - - -
    -

    The UUID or name of the UsergridEntity.

    - -
    -
    - - completion - - -
    -

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

    - -
    -
    -
    -
    -
    -
  • -
  • -
    - - - - GET(_:completion:) - -
    -
    -
    -
    -
    -
    -

    Gets a group of UsergridEntity objects of a given type using the shared instance of UsergridCient.

    - -
    -
    -

    Declaration

    -
    -

    Swift

    -
    public static func GET(type: String, completion: UsergridResponseCompletion? = nil)