usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [01/40] usergrid git commit: Updates. See commit details.
Date Thu, 19 May 2016 17:18:34 GMT
Repository: usergrid
Updated Branches:
  refs/heads/master 8f8b46729 -> 886e837c1


Updates. See commit details.

UsergridClient.getConnection methods now use a default value for queries in the method definition.

Removed invalid method UsergridDevice.uuid.

Added use of `guard` statement in favor of if/else in various parts of the code.

UsergridUser.create() now copies the properties from the response over to the User that called
it.

UsergridUser.reauthenticate() now resets the UsergridClient.currentUser property if the calling
User is in fact the same as the currentUser.

UsergridUser.connectToDevice() and UsergridUser.disconnectFromDevice() methods fixed.

UsergridUser.getConnectedDevice() methods added.

UsergridClient.logoutUser() now determines if the user to logout is in fact the currentUser
and if so now sets that to nil if need be.

Decoding of UsergridClientConfig.authFallback is fixed.

Updates to tests.


Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/645bef13
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/645bef13
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/645bef13

Branch: refs/heads/master
Commit: 645bef13dc119135de127d77997dc0d3de113927
Parents: c638c77
Author: Robert Walsh <rjwalsh1985@gmail.com>
Authored: Tue Feb 16 12:40:45 2016 -0600
Committer: Robert Walsh <rjwalsh1985@gmail.com>
Committed: Tue Feb 16 12:40:45 2016 -0600

----------------------------------------------------------------------
 sdks/swift/Source/Usergrid.swift             |   6 +-
 sdks/swift/Source/UsergridClient.swift       |  25 +--
 sdks/swift/Source/UsergridClientConfig.swift |   2 +-
 sdks/swift/Source/UsergridDevice.swift       |   3 -
 sdks/swift/Source/UsergridEntity.swift       |  76 ++++----
 sdks/swift/Source/UsergridUser.swift         |  62 +++++--
 sdks/swift/Tests/ASSET_Tests.swift           |  15 +-
 sdks/swift/Tests/AUTH_Tests.swift            |  21 ++-
 sdks/swift/Tests/CONNECTION_Tests.swift      |  29 ++--
 sdks/swift/Tests/ClientCreationTests.swift   |  23 ++-
 sdks/swift/Tests/User_Tests.swift            | 200 ++++++++++++++++++++--
 11 files changed, 348 insertions(+), 114 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/645bef13/sdks/swift/Source/Usergrid.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Source/Usergrid.swift b/sdks/swift/Source/Usergrid.swift
