Minor updates.

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

Branch: refs/heads/master
Commit: 5f15161a7d049338791321d5072fa34d80fa0d9e
Parents: 891e0f2
Author: Robert Walsh <rjwalsh1...@gmail.com>
Authored: Fri Feb 19 13:18:14 2016 -0600
Committer: Robert Walsh <rjwalsh1...@gmail.com>
Committed: Fri Feb 19 13:18:14 2016 -0600

----------------------------------------------------------------------
 sdks/swift/Source/UsergridClient.swift         |  4 +-
 sdks/swift/Source/UsergridEntity.swift         |  4 +-
 sdks/swift/Source/UsergridExtensions.swift     | 43 ++++++++++++++++++---
 sdks/swift/Source/UsergridFileMetaData.swift   |  4 +-
 sdks/swift/Source/UsergridRequest.swift        |  2 +-
 sdks/swift/Source/UsergridRequestManager.swift | 12 +++---
 sdks/swift/Source/UsergridResponse.swift       |  6 +--
 7 files changed, 53 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f15161a/sdks/swift/Source/UsergridClient.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Source/UsergridClient.swift 
b/sdks/swift/Source/UsergridClient.swift
index 8ebd934..95bc481 100644
--- a/sdks/swift/Source/UsergridClient.swift
+++ b/sdks/swift/Source/UsergridClient.swift
@@ -51,7 +51,7 @@ public class UsergridClient: NSObject, NSCoding {
     public var baseUrl : String { return config.baseUrl }
 
     /// The constructed URL string based on the `UsergridClient`'s `baseUrl`, 
`orgId`, and `appId`.
-    internal var clientAppURL : String { return "\(baseUrl)/\(orgId)/\(appId)" 
}
+    public var clientAppURL : String { return "\(baseUrl)/\(orgId)/\(appId)" }
 
     /// Whether or not the current user will be saved and restored from the 
keychain.
     public var persistCurrentUserInKeychain: Bool {
@@ -212,7 +212,7 @@ public class UsergridClient: NSObject, NSCoding {
 
     - returns: The `UsergridAuth` if one is found or nil if not.
     */
-    internal func authForRequests() -> UsergridAuth? {
+    public func authForRequests() -> UsergridAuth? {
         var usergridAuth: UsergridAuth?
         if let tempAuth = self.tempAuth where tempAuth.isValid {
             usergridAuth = tempAuth

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f15161a/sdks/swift/Source/UsergridEntity.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Source/UsergridEntity.swift 
b/sdks/swift/Source/UsergridEntity.swift
index 75b35b9..dd169ed 100644
--- a/sdks/swift/Source/UsergridEntity.swift
+++ b/sdks/swift/Source/UsergridEntity.swift
@@ -399,8 +399,8 @@ public class UsergridEntity: NSObject, NSCoding {
             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)
+                if let milliseconds = 
self.properties[entityProperty.stringValue] as? Int {
+                    propertyValue = NSDate(milliseconds: 
milliseconds.description)
                 }
             case .Location :
                 if let locationDict = 
self.properties[entityProperty.stringValue] as? [String:Double], lat = 
locationDict[ENTITY_LATITUDE], long = locationDict[ENTITY_LONGITUDE] {

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f15161a/sdks/swift/Source/UsergridExtensions.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Source/UsergridExtensions.swift 
b/sdks/swift/Source/UsergridExtensions.swift
index 050145c..404c608 100644
--- a/sdks/swift/Source/UsergridExtensions.swift
+++ b/sdks/swift/Source/UsergridExtensions.swift
@@ -26,12 +26,35 @@
 
 import Foundation
 
-internal extension NSDate {
-    convenience init(utcTimeStamp: String) {
-        self.init(timeIntervalSince1970: (utcTimeStamp as 
NSString).doubleValue / 1000 )
+private let kUsergrid_Milliseconds_Per_Second = 1000
+
+public extension NSDate {
+    public convenience init(milliseconds: String) {
+        self.init(timeIntervalSince1970: (milliseconds as 
NSString).doubleValue / Double(kUsergrid_Milliseconds_Per_Second) )
+    }
+    public func dateAsMilliseconds() -> Int {
+        return Int(self.timeIntervalSince1970 * 
Double(kUsergrid_Milliseconds_Per_Second))
+    }
+    public func dateAsMillisecondsString() -> String {
+        return NSDate.stringFromMilleseconds(self.dateAsMilliseconds())
     }
-    func utcTimeStamp() -> Int {
-        return Int(self.timeIntervalSince1970 * 1000)
+    public static func stringFromMilleseconds(milliseconds:Int) -> String {
+        return NSNumber(longLong: Int64(milliseconds)).stringValue
+    }
+    public static func unixTimeStampString() -> String {
+        return NSDate.stringFromMilleseconds(NSDate.nowAsMilliseconds())
+    }
+    public static func unixTimeStamp() -> Int {
+        return NSDate.nowAsMilliseconds()
+    }
+
+    public static func nowAsMilliseconds() -> Int {
+        var tv = timeval()
+        let currentMillisecondTime = withUnsafeMutablePointer(&tv, { (t: 
UnsafeMutablePointer<timeval>) -> Int in
+            gettimeofday(t, nil)
+            return (Int(t.memory.tv_sec) * kUsergrid_Milliseconds_Per_Second) 
+ (Int(t.memory.tv_usec) / kUsergrid_Milliseconds_Per_Second)
+        })
+        return currentMillisecondTime
     }
 }
 
@@ -39,4 +62,12 @@ internal extension String {
     func isUuid() -> Bool {
         return (NSUUID(UUIDString: self) != nil) ? true : false
     }
-}
\ No newline at end of file
+}
+
+internal extension Dictionary {
+    mutating func update(other:Dictionary) {
+        for (key,value) in other {
+            self.updateValue(value, forKey:key)
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f15161a/sdks/swift/Source/UsergridFileMetaData.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Source/UsergridFileMetaData.swift 
b/sdks/swift/Source/UsergridFileMetaData.swift
index c3e7f52..4908430 100644
--- a/sdks/swift/Source/UsergridFileMetaData.swift
+++ b/sdks/swift/Source/UsergridFileMetaData.swift
@@ -70,7 +70,7 @@ public class UsergridFileMetaData : NSObject,NSCoding {
         self.lastModifiedTimeStamp = fileMetaDataJSON["last-modified"] as? Int 
?? 0
 
         if self.lastModifiedTimeStamp > 0 {
-            self.lastModifiedDate = NSDate(utcTimeStamp: 
self.lastModifiedTimeStamp.description)
+            self.lastModifiedDate = NSDate(milliseconds: 
self.lastModifiedTimeStamp.description)
         } else {
             self.lastModifiedDate = nil
         }
@@ -93,7 +93,7 @@ public class UsergridFileMetaData : NSObject,NSCoding {
         self.lastModifiedTimeStamp = 
aDecoder.decodeIntegerForKey("last-modified") ?? 0
 
         if self.lastModifiedTimeStamp > 0 {
-            self.lastModifiedDate = NSDate(utcTimeStamp: 
self.lastModifiedTimeStamp.description)
+            self.lastModifiedDate = NSDate(milliseconds: 
self.lastModifiedTimeStamp.description)
         } else {
             self.lastModifiedDate = nil
         }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f15161a/sdks/swift/Source/UsergridRequest.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Source/UsergridRequest.swift 
b/sdks/swift/Source/UsergridRequest.swift
index dd1f561..0a651e2 100644
--- a/sdks/swift/Source/UsergridRequest.swift
+++ b/sdks/swift/Source/UsergridRequest.swift
@@ -177,7 +177,7 @@ public class UsergridRequest : NSObject {
 
     private static let AUTHORIZATION = "Authorization"
     private static let ACCESS_TOKEN = "access_token"
-    private static let APPLICATION_JSON = "application/json"
+    private static let APPLICATION_JSON = "application/json; charset=utf-8"
     private static let BEARER = "Bearer"
     private static let CONTENT_LENGTH = "Content-Length"
     private static let CONTENT_TYPE = "Content-Type"

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f15161a/sdks/swift/Source/UsergridRequestManager.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Source/UsergridRequestManager.swift 
b/sdks/swift/Source/UsergridRequestManager.swift
index 65fde19..46a4213 100644
--- a/sdks/swift/Source/UsergridRequestManager.swift
+++ b/sdks/swift/Source/UsergridRequestManager.swift
@@ -74,7 +74,7 @@ final class UsergridRequestManager {
 // MARK: - Authentication -
 extension UsergridRequestManager {
 
-    static func getTokenAndExpiryFromResponseJSON(jsonDict:[String:AnyObject]) 
-> (String?,NSDate?) {
+    static func getTokenAndExpiryFromResponseJSON(jsonDict:[String:AnyObject]) 
-> (token:String?,expiry:NSDate?) {
         var token: String? = nil
         var expiry: NSDate? = nil
         if let accessToken = jsonDict["access_token"] as? String {
@@ -82,7 +82,7 @@ extension UsergridRequestManager {
         }
         if let expiresIn = jsonDict["expires_in"] as? Int {
             let expiresInAdjusted = expiresIn - 5000
-            expiry = NSDate(timeIntervalSinceNow: Double(expiresInAdjusted))
+            expiry = NSDate(timeIntervalSinceNow: 
NSTimeInterval(expiresInAdjusted))
         }
         return (token,expiry)
     }
@@ -96,8 +96,8 @@ extension UsergridRequestManager {
 
             if let jsonDict = dataAsJSON as? [String:AnyObject] {
                 let tokenAndExpiry = 
UsergridRequestManager.getTokenAndExpiryFromResponseJSON(jsonDict)
-                userAuth.accessToken = tokenAndExpiry.0
-                userAuth.expiry = tokenAndExpiry.1
+                userAuth.accessToken = tokenAndExpiry.token
+                userAuth.expiry = tokenAndExpiry.expiry
 
                 if let userDict = jsonDict[UsergridUser.USER_ENTITY_TYPE] as? 
[String:AnyObject] {
                     if let newUser = UsergridEntity.entity(jsonDict: userDict) 
as? UsergridUser {
@@ -126,8 +126,8 @@ extension UsergridRequestManager {
 
             if let jsonDict = dataAsJSON as? [String:AnyObject] {
                 let tokenAndExpiry = 
UsergridRequestManager.getTokenAndExpiryFromResponseJSON(jsonDict)
-                appAuth.accessToken = tokenAndExpiry.0
-                appAuth.expiry = tokenAndExpiry.1
+                appAuth.accessToken = tokenAndExpiry.token
+                appAuth.expiry = tokenAndExpiry.expiry
             } else {
                 responseError = UsergridResponseError(errorName: "Auth 
Failed.", errorDescription: "Error Description: 
\(error?.localizedDescription).")
             }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/5f15161a/sdks/swift/Source/UsergridResponse.swift
----------------------------------------------------------------------
diff --git a/sdks/swift/Source/UsergridResponse.swift 
b/sdks/swift/Source/UsergridResponse.swift
index d2b025d..b9e58ec 100644
--- a/sdks/swift/Source/UsergridResponse.swift
+++ b/sdks/swift/Source/UsergridResponse.swift
@@ -95,11 +95,11 @@ public class UsergridResponse: NSObject {
     public var hasNextPage: Bool { return self.cursor != nil }
 
     /// The string value.
-    public var stringValue : String? {
+    public var stringValue : String {
         if let responseJSON = self.responseJSON {
-            return NSString(data: try! 
NSJSONSerialization.dataWithJSONObject(responseJSON, options: .PrettyPrinted), 
encoding: NSUTF8StringEncoding) as? String
+            return NSString(data: try! 
NSJSONSerialization.dataWithJSONObject(responseJSON, options: .PrettyPrinted), 
encoding: NSUTF8StringEncoding) as? String ?? ""
         } else {
-            return error?.description
+            return error?.description ?? ""
         }
     }
 

Reply via email to