See details. Added authMode. Fixed DEVICE_OSVERSION constant. UsergridQuery now always prefixes the query string with "select *". When registering the device for push notifications, "devices" is used instead of "device".
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/dd9ddb73 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/dd9ddb73 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/dd9ddb73 Branch: refs/heads/master Commit: dd9ddb7304b31c26e6f20864c232f88d076121d1 Parents: ebf43c7 Author: Robert Walsh <[email protected]> Authored: Thu Apr 7 18:10:28 2016 -0500 Committer: Robert Walsh <[email protected]> Committed: Thu Apr 7 18:10:28 2016 -0500 ---------------------------------------------------------------------- .../Samples/Push/Source/UsergridManager.swift | 2 +- sdks/swift/Source/Usergrid.swift | 6 +-- sdks/swift/Source/UsergridClient.swift | 39 +++++++++++++++----- sdks/swift/Source/UsergridClientConfig.swift | 14 +++---- sdks/swift/Source/UsergridEnums.swift | 16 ++++---- sdks/swift/Source/UsergridQuery.swift | 3 +- sdks/swift/Tests/AUTH_Tests.swift | 2 +- sdks/swift/Tests/CONNECTION_Tests.swift | 2 +- sdks/swift/Tests/ClientCreationTests.swift | 4 +- sdks/swift/Tests/GET_Tests.swift | 4 +- 10 files changed, 57 insertions(+), 35 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/dd9ddb73/sdks/swift/Samples/Push/Source/UsergridManager.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Samples/Push/Source/UsergridManager.swift b/sdks/swift/Samples/Push/Source/UsergridManager.swift index a916b75..00e8ec2 100644 --- a/sdks/swift/Samples/Push/Source/UsergridManager.swift +++ b/sdks/swift/Samples/Push/Source/UsergridManager.swift @@ -63,7 +63,7 @@ public class UsergridManager { } static func pushToThisDevice() { - UsergridManager.sendPush(deviceId: UsergridDevice.sharedDevice.uuid, message: "Push to this device message.") + UsergridManager.sendPush(deviceId: UsergridDevice.sharedDevice.uuid!, message: "Push to this device message.") } static func pushToAllDevices() { http://git-wip-us.apache.org/repos/asf/usergrid/blob/dd9ddb73/sdks/swift/Source/Usergrid.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Source/Usergrid.swift b/sdks/swift/Source/Usergrid.swift index 19444a0..14bda2f 100644 --- a/sdks/swift/Source/Usergrid.swift +++ b/sdks/swift/Source/Usergrid.swift @@ -88,9 +88,9 @@ public class Usergrid: NSObject { } /// The `UsergridAuthFallback` value used to determine what type of token will be sent of the shared instance of `UsergridClient`, if any. - public static var authFallback: UsergridAuthFallback { - get { return Usergrid.sharedInstance.authFallback } - set(authFallback) { Usergrid.sharedInstance.authFallback = authFallback } + public static var authMode: UsergridAuthMode { + get { return Usergrid.sharedInstance.authMode } + set(mode) { Usergrid.sharedInstance.authMode = mode } } // MARK: - Initialization - http://git-wip-us.apache.org/repos/asf/usergrid/blob/dd9ddb73/sdks/swift/Source/UsergridClient.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Source/UsergridClient.swift b/sdks/swift/Source/UsergridClient.swift index 95bc481..41cf8e6 100644 --- a/sdks/swift/Source/UsergridClient.swift +++ b/sdks/swift/Source/UsergridClient.swift @@ -85,9 +85,9 @@ public class UsergridClient: NSObject, NSCoding { } /// The `UsergridAuthFallback` value used to determine what type of token will be sent, if any. - public var authFallback: UsergridAuthFallback { - get { return config.authFallback } - set(fallback) { config.authFallback = fallback } + public var authMode: UsergridAuthMode { + get { return config.authMode } + set(mode) { config.authMode = mode } } // MARK: - Initialization - @@ -196,7 +196,12 @@ public class UsergridClient: NSObject, NSCoding { */ public func applyPushToken(device: UsergridDevice, pushToken: NSData, notifierID: String, completion: UsergridResponseCompletion? = nil) { device.applyPushToken(pushToken, notifierID: notifierID) - device.save(self, completion: completion) + self.PUT("devices", jsonBody: device.jsonObjectValue) { (response) in + if let responseEntity = response.entity { + device.copyInternalsFromEntity(responseEntity) + } + completion?(response: response) + } } // MARK: - Authorization and User Management - @@ -214,13 +219,27 @@ public class UsergridClient: NSObject, NSCoding { */ public func authForRequests() -> UsergridAuth? { var usergridAuth: UsergridAuth? - if let tempAuth = self.tempAuth where tempAuth.isValid { - usergridAuth = tempAuth + if let tempAuth = self.tempAuth { + if tempAuth.isValid { + usergridAuth = tempAuth + } self.tempAuth = nil - } else if let userAuth = self.userAuth where userAuth.isValid { - usergridAuth = userAuth - } else if self.authFallback == .App, let appAuth = self.appAuth where appAuth.isValid { - usergridAuth = appAuth + } else { + switch(self.authMode) { + case .User: + if let userAuth = self.userAuth where userAuth.isValid { + usergridAuth = userAuth + } + break + case .App: + if let appAuth = self.appAuth where appAuth.isValid { + usergridAuth = appAuth + } + break + case .None: + usergridAuth = nil + break + } } return usergridAuth } http://git-wip-us.apache.org/repos/asf/usergrid/blob/dd9ddb73/sdks/swift/Source/UsergridClientConfig.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Source/UsergridClientConfig.swift b/sdks/swift/Source/UsergridClientConfig.swift index 3f68ee8..64ebd4f 100644 --- a/sdks/swift/Source/UsergridClientConfig.swift +++ b/sdks/swift/Source/UsergridClientConfig.swift @@ -44,8 +44,8 @@ public class UsergridClientConfig : NSObject, NSCoding { /// The base URL that all calls will be made with. public var baseUrl: String = UsergridClient.DEFAULT_BASE_URL - /// The `UsergridAuthFallback` value used to determine what type of token will be sent, if any. - public var authFallback: UsergridAuthFallback = .None + /// The `UsergridAuthMode` value used to determine what type of token will be sent, if any. + public var authMode: UsergridAuthMode = .User /// Whether or not the `UsergridClient` current user will be saved and restored from the keychain. public var persistCurrentUserInKeychain: Bool = true @@ -92,16 +92,16 @@ public class UsergridClientConfig : NSObject, NSCoding { - parameter orgId: The organization identifier. - parameter appId: The application identifier. - parameter baseUrl: The base URL that all calls will be made with. - - parameter authFallback: The `UsergridAuthFallback` value used to determine what type of token will be sent, if any. + - parameter authMode: The `UsergridAuthMode` value used to determine what type of token will be sent, if any. - parameter persistCurrentUserInKeychain: Whether or not the `UsergridClient` current user will be saved and restored from the keychain. - parameter appAuth: The application level `UsergridAppAuth` object. - returns: A new instance of `UsergridClientConfig`. */ - public convenience init(orgId: String, appId: String, baseUrl:String, authFallback:UsergridAuthFallback, persistCurrentUserInKeychain: Bool = true, appAuth:UsergridAppAuth? = nil) { + public convenience init(orgId: String, appId: String, baseUrl:String, authMode:UsergridAuthMode, persistCurrentUserInKeychain: Bool = true, appAuth:UsergridAppAuth? = nil) { self.init(orgId:orgId,appId:appId,baseUrl:baseUrl) self.persistCurrentUserInKeychain = persistCurrentUserInKeychain - self.authFallback = authFallback + self.authMode = authMode self.appAuth = appAuth } @@ -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")) ?? .None + self.authMode = UsergridAuthMode(rawValue:aDecoder.decodeIntegerForKey("authMode")) ?? .None super.init() } @@ -144,6 +144,6 @@ public class UsergridClientConfig : NSObject, NSCoding { aCoder.encodeObject(self.baseUrl, forKey: "baseUrl") aCoder.encodeObject(self.appAuth, forKey: "appAuth") aCoder.encodeBool(self.persistCurrentUserInKeychain, forKey: "persistCurrentUserInKeychain") - aCoder.encodeInteger(self.authFallback.rawValue, forKey: "authFallback") + aCoder.encodeInteger(self.authMode.rawValue, forKey: "authMode") } } http://git-wip-us.apache.org/repos/asf/usergrid/blob/dd9ddb73/sdks/swift/Source/UsergridEnums.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Source/UsergridEnums.swift b/sdks/swift/Source/UsergridEnums.swift index 1cc0c9c..a2468af 100644 --- a/sdks/swift/Source/UsergridEnums.swift +++ b/sdks/swift/Source/UsergridEnums.swift @@ -27,9 +27,9 @@ import Foundation /** -An enumeration that is used to determine what the `UsergridClient` will fallback to depending on certain authorization conditions. +An enumeration that is used to determine what the `UsergridClient` will use for authorization. */ -@objc public enum UsergridAuthFallback : Int { +@objc public enum UsergridAuthMode : Int { // MARK: - Values - @@ -37,16 +37,16 @@ An enumeration that is used to determine what the `UsergridClient` will fallback If a non-expired user auth token exists in `UsergridClient.currentUser`, this token is used to authenticate all API calls. If the API call fails, the activity is treated as a failure with an appropriate HTTP status code. - - If a non-expired user auth token does not exist, all API calls will be made unauthenticated. */ case None + /** - If a non-expired user auth token exists in `UsergridClient.currentUser`, this token is used to authenticate all API calls. + If the API call fails, the activity is treated as a failure with an appropriate HTTP status code (This behavior is identical to authFallback=.None). + */ + case User + /** If the API call fails, the activity is treated as a failure with an appropriate HTTP status code (This behavior is identical to authFallback=.None). - - If a non-expired user auth does not exist, all API calls will be made using stored app auth. */ case App } @@ -406,7 +406,7 @@ let USER_PICTURE = "picture" let DEVICE_MODEL = "deviceModel" let DEVICE_PLATFORM = "devicePlatform" -let DEVICE_OSVERSION = "devicePlatform" +let DEVICE_OSVERSION = "deviceOSVersion" let ASSET_IMAGE_PNG = "image/png" let ASSET_IMAGE_JPEG = "image/jpeg" http://git-wip-us.apache.org/repos/asf/usergrid/blob/dd9ddb73/sdks/swift/Source/UsergridQuery.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Source/UsergridQuery.swift b/sdks/swift/Source/UsergridQuery.swift index 7d08e35..c2a7000 100644 --- a/sdks/swift/Source/UsergridQuery.swift +++ b/sdks/swift/Source/UsergridQuery.swift @@ -528,7 +528,7 @@ public class UsergridQuery : NSObject,NSCopying { urlAppend += "\(UsergridQuery.CURSOR)=\(cursorString)" } - var requirementsString = self.constructRequirementString() + var requirementsString = UsergridQuery.SELECT_ALL + UsergridQuery.SPACE + self.constructRequirementString() let orderByString = self.constructOrderByString() if !orderByString.isEmpty { requirementsString += orderByString @@ -577,6 +577,7 @@ public class UsergridQuery : NSObject,NSCopying { private static let ORDER_BY = "order by" private static let QL = "ql" private static let QUESTION_MARK = "?" + private static let SELECT_ALL = "select *" private static let SPACE = " " private static let WITHIN = "within" http://git-wip-us.apache.org/repos/asf/usergrid/blob/dd9ddb73/sdks/swift/Tests/AUTH_Tests.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Tests/AUTH_Tests.swift b/sdks/swift/Tests/AUTH_Tests.swift index ca96e59..6b4a4d2 100644 --- a/sdks/swift/Tests/AUTH_Tests.swift +++ b/sdks/swift/Tests/AUTH_Tests.swift @@ -50,7 +50,7 @@ class AUTH_Tests: XCTestCase { func test_CLIENT_AUTH() { let authExpect = self.expectationWithDescription("\(__FUNCTION__)") - Usergrid.authFallback = .App + Usergrid.authMode = .App Usergrid.authenticateApp(appAuth) { auth,error in XCTAssertTrue(NSThread.isMainThread()) XCTAssertNil(error) http://git-wip-us.apache.org/repos/asf/usergrid/blob/dd9ddb73/sdks/swift/Tests/CONNECTION_Tests.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Tests/CONNECTION_Tests.swift b/sdks/swift/Tests/CONNECTION_Tests.swift index 8eb9f94..4902fa8 100644 --- a/sdks/swift/Tests/CONNECTION_Tests.swift +++ b/sdks/swift/Tests/CONNECTION_Tests.swift @@ -45,7 +45,7 @@ class CONNECTION_Tests: XCTestCase { func test_CLIENT_AUTH() { let authExpect = self.expectationWithDescription("\(__FUNCTION__)") - Usergrid.authFallback = .App + Usergrid.authMode = .App Usergrid.authenticateApp(clientAuth) { auth,error in XCTAssertTrue(NSThread.isMainThread()) XCTAssertNil(error) http://git-wip-us.apache.org/repos/asf/usergrid/blob/dd9ddb73/sdks/swift/Tests/ClientCreationTests.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Tests/ClientCreationTests.swift b/sdks/swift/Tests/ClientCreationTests.swift index c7e57a4..40a7de1 100644 --- a/sdks/swift/Tests/ClientCreationTests.swift +++ b/sdks/swift/Tests/ClientCreationTests.swift @@ -50,7 +50,7 @@ class ClientCreationTests: XCTestCase { func test_CLIENT_PROPERTIES() { XCTAssertEqual(Usergrid.appId, ClientCreationTests.appId) XCTAssertEqual(Usergrid.orgId, ClientCreationTests.orgId) - XCTAssertEqual(Usergrid.authFallback, UsergridAuthFallback.None) + XCTAssertEqual(Usergrid.authMode, UsergridAuthMode.User) XCTAssertEqual(Usergrid.persistCurrentUserInKeychain, false) XCTAssertEqual(Usergrid.baseUrl, UsergridClient.DEFAULT_BASE_URL) XCTAssertEqual(Usergrid.clientAppURL, "\(UsergridClient.DEFAULT_BASE_URL)/\(ClientCreationTests.orgId)/\(ClientCreationTests.appId)" ) @@ -67,7 +67,7 @@ class ClientCreationTests: XCTestCase { if let newInstance = newInstanceFromData { XCTAssertEqual(Usergrid.appId, newInstance.appId) XCTAssertEqual(Usergrid.orgId, newInstance.orgId) - XCTAssertEqual(Usergrid.authFallback, newInstance.authFallback) + XCTAssertEqual(Usergrid.authMode, newInstance.authMode) XCTAssertEqual(Usergrid.baseUrl, newInstance.baseUrl) } } http://git-wip-us.apache.org/repos/asf/usergrid/blob/dd9ddb73/sdks/swift/Tests/GET_Tests.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Tests/GET_Tests.swift b/sdks/swift/Tests/GET_Tests.swift index efb899e..aedb27e 100644 --- a/sdks/swift/Tests/GET_Tests.swift +++ b/sdks/swift/Tests/GET_Tests.swift @@ -32,7 +32,7 @@ class GET_Tests: XCTestCase { static let collectionName = "books" static let entityUUID = "f4078aca-2fb1-11e5-8eb2-e13f8369aad1" - let query = UsergridQuery(GET_Tests.collectionName).fromString("select * where title = 'The Sun Also Rises' or title = 'The Old Man and the Sea'") + let query = UsergridQuery(GET_Tests.collectionName).eq("title", value: "The Sun Also Rises").or().eq("title", value: "The Old Man and the Sea") override func setUp() { super.setUp() @@ -91,6 +91,8 @@ class GET_Tests: XCTestCase { func test_GET_NEXT_PAGE_WITH_NO_QUERY() { let getExpect = self.expectationWithDescription("\(__FUNCTION__)") + + Usergrid.GET(GET_Tests.collectionName) { (response) in XCTAssertTrue(NSThread.isMainThread()) XCTAssertNotNil(response)