index 1049a62..19444a0 100644
--- a/sdks/swift/Source/Usergrid.swift
+++ b/sdks/swift/Source/Usergrid.swift
@@ -566,7 +566,7 @@ public class Usergrid: NSObject {
     - parameter relationship: The relationship.
     - parameter completion:   The completion block that will be called once the request has
completed.
     */
-    public static func getConnections(direction:UsergridDirection, entity:UsergridEntity,
relationship:String, query:UsergridQuery?, completion:UsergridResponseCompletion? = nil) {
+    public static func getConnections(direction:UsergridDirection, entity:UsergridEntity,
relationship:String, query:UsergridQuery? = nil, completion:UsergridResponseCompletion? =
nil) {
         Usergrid.sharedInstance.getConnections(direction, entity: entity, relationship: relationship,
query:query, completion: completion)
     }
 
@@ -580,7 +580,7 @@ public class Usergrid: NSObject {
      - parameter query:            The optional query.
      - parameter completion:       The completion block that will be called once the request
has completed.
      */
-    public static func getConnections(direction:UsergridDirection, type:String, uuidOrName:String,
relationship:String, query:UsergridQuery?, completion:UsergridResponseCompletion? = nil) {
+    public static func getConnections(direction:UsergridDirection, type:String, uuidOrName:String,
relationship:String, query:UsergridQuery? = nil, completion:UsergridResponseCompletion? =
nil) {
         Usergrid.sharedInstance.getConnections(direction, type: type, uuidOrName: uuidOrName,
relationship: relationship, query:query, completion: completion)
     }
 
@@ -593,7 +593,7 @@ public class Usergrid: NSObject {
      - parameter query:        The optional query.
      - parameter completion:   The optional completion block that will be called once the
request has completed.
      */
-    public static func getConnections(direction:UsergridDirection, uuid:String, relationship:String,
query:UsergridQuery?, completion:UsergridResponseCompletion? = nil) {
+    public static func getConnections(direction:UsergridDirection, uuid:String, relationship:String,
query:UsergridQuery? = nil, completion:UsergridResponseCompletion? = nil) {
         Usergrid.sharedInstance.getConnections(direction, uuid: uuid, relationship: relationship,
query: query, completion: completion)
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/645bef13/sdks/swift/Source/UsergridClient.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Source/UsergridClient.swift b/sdks/swift/Source/UsergridClient.swift
index 9cb6aa7..a0306a3 100644
--- a/sdks/swift/Source/UsergridClient.swift
+++ b/sdks/swift/Source/UsergridClient.swift
@@ -357,13 +357,7 @@ public class UsergridClient: NSObject, NSCoding {
             return
         }
 
-        self.logoutUser(uuidOrUsername, token: token) { (response) -> Void in
-            if response.ok || response.error?.errorName == "auth_bad_access_token" {
-                self.currentUser?.auth = nil
-                self.currentUser = nil
-            }
-            completion?(response: response)
-        }
+        self.logoutUser(uuidOrUsername, token: token)
     }
 
     /**
@@ -396,7 +390,16 @@ public class UsergridClient: NSObject, NSCoding {
                                       paths: paths,
                                       auth: self.authForRequests(),
                                       queryParams: queryParams)
-        self.sendRequest(request, completion: completion)
+
+        self.sendRequest(request) { response in
+            if uuidOrUsername == self.currentUser?.uuidOrUsername { // Check to see if this
user is the currentUser
+                if response.ok || response.error?.errorName == "auth_bad_access_token" {
// If the logout was successful or if we have a bad token reset things.
+                    self.currentUser?.auth = nil
+                    self.currentUser = nil
+                }
+            }
+            completion?(response: response)
+        }
     }
 
     // MARK: - Generic Request Methods -
@@ -807,7 +810,7 @@ public class UsergridClient: NSObject, NSCoding {
     - parameter query:        The optional query.
     - parameter completion:   The optional completion block that will be called once the
request has completed.
     */
-    public func getConnections(direction:UsergridDirection, entity:UsergridEntity, relationship:String,
query:UsergridQuery?, completion:UsergridResponseCompletion? = nil) {
+    public func getConnections(direction:UsergridDirection, entity:UsergridEntity, relationship:String,
query:UsergridQuery? = nil, completion:UsergridResponseCompletion? = nil) {
         guard let uuidOrName = entity.uuidOrName
         else {
             completion?(response: UsergridResponse(client: self, errorName: "Invalid Entity
Get Connections Attempt.", errorDescription: "The entity must have a `uuid` or `name` assigned."))
@@ -826,7 +829,7 @@ public class UsergridClient: NSObject, NSCoding {
      - parameter query:            The optional query.
      - parameter completion:       The optional completion block that will be called once
the request has completed.
      */
-    public func getConnections(direction:UsergridDirection, type:String, uuidOrName:String,
relationship:String, query:UsergridQuery?, completion:UsergridResponseCompletion? = nil) {
+    public func getConnections(direction:UsergridDirection, type:String, uuidOrName:String,
relationship:String, query:UsergridQuery? = nil, completion:UsergridResponseCompletion? =
nil) {
         let request = UsergridRequest(method: .Get,
                                       baseUrl: self.clientAppURL,
                                       paths: [type, uuidOrName, direction.connectionValue,
relationship],
@@ -844,7 +847,7 @@ public class UsergridClient: NSObject, NSCoding {
      - parameter query:        The optional query.
      - parameter completion:   The optional completion block that will be called once the
request has completed.
      */
-    public func getConnections(direction:UsergridDirection, uuid:String, relationship:String,
query:UsergridQuery?, completion:UsergridResponseCompletion? = nil) {
+    public func getConnections(direction:UsergridDirection, uuid:String, relationship:String,
query:UsergridQuery? = nil, completion:UsergridResponseCompletion? = nil) {
         let request = UsergridRequest(method: .Get,
             baseUrl: self.clientAppURL,
             paths: [uuid, direction.connectionValue, relationship],

http://git-wip-us.apache.org/repos/asf/usergrid/blob/645bef13/sdks/swift/Source/UsergridClientConfig.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Source/UsergridClientConfig.swift b/sdks/swift/Source/UsergridClientConfig.swift
index 2719610..3f68ee8 100644
--- a/sdks/swift/Source/UsergridClientConfig.swift
+++ b/sdks/swift/Source/UsergridClientConfig.swift
@@ -129,7 +129,7 @@ public class UsergridClientConfig : NSObject, NSCoding {
         self.baseUrl = baseUrl
         self.appAuth = aDecoder.decodeObjectForKey("appAuth") as? UsergridAppAuth
         self.persistCurrentUserInKeychain = aDecoder.decodeBoolForKey("persistCurrentUserInKeychain")
?? true
-        self.authFallback = UsergridAuthFallback(rawValue:aDecoder.decodeIntegerForKey("authFallback"))
?? .App
+        self.authFallback = UsergridAuthFallback(rawValue:aDecoder.decodeIntegerForKey("authFallback"))
?? .None
         super.init()
     }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/645bef13/sdks/swift/Source/UsergridDevice.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Source/UsergridDevice.swift b/sdks/swift/Source/UsergridDevice.swift
index 995470c..90efbd4 100644
--- a/sdks/swift/Source/UsergridDevice.swift
+++ b/sdks/swift/Source/UsergridDevice.swift
@@ -46,9 +46,6 @@ public class UsergridDevice : UsergridEntity {
 
     // MARK: - Instance Properties -
 
-    /// Property helper method for the `UsergridDevice` objects `uuid`.
-    override public var uuid: String! { return super[UsergridEntityProperties.UUID.stringValue]
as! String }
-
     /// Property helper method for the `UsergridDevice` objects device model.
     public var model: String { return super[UsergridDeviceProperties.Model.stringValue] as!
String }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/645bef13/sdks/swift/Source/UsergridEntity.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Source/UsergridEntity.swift b/sdks/swift/Source/UsergridEntity.swift
index 5baaba4..4e15683 100644
--- a/sdks/swift/Source/UsergridEntity.swift
+++ b/sdks/swift/Source/UsergridEntity.swift
@@ -149,15 +149,13 @@ public class UsergridEntity: NSObject, NSCoding {
     - returns: A `UsergridEntity` object provided that the `type` key within the dictionay
exists. Otherwise nil.
     */
     public class func entity(jsonDict jsonDict: [String:AnyObject]) -> UsergridEntity?
{
-        if let type = jsonDict[UsergridEntityProperties.EntityType.stringValue] as? String
{
-            if let mapping = UsergridEntity.subclassMappings[type] {
-                return mapping.init(type: type,propertyDict:jsonDict)
-            } else {
-                return UsergridEntity(type:type, propertyDict:jsonDict)
-            }
-        } else {
-            return nil
+        guard let type = jsonDict[UsergridEntityProperties.EntityType.stringValue] as? String
+            else {
+                return nil
         }
+
+        let mapping = UsergridEntity.subclassMappings[type] ?? UsergridEntity.self
+        return mapping.init(type: type, propertyDict: jsonDict)
     }
 
     /**
@@ -392,17 +390,17 @@ public class UsergridEntity: NSObject, NSCoding {
     private func getEntitySpecificProperty(entityProperty: UsergridEntityProperties) ->
AnyObject? {
         var propertyValue: AnyObject? = nil
         switch entityProperty {
-        case .UUID,.EntityType,.Name :
-            propertyValue = self.properties[entityProperty.stringValue]
-        case .Created,.Modified :
-            if let utcTimeStamp = self.properties[entityProperty.stringValue] as? Int {
-                propertyValue = NSDate(utcTimeStamp: utcTimeStamp.description)
-            }
-        case .Location :
-            if let locationDict = self.properties[entityProperty.stringValue] as? [String:Double],
lat = locationDict[ENTITY_LATITUDE], long = locationDict[ENTITY_LONGITUDE] {
-                propertyValue = CLLocation(latitude: lat, longitude: long)
+            case .UUID,.EntityType,.Name :
+                propertyValue = self.properties[entityProperty.stringValue]
+            case .Created,.Modified :
+                if let utcTimeStamp = self.properties[entityProperty.stringValue] as? Int
{
+                    propertyValue = NSDate(utcTimeStamp: utcTimeStamp.description)
+                }
+            case .Location :
+                if let locationDict = self.properties[entityProperty.stringValue] as? [String:Double],
lat = locationDict[ENTITY_LATITUDE], long = locationDict[ENTITY_LONGITUDE] {
+                    propertyValue = CLLocation(latitude: lat, longitude: long)
+                }
             }
-        }
         return propertyValue
     }
 
@@ -424,15 +422,17 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter completion: An optional completion block that, if successful, will contain
the reloaded `UsergridEntity` object.
     */
     public func reload(client:UsergridClient, completion: UsergridResponseCompletion? = nil)
{
-        if let uuidOrName = self.uuidOrName {
-            client.GET(self.type, uuidOrName: uuidOrName) { (response) -> Void in
-                if let responseEntity = response.entity {
-                    self.copyInternalsFromEntity(responseEntity)
-                }
-                completion?(response: response)
+        guard let uuidOrName = self.uuidOrName
+            else {
+                completion?(response: UsergridResponse(client: client, errorName: "Entity
cannot be reloaded.", errorDescription: "Entity has neither an UUID or name specified."))
+                return
+        }
+
+        client.GET(self.type, uuidOrName: uuidOrName) { response in
+            if let responseEntity = response.entity {
+                self.copyInternalsFromEntity(responseEntity)
             }
-        } else {
-            completion?(response: UsergridResponse(client: client, errorName: "Entity cannot
be reloaded.", errorDescription: "Entity has neither an UUID or name specified."))
+            completion?(response: response)
         }
     }
 
@@ -453,19 +453,19 @@ public class UsergridEntity: NSObject, NSCoding {
     */
     public func save(client:UsergridClient, completion: UsergridResponseCompletion? = nil)
{
         if let _ = self.uuid { // If UUID exists we PUT otherwise POST
-            client.PUT(self, completion: { (response) -> Void in
+            client.PUT(self) { response in
                 if let responseEntity = response.entity {
                     self.copyInternalsFromEntity(responseEntity)
                 }
                 completion?(response: response)
-            })
+            }
         } else {
-            client.POST(self, completion: { (response) -> Void in
+            client.POST(self) { response in
                 if let responseEntity = response.entity {
                     self.copyInternalsFromEntity(responseEntity)
                 }
                 completion?(response: response)
-            })
+            }
         }
     }
 
@@ -475,7 +475,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter completion: An optional completion block.
     */
     public func remove(completion: UsergridResponseCompletion? = nil) {
-        Usergrid.sharedInstance.DELETE(self, completion: completion)
+        self.remove(Usergrid.sharedInstance, completion: completion)
     }
 
     /**
@@ -498,7 +498,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter completion: An optional completion block.
     */
     public func uploadAsset(asset:UsergridAsset, progress:UsergridAssetRequestProgress? =
nil, completion:UsergridAssetUploadCompletion? = nil) {
-        Usergrid.sharedInstance.uploadAsset(self, asset: asset, progress:progress, completion:completion)
+        self.uploadAsset(Usergrid.sharedInstance, asset: asset, progress: progress, completion:
completion)
     }
 
     /**
@@ -521,7 +521,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter completion:  An optional completion block.
     */
     public func downloadAsset(contentType:String, progress:UsergridAssetRequestProgress?
= nil, completion:UsergridAssetDownloadCompletion? = nil) {
-        Usergrid.sharedInstance.downloadAsset(self, contentType: contentType, progress:progress,
completion: completion)
+        self.downloadAsset(Usergrid.sharedInstance, contentType: contentType, progress: progress,
completion: completion)
     }
 
     /**
@@ -546,7 +546,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter completion:   An optional completion block.
     */
     public func connect(relationship:String, toEntity:UsergridEntity, completion: UsergridResponseCompletion?
= nil) {
-        Usergrid.sharedInstance.connect(self, relationship: relationship, to: toEntity, completion:
completion)
+        self.connect(Usergrid.sharedInstance, relationship: relationship, toEntity: toEntity,
completion: completion)
     }
 
     /**
@@ -569,7 +569,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter completion:   An optional completion block.
     */
     public func disconnect(relationship:String, fromEntity:UsergridEntity, completion: UsergridResponseCompletion?
= nil) {
-        Usergrid.sharedInstance.disconnect(self, relationship: relationship, from: fromEntity,
completion: completion)
+        self.disconnect(Usergrid.sharedInstance, relationship: relationship, fromEntity:
fromEntity, completion: completion)
     }
 
     /**
@@ -592,8 +592,8 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter query:          The optional query.
     - parameter completion:     An optional completion block.
     */
-    public func getConnections(direction:UsergridDirection, relationship:String, query:UsergridQuery?,
completion:UsergridResponseCompletion? = nil) {
-        Usergrid.sharedInstance.getConnections(direction, entity: self, relationship: relationship,
query:query, completion: completion)
+    public func getConnections(direction:UsergridDirection, relationship:String, query:UsergridQuery?
= nil, completion:UsergridResponseCompletion? = nil) {
+        self.getConnections(Usergrid.sharedInstance, direction: direction, relationship:
relationship, query: query, completion: completion)
     }
 
     /**
@@ -605,7 +605,7 @@ public class UsergridEntity: NSObject, NSCoding {
     - parameter query:        The optional query.
     - parameter completion:   An optional completion block.
     */
-    public func getConnections(client:UsergridClient, direction:UsergridDirection, relationship:String,
query:UsergridQuery?, completion:UsergridResponseCompletion? = nil) {
+    public func getConnections(client:UsergridClient, direction:UsergridDirection, relationship:String,
query:UsergridQuery? = nil, completion:UsergridResponseCompletion? = nil) {
         client.getConnections(direction, entity: self, relationship: relationship, query:query,
completion: completion)
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/usergrid/blob/645bef13/sdks/swift/Source/UsergridUser.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Source/UsergridUser.swift b/sdks/swift/Source/UsergridUser.swift
index 0c98b5f..7c70142 100644
--- a/sdks/swift/Source/UsergridUser.swift
+++ b/sdks/swift/Source/UsergridUser.swift
@@ -291,7 +291,12 @@ public class UsergridUser : UsergridEntity {
     - parameter completion: The optional completion block.
     */
     public func create(client: UsergridClient, completion: UsergridResponseCompletion? =
nil) {
-        client.POST(self,completion:completion)
+        client.POST(self) { (response) -> Void in
+            if response.ok, let createdUser = response.user {
+                self.copyInternalsFromEntity(createdUser)
+            }
+            completion?(response: response)
+        }
     }
 
     /**
@@ -364,12 +369,13 @@ public class UsergridUser : UsergridEntity {
      - parameter completion: The optional completion block.
      */
     public func reauthenticate(client: UsergridClient, completion: UsergridUserAuthCompletionBlock?
= nil) {
-        if let userAuth = self.auth {
-            client.authenticateUser(userAuth, completion: completion)
-        } else {
-            let error = UsergridResponseError(errorName: "Invalid UsergridUserAuth.", errorDescription:
"No UsergridUserAuth found on the UsergridUser.")
-            completion?(auth: nil, user: self, error: error)
+        guard let userAuth = self.auth
+            else {
+                completion?(auth: nil, user: self, error: UsergridResponseError(errorName:
"Invalid UsergridUserAuth.", errorDescription: "No UsergridUserAuth found on the UsergridUser."))
+                return
         }
+
+        client.authenticateUser(userAuth, setAsCurrentUser:(self == client.currentUser),
completion: completion)
     }
 
     /**
@@ -388,15 +394,16 @@ public class UsergridUser : UsergridEntity {
     - parameter completion: The optional completion block.
     */
     public func logout(client: UsergridClient, completion:UsergridResponseCompletion? = nil)
{
-        if self === client.currentUser {
-            client.logoutCurrentUser(completion)
-        } else if let uuidOrUsername = self.uuidOrUsername, accessToken = self.auth?.accessToken
{
-            client.logoutUser(uuidOrUsername, token: accessToken) { (response) in
-                self.auth = nil
-                completion?(response: response)
-            }
-        } else {
-            completion?(response: UsergridResponse(client:client, errorName:"Logout Failed.",
errorDescription:"UUID or Access Token not found on UsergridUser object."))
+        guard let uuidOrUsername = self.uuidOrUsername,
+              let accessToken = self.auth?.accessToken
+            else {
+                completion?(response: UsergridResponse(client:client, errorName:"Logout Failed.",
errorDescription:"UUID or Access Token not found on UsergridUser object."))
+                return
+        }
+        
+        client.logoutUser(uuidOrUsername, token: accessToken) { (response) in
+            self.auth = nil
+            completion?(response: response)
         }
     }
 
@@ -420,12 +427,31 @@ public class UsergridUser : UsergridEntity {
     public func connectToDevice(client:UsergridClient, device:UsergridDevice? = nil, completion:UsergridResponseCompletion?
= nil) {
         let deviceToConnect = device ?? UsergridDevice.sharedDevice
         guard let _ = deviceToConnect.uuidOrName
-        else {
+            else {
             completion?(response: UsergridResponse(client: client, errorName: "Device cannot
be connected to User.", errorDescription: "Device has neither an UUID or name specified."))
             return
         }
 
-        self.connect(client, relationship: "devices", toEntity: deviceToConnect, completion:
completion)
+        self.connect(client, relationship: "", toEntity: deviceToConnect, completion: completion)
+    }
+
+    /**
+     Gets the connected device using the shared instance of `UsergridClient`.
+
+     - parameter completion: The optional completion block.
+     */
+    public func getConnectedDevice(completion:UsergridResponseCompletion? = nil) {
+        self.getConnectedDevice(Usergrid.sharedInstance, completion: completion)
+    }
+
+    /**
+     Gets the connected device.
+
+     - parameter client:     The `UsergridClient` object to use for connecting.
+     - parameter completion: The optional completion block.
+     */
+    public func getConnectedDevice(client:UsergridClient, completion:UsergridResponseCompletion?
= nil) {
+        client.getConnections(.Out, entity: self, relationship: "device", completion: completion)
     }
 
     /**
@@ -453,7 +479,7 @@ public class UsergridUser : UsergridEntity {
                 return
         }
 
-        self.disconnect(client, relationship: "devices", fromEntity: deviceToDisconnectFrom,
completion: completion)
+        self.disconnect(client, relationship: "", fromEntity: deviceToDisconnectFrom, completion:
completion)
     }
 
     private func getUserSpecificProperty(userProperty: UsergridUserProperties) -> AnyObject?
{

http://git-wip-us.apache.org/repos/asf/usergrid/blob/645bef13/sdks/swift/Tests/ASSET_Tests.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Tests/ASSET_Tests.swift b/sdks/swift/Tests/ASSET_Tests.swift
index 23c9316..ad383ca 100644
--- a/sdks/swift/Tests/ASSET_Tests.swift
+++ b/sdks/swift/Tests/ASSET_Tests.swift
@@ -29,13 +29,21 @@ import XCTest
 
 class ASSET_Tests: XCTestCase {
 
-    let sharedClient = Usergrid.initSharedInstance(orgId:ClientCreationTests.orgId, appId:
ClientCreationTests.appId)
-
     static let collectionName = "books"
     static let entityUUID = "f4078aca-2fb1-11e5-8eb2-e13f8369aad1"
     static let imageLocation = "TestAssets/test.png"
     static let imageName = "test"
 
+    override func setUp() {
+        super.setUp()
+        Usergrid.initSharedInstance(orgId:ClientCreationTests.orgId, appId: ClientCreationTests.appId)
+    }
+
+    override func tearDown() {
+        Usergrid._sharedClient = nil
+        super.tearDown()
+    }
+
     func getFullPathOfFile(fileLocation:String) -> String {
         return (NSBundle(forClass: object_getClass(self)).resourcePath! as NSString).stringByAppendingPathComponent(fileLocation)
     }
@@ -52,6 +60,7 @@ class ASSET_Tests: XCTestCase {
         Usergrid.GET(ASSET_Tests.collectionName, uuidOrName:ASSET_Tests.entityUUID) { (response)
in
             let entity = response.first!
             XCTAssertNotNil(entity)
+            XCTAssertFalse(entity.isUser)
 
             let imagePath = self.getFullPathOfFile(ASSET_Tests.imageLocation)
             XCTAssertNotNil(imagePath)
@@ -62,7 +71,7 @@ class ASSET_Tests: XCTestCase {
             let asset = UsergridAsset(fileName:ASSET_Tests.imageName,image: localImage!)
             XCTAssertNotNil(asset)
 
-            entity.uploadAsset(self.sharedClient, asset:asset!, progress:uploadProgress)
{ (response, uploadedAsset, error) -> Void in
+            entity.uploadAsset(asset!, progress:uploadProgress) { (response, uploadedAsset,
error) -> Void in
                 XCTAssertNotNil(asset)
                 XCTAssertNil(error)
                 XCTAssertTrue(response.ok)

http://git-wip-us.apache.org/repos/asf/usergrid/blob/645bef13/sdks/swift/Tests/AUTH_Tests.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Tests/AUTH_Tests.swift b/sdks/swift/Tests/AUTH_Tests.swift
index 160cd19..3ae21bc 100644
--- a/sdks/swift/Tests/AUTH_Tests.swift
+++ b/sdks/swift/Tests/AUTH_Tests.swift
@@ -29,26 +29,35 @@ import XCTest
 
 class AUTH_Tests: XCTestCase {
 
-    let testAuthClient = UsergridClient(orgId: ClientCreationTests.orgId, appId: "sdk.demo")
     let clientAuth = UsergridAppAuth(clientId: "b3U6THNcevskEeOQZLcUROUUVA", clientSecret:
"b3U6RZHYznP28xieBzQPackFPmmnevU")
     private static let collectionName = "publicevent"
     private static let entityUUID = "fa015eaa-fe1c-11e3-b94b-63b29addea01"
 
+    override func setUp() {
+        super.setUp()
+        Usergrid.initSharedInstance(orgId:ClientCreationTests.orgId, appId: "sdk.demo")
+    }
+
+    override func tearDown() {
+        Usergrid._sharedClient = nil
+        super.tearDown()
+    }
+
     func test_CLIENT_AUTH() {
 
         let authExpect = self.expectationWithDescription("\(__FUNCTION__)")
-        testAuthClient.authFallback = .App
-        testAuthClient.authenticateApp(clientAuth) { [weak self] (auth,error) in
+        Usergrid.authFallback = .App
+        Usergrid.authenticateApp(clientAuth) { auth,error in
 
             XCTAssertNil(error)
-            XCTAssertNotNil(self?.testAuthClient.appAuth)
+            XCTAssertNotNil(Usergrid.appAuth)
 
-            if let appAuth = self?.testAuthClient.appAuth {
+            if let appAuth = Usergrid.appAuth {
 
                 XCTAssertNotNil(appAuth.accessToken)
                 XCTAssertNotNil(appAuth.expiry)
 
-                self?.testAuthClient.GET(AUTH_Tests.collectionName) { (response) in
+                Usergrid.GET(AUTH_Tests.collectionName) { (response) in
 
                     XCTAssertNotNil(response)
                     XCTAssertTrue(response.hasNextPage)

http://git-wip-us.apache.org/repos/asf/usergrid/blob/645bef13/sdks/swift/Tests/CONNECTION_Tests.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Tests/CONNECTION_Tests.swift b/sdks/swift/Tests/CONNECTION_Tests.swift
index 4dff28f..544b7c5 100644
--- a/sdks/swift/Tests/CONNECTION_Tests.swift
+++ b/sdks/swift/Tests/CONNECTION_Tests.swift
@@ -29,24 +29,33 @@ import XCTest
 
 class CONNECTION_Tests: XCTestCase {
 
-    let testAuthClient = UsergridClient(orgId:ClientCreationTests.orgId, appId: "sdk.demo")
     let clientAuth = UsergridAppAuth(clientId: "b3U6THNcevskEeOQZLcUROUUVA", clientSecret:
"b3U6RZHYznP28xieBzQPackFPmmnevU")
     private static let collectionName = "publicevent"
 
+    override func setUp() {
+        super.setUp()
+        Usergrid.initSharedInstance(orgId:ClientCreationTests.orgId, appId: "sdk.demo")
+    }
+
+    override func tearDown() {
+        Usergrid._sharedClient = nil
+        super.tearDown()
+    }
+
     func test_CLIENT_AUTH() {
 
         let authExpect = self.expectationWithDescription("\(__FUNCTION__)")
-        testAuthClient.authFallback = .App
-        testAuthClient.authenticateApp(clientAuth) { [weak self] (auth,error) in
+        Usergrid.authFallback = .App
+        Usergrid.authenticateApp(clientAuth) { auth,error in
             XCTAssertNil(error)
-            XCTAssertNotNil(self?.testAuthClient.appAuth)
+            XCTAssertNotNil(Usergrid.appAuth)
 
-            if let appAuth = self?.testAuthClient.appAuth {
+            if let appAuth = Usergrid.appAuth {
 
                 XCTAssertNotNil(appAuth.accessToken)
                 XCTAssertNotNil(appAuth.expiry)
 
-                self?.testAuthClient.GET(CONNECTION_Tests.collectionName) { (response) in
+                Usergrid.GET(CONNECTION_Tests.collectionName) { (response) in
 
                     XCTAssertNotNil(response)
                     XCTAssertTrue(response.ok)
@@ -57,19 +66,19 @@ class CONNECTION_Tests: XCTestCase {
                     let entityToConnect = response.entities![1]
                     XCTAssertEqual(entity.type, CONNECTION_Tests.collectionName)
 
-                    entity.connect(self!.testAuthClient,relationship:"likes", toEntity: entityToConnect)
{ (response) -> Void in
+                    entity.connect("likes", toEntity: entityToConnect) { (response) ->
Void in
                         XCTAssertNotNil(response)
                         XCTAssertTrue(response.ok)
-                        entity.getConnections(self!.testAuthClient, direction:.Out, relationship:
"likes", query:nil) { (response) -> Void in
+                        entity.getConnections(.Out, relationship: "likes", query:nil) { (response)
-> Void in
                             XCTAssertNotNil(response)
                             XCTAssertTrue(response.ok)
                             let connectedEntity = response.first!
                             XCTAssertNotNil(connectedEntity)
                             XCTAssertEqual(connectedEntity.uuidOrName, entityToConnect.uuidOrName)
-                            entity.disconnect(self!.testAuthClient, relationship: "likes",
fromEntity: connectedEntity) { (response) -> Void in
+                            entity.disconnect("likes", fromEntity: connectedEntity) { (response)
-> Void in
                                 XCTAssertNotNil(response)
                                 XCTAssertTrue(response.ok)
-                                entity.getConnections(self!.testAuthClient, direction:.Out,
relationship: "likes", query:nil) { (response) -> Void in
+                                entity.getConnections(.Out, relationship: "likes", query:nil)
{ (response) -> Void in
                                     XCTAssertNotNil(response)
                                     XCTAssertTrue(response.ok)
                                     authExpect.fulfill()

http://git-wip-us.apache.org/repos/asf/usergrid/blob/645bef13/sdks/swift/Tests/ClientCreationTests.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Tests/ClientCreationTests.swift b/sdks/swift/Tests/ClientCreationTests.swift
index 0d1ab88..0fe0dbe 100644
--- a/sdks/swift/Tests/ClientCreationTests.swift
+++ b/sdks/swift/Tests/ClientCreationTests.swift
@@ -42,6 +42,7 @@ class ClientCreationTests: XCTestCase {
                                                          appId: ClientCreationTests.otherAppID,
                                                          baseUrl: ClientCreationTests.otherBaseURL,
                                                          authFallback: .App,
+                                                         persistCurrentUserInKeychain: true,
                                                          appAuth: ClientCreationTests.otherAppAuth)
 
     let otherClient = UsergridClient(configuration: ClientCreationTests.otherConfiguration)
@@ -49,6 +50,7 @@ class ClientCreationTests: XCTestCase {
     override func setUp() {
         super.setUp()
         Usergrid.initSharedInstance(orgId:ClientCreationTests.orgId, appId: ClientCreationTests.appId)
+        Usergrid.persistCurrentUserInKeychain = false
     }
 
     override func tearDown() {
@@ -63,11 +65,14 @@ class ClientCreationTests: XCTestCase {
     }
 
     func test_CLIENT_PROPERTIES() {
-        XCTAssertEqual(Usergrid.sharedInstance.appId, ClientCreationTests.appId)
-        XCTAssertEqual(Usergrid.sharedInstance.orgId, ClientCreationTests.orgId)
-        XCTAssertEqual(Usergrid.sharedInstance.authFallback, UsergridAuthFallback.None)
-        XCTAssertEqual(Usergrid.sharedInstance.baseUrl, UsergridClient.DEFAULT_BASE_URL)
-        XCTAssertNil(Usergrid.sharedInstance.currentUser)
+        XCTAssertEqual(Usergrid.appId, ClientCreationTests.appId)
+        XCTAssertEqual(Usergrid.orgId, ClientCreationTests.orgId)
+        XCTAssertEqual(Usergrid.authFallback, UsergridAuthFallback.None)
+        XCTAssertEqual(Usergrid.persistCurrentUserInKeychain, false)
+        XCTAssertEqual(Usergrid.baseUrl, UsergridClient.DEFAULT_BASE_URL)
+        XCTAssertEqual(Usergrid.clientAppURL, "\(UsergridClient.DEFAULT_BASE_URL)/\(ClientCreationTests.orgId)/\(ClientCreationTests.appId)"
)
+        XCTAssertNil(Usergrid.currentUser)
+        XCTAssertNil(Usergrid.userAuth)
 
         XCTAssertEqual(otherClient.appId, ClientCreationTests.otherAppID)
         XCTAssertEqual(otherClient.orgId, ClientCreationTests.otherOrgID)
@@ -83,10 +88,10 @@ class ClientCreationTests: XCTestCase {
         XCTAssertNotNil(newInstanceFromData)
 
         if let newInstance = newInstanceFromData {
-            XCTAssertEqual(Usergrid.sharedInstance.appId, newInstance.appId)
-            XCTAssertEqual(Usergrid.sharedInstance.orgId, newInstance.orgId)
-            XCTAssertEqual(Usergrid.sharedInstance.authFallback, newInstance.authFallback)
-            XCTAssertEqual(Usergrid.sharedInstance.baseUrl, newInstance.baseUrl)
+            XCTAssertEqual(Usergrid.appId, newInstance.appId)
+            XCTAssertEqual(Usergrid.orgId, newInstance.orgId)
+            XCTAssertEqual(Usergrid.authFallback, newInstance.authFallback)
+            XCTAssertEqual(Usergrid.baseUrl, newInstance.baseUrl)
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/645bef13/sdks/swift/Tests/User_Tests.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Tests/User_Tests.swift b/sdks/swift/Tests/User_Tests.swift
index 2b1a504..845b087 100644
--- a/sdks/swift/Tests/User_Tests.swift
+++ b/sdks/swift/Tests/User_Tests.swift
@@ -25,32 +25,44 @@
  */
 
 import XCTest
+import CoreLocation
 @testable import UsergridSDK
 
 class User_Tests: XCTestCase {
 
-    var client = UsergridClient(orgId:ClientCreationTests.orgId, appId: ClientCreationTests.appId)
-
     let userWithNoName = UsergridUser()
-    let user = UsergridUser(name:User_Tests.name, email:User_Tests.email, username:User_Tests.username,
password:User_Tests.password)
+    var user: UsergridUser!
 
     static let name = "Robert Walsh"
     static let age = 29
     static let email = "handsomeRob741@yahoo.com"
     static let username = "rwalsh"
     static let password = "password"
+    static let resetPassword = "password111"
     static let picture = "http://www.gravatar.com/avatar/e466d447df831ddce35fbc50763fb03a"
     static let activated = true
     static let disabled = false
 
     override func setUp() {
         super.setUp()
+
+        Usergrid.initSharedInstance(orgId:ClientCreationTests.orgId, appId: ClientCreationTests.appId)
+        Usergrid.persistCurrentUserInKeychain = false
+
+        user = UsergridUser(name:"a_bogus_name", email:User_Tests.email, username:User_Tests.username,
password:User_Tests.password)
+        user["name"] = User_Tests.name
         user.age = User_Tests.age
+        user.location = CLLocation(latitude: -90, longitude: 100)
         user.picture = User_Tests.picture
         user.activated = User_Tests.activated
         user.disabled = User_Tests.disabled
     }
 
+    override func tearDown() {
+        Usergrid._sharedClient = nil        
+        super.tearDown()
+    }
+
     func test_USERS_AND_PROPERTIES_NOT_NIL() {
         XCTAssertNotNil(user)
         XCTAssertNotNil(user.name)
@@ -67,6 +79,9 @@ class User_Tests: XCTestCase {
     }
 
     func test_USER_PROPERTIES_WITH_HELPERS() {
+        user["uuid"] = User_Tests.age
+        XCTAssertNil(user.uuid)
+
         XCTAssertEqual(user.name!, User_Tests.name)
         XCTAssertEqual(user.age!, User_Tests.age)
         XCTAssertEqual(user.username!, User_Tests.username)
@@ -88,17 +103,32 @@ class User_Tests: XCTestCase {
         XCTAssertFalse(user[UsergridUserProperties.Disabled.stringValue]! as! Bool)
     }
 
+    func deleteUser(expectation:XCTestExpectation) {
+        self.user.remove() { (removeResponse) in
+            XCTAssertNotNil(removeResponse)
+            XCTAssertTrue(removeResponse.ok)
+            XCTAssertNotNil(removeResponse.user)
+            XCTAssertNotNil(removeResponse.users)
+            print(removeResponse.error)
+            expectation.fulfill()
+        }
+    }
+
     func test_CREATE_AND_DELETE_USER() {
-        let createUserExpect = self.expectationWithDescription("\(__FUNCTION__)")
+        let userExpect = self.expectationWithDescription("\(__FUNCTION__)")
 
-        user.create(client) { (createResponse) in
+        user.save() { (createResponse) in
             XCTAssertNotNil(createResponse)
             XCTAssertTrue(createResponse.ok)
             XCTAssertNotNil(createResponse.user)
             XCTAssertNotNil(createResponse.users)
 
             if let createdUser = createResponse.user {
+                XCTAssertTrue(createdUser.isUser)
                 XCTAssertNotNil(createdUser.uuid)
+                XCTAssertNotNil(createdUser.created)
+                XCTAssertNotNil(createdUser.modified)
+                XCTAssertNotNil(createdUser.location)
                 XCTAssertEqual(createdUser.name!, User_Tests.name)
                 XCTAssertEqual(createdUser.age!, User_Tests.age)
                 XCTAssertEqual(createdUser.username!, User_Tests.username)
@@ -106,16 +136,162 @@ class User_Tests: XCTestCase {
                 XCTAssertEqual(createdUser.picture!, User_Tests.picture)
                 XCTAssertTrue(createdUser.activated)
                 XCTAssertFalse(createdUser.disabled)
+                XCTAssertFalse(createdUser.hasAsset)
+
+                self.deleteUser(userExpect)
+            }
+        }
+        self.waitForExpectationsWithTimeout(100, handler: nil)
+    }
+
+    func test_AUTHENTICATE_USER() {
+        let userExpect = self.expectationWithDescription("\(__FUNCTION__)")
+
+        UsergridUser.checkAvailable(user.email!,username: user.username) { error,available
in
+
+            XCTAssertNil(error)
+            XCTAssertTrue(available)
+
+            self.user.create() { (createResponse) in
+                XCTAssertNotNil(createResponse)
+                XCTAssertTrue(createResponse.ok)
+                XCTAssertNotNil(createResponse.user)
+                XCTAssertNotNil(createResponse.users)
+                XCTAssertNotNil(self.user.uuid)
+
+                self.user.login(self.user.username!, password:User_Tests.password) { (auth,
loggedInUser, error) -> Void in
+
+                    XCTAssertNil(error)
+                    XCTAssertNotNil(auth)
+                    XCTAssertNotNil(loggedInUser)
+                    XCTAssertEqual(auth, self.user.auth!)
+
+                    Usergrid.authenticateUser(self.user.auth!) { auth,currentUser,error in
+
+                        XCTAssertNil(error)
+                        XCTAssertNotNil(auth)
+                        XCTAssertNotNil(loggedInUser)
+                        XCTAssertEqual(auth, self.user.auth!)
+                        XCTAssertNotNil(Usergrid.currentUser)
+
+                        self.user.reauthenticate() { auth, user, error in
+                            XCTAssertNil(error)
+                            XCTAssertNotNil(auth)
+                            XCTAssertNotNil(loggedInUser)
+                            XCTAssertEqual(auth, self.user.auth!)
+                            XCTAssertNotNil(Usergrid.currentUser)
+
+                            self.user.logout() { response in
+                                XCTAssertNotNil(response)
+                                XCTAssertTrue(response.ok)
+                                XCTAssertNil(response.error)
+
+                                self.deleteUser(userExpect)
+                            }
+                        }
+                    }
+                }
+            }
+        }
+        self.waitForExpectationsWithTimeout(100, handler: nil)
+    }
+
+    func test_RESET_USER_PASSWORD() {
+        let userExpect = self.expectationWithDescription("\(__FUNCTION__)")
 
-                createdUser.remove(self.client) { (removeResponse) in
-                    XCTAssertNotNil(removeResponse)
-                    XCTAssertTrue(removeResponse.ok)
-                    XCTAssertNotNil(removeResponse.user)
-                    XCTAssertNotNil(removeResponse.users)
-                    createUserExpect.fulfill()
+        user.create() { (createResponse) in
+            XCTAssertNotNil(createResponse)
+            XCTAssertTrue(createResponse.ok)
+            XCTAssertNotNil(createResponse.user)
+            XCTAssertNotNil(createResponse.users)
+            XCTAssertNotNil(self.user.uuid)
+
+            self.user.login(self.user.username!, password:User_Tests.password) { (auth, loggedInUser,
error) -> Void in
+
+                XCTAssertNil(error)
+                XCTAssertNotNil(auth)
+                XCTAssertNotNil(loggedInUser)
+                XCTAssertEqual(auth, self.user.auth!)
+
+                self.user.resetPassword(User_Tests.password, new: User_Tests.resetPassword)
{ error,didSucceed in
+                    XCTAssertTrue(didSucceed)
+                    XCTAssertNil(error)
+
+                    self.user.login(self.user.username!, password:User_Tests.resetPassword)
{ (auth, loggedInUser, error) -> Void in
+                        XCTAssertNil(error)
+                        XCTAssertNotNil(auth)
+                        XCTAssertNotNil(loggedInUser)
+                        XCTAssertEqual(auth, self.user.auth!)
+
+                        self.deleteUser(userExpect)
+                    }
                 }
             }
         }
-        self.waitForExpectationsWithTimeout(10, handler: nil)
+        self.waitForExpectationsWithTimeout(100, handler: nil)
+    }
+
+    func test_DEVICE_CONNECTION() {
+        let userExpect = self.expectationWithDescription("\(__FUNCTION__)")
+
+        user.create() { createResponse in
+            XCTAssertNotNil(createResponse)
+            XCTAssertTrue(createResponse.ok)
+            XCTAssertNotNil(createResponse.user)
+            XCTAssertNotNil(createResponse.users)
+            XCTAssertNotNil(self.user.uuid)
+
+            self.user.connectToDevice() { connectResponse in
+                XCTAssertNotNil(connectResponse)
+                XCTAssertTrue(connectResponse.ok)
+                XCTAssertNil(connectResponse.error)
+
+                self.user.getConnectedDevice() { getConnectedDeviceResponse in
+                    XCTAssertNotNil(getConnectedDeviceResponse)
+                    XCTAssertTrue(getConnectedDeviceResponse.ok)
+                    XCTAssertNil(getConnectedDeviceResponse.error)
+                    XCTAssertNotNil(getConnectedDeviceResponse.entity)
+
+                    if let responseEntity = getConnectedDeviceResponse.entity {
+                        XCTAssertTrue(responseEntity is UsergridDevice)
+                    }
+
+                    self.user.disconnectFromDevice() { disconnectResponse in
+                        XCTAssertNotNil(disconnectResponse)
+                        XCTAssertTrue(disconnectResponse.ok)
+                        XCTAssertNil(disconnectResponse.error)
+
+                        self.deleteUser(userExpect)
+                    }
+                }
+            }
+        }
+        self.waitForExpectationsWithTimeout(100, handler: nil)
+    }
+
+    func test_USER_NSCODING() {
+        let userData = NSKeyedArchiver.archivedDataWithRootObject(user)
+        let newInstanceFromData = NSKeyedUnarchiver.unarchiveObjectWithData(userData) as?
UsergridUser
+
+        XCTAssertNotNil(newInstanceFromData)
+
+        if let newInstance = newInstanceFromData {
+            XCTAssertEqual(user.uuid,newInstance.uuid)
+            XCTAssertEqual(user.uuidOrName,newInstance.uuidOrName)
+            XCTAssertEqual(user.uuidOrUsername,newInstance.uuidOrUsername)
+            XCTAssertEqual(user.auth,newInstance.auth)
+            XCTAssertEqual(user.created,newInstance.created)
+            XCTAssertEqual(user.modified,newInstance.modified)
+            XCTAssertEqual(user.location!.coordinate.longitude,newInstance.location!.coordinate.longitude)
+            XCTAssertEqual(user.location!.coordinate.latitude,newInstance.location!.coordinate.latitude)
+            XCTAssertEqual(user.name,newInstance.name)
+            XCTAssertEqual(user.age,newInstance.age)
+            XCTAssertEqual(user.username,newInstance.username)
+            XCTAssertEqual(user.email,newInstance.email)
+            XCTAssertEqual(user.picture,newInstance.picture)
+            XCTAssertEqual(user.activated,newInstance.activated)
+            XCTAssertEqual(user.disabled,newInstance.disabled)
+            XCTAssertEqual(user.hasAsset,newInstance.hasAsset)
+        }
     }
 }
\ No newline at end of file


Mime
View raw message