Fixed UsergridClient.uploadAsset(). While the UsergridClient.uploadAsset() was setting the requesting entities.asset it wasnt setting the fileMetaData.
Also upon initialization of UsergridEntity objects the fileMetaData was not being set properly. Now that is fixed. Also updated the UsergridAsset initialization functions to use filename instead of fileName for parameter names. Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/865560c0 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/865560c0 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/865560c0 Branch: refs/heads/master Commit: 865560c063220c613b562cfd8778b9bc8dda01ce Parents: 9f53f58 Author: Robert Walsh <rjwalsh1...@gmail.com> Authored: Wed Feb 17 12:26:35 2016 -0600 Committer: Robert Walsh <rjwalsh1...@gmail.com> Committed: Wed Feb 17 12:26:35 2016 -0600 ---------------------------------------------------------------------- sdks/swift/Source/UsergridAsset.swift | 12 ++++++------ sdks/swift/Source/UsergridClient.swift | 7 ++++++- sdks/swift/Source/UsergridEntity.swift | 10 ++++++++-- 3 files changed, 20 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/865560c0/sdks/swift/Source/UsergridAsset.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Source/UsergridAsset.swift b/sdks/swift/Source/UsergridAsset.swift index 73f0bd3..9353ec1 100644 --- a/sdks/swift/Source/UsergridAsset.swift +++ b/sdks/swift/Source/UsergridAsset.swift @@ -47,7 +47,7 @@ Unless defined, whenever possible, the content-type will be inferred from the da */ public class UsergridAsset: NSObject, NSCoding { - private static let DEFAULT_FILE_NAME = "file" + internal static let DEFAULT_FILE_NAME = "file" // MARK: - Instance Properties - @@ -95,7 +95,7 @@ public class UsergridAsset: NSObject, NSCoding { - returns: A new instance of `UsergridAsset` if the data can be gathered from the passed in `UIImage`, otherwise nil. */ - public convenience init?(fileName:String? = UsergridAsset.DEFAULT_FILE_NAME, image:UIImage, imageContentType:UsergridImageContentType = .Png) { + public convenience init?(filename:String? = UsergridAsset.DEFAULT_FILE_NAME, image:UIImage, imageContentType:UsergridImageContentType = .Png) { var imageData: NSData? switch(imageContentType) { case .Png : @@ -104,7 +104,7 @@ public class UsergridAsset: NSObject, NSCoding { imageData = UIImageJPEGRepresentation(image, 1.0) } if let assetData = imageData { - self.init(filename:fileName,data:assetData,contentType:imageContentType.stringValue) + self.init(filename:filename,data:assetData,contentType:imageContentType.stringValue) } else { self.init(filename:"",data:NSData(),contentType:"") return nil @@ -121,9 +121,9 @@ public class UsergridAsset: NSObject, NSCoding { - returns: A new instance of `UsergridAsset` if the data can be gathered from the passed in `NSURL`, otherwise nil. */ - public convenience init?(fileName:String? = UsergridAsset.DEFAULT_FILE_NAME, fileURL:NSURL, contentType:String? = nil) { + public convenience init?(filename:String? = UsergridAsset.DEFAULT_FILE_NAME, fileURL:NSURL, contentType:String? = nil) { if fileURL.fileURL, let assetData = NSData(contentsOfURL: fileURL) { - var fileNameToUse = fileName + var fileNameToUse = filename if fileNameToUse != UsergridAsset.DEFAULT_FILE_NAME, let inferredFileName = fileURL.lastPathComponent { fileNameToUse = inferredFileName } @@ -135,7 +135,7 @@ public class UsergridAsset: NSObject, NSCoding { return nil } } else { - print("Usergrid Error: fileURL parameter must be a file reference URL.") + print("Usergrid Error: fileURL parameter must be a file URL.") self.init(filename:"",data:NSData(),contentType:"") return nil } http://git-wip-us.apache.org/repos/asf/usergrid/blob/865560c0/sdks/swift/Source/UsergridClient.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Source/UsergridClient.swift b/sdks/swift/Source/UsergridClient.swift index 46310c6..8ebd934 100644 --- a/sdks/swift/Source/UsergridClient.swift +++ b/sdks/swift/Source/UsergridClient.swift @@ -873,7 +873,12 @@ public class UsergridClient: NSObject, NSCoding { asset: asset) _requestManager.performAssetUpload(assetRequest, progress: progress) { asset, response in - entity.asset = asset + if response.ok { + entity.asset = asset + if let responseEntityFileMetaData = response.entity?.fileMetaData { + entity.fileMetaData = responseEntityFileMetaData + } + } completion?(asset: asset, response: response) } } http://git-wip-us.apache.org/repos/asf/usergrid/blob/865560c0/sdks/swift/Source/UsergridEntity.swift ---------------------------------------------------------------------- diff --git a/sdks/swift/Source/UsergridEntity.swift b/sdks/swift/Source/UsergridEntity.swift index 322ef29..75b35b9 100644 --- a/sdks/swift/Source/UsergridEntity.swift +++ b/sdks/swift/Source/UsergridEntity.swift @@ -50,10 +50,10 @@ public class UsergridEntity: NSObject, NSCoding { } /// The `UsergridAsset` that contains the asset data. - public var asset: UsergridAsset? + internal(set) public var asset: UsergridAsset? /// The `UsergridFileMetaData` of this `UsergridEntity`. - private(set) public var fileMetaData : UsergridFileMetaData? + internal(set) public var fileMetaData : UsergridFileMetaData? /// Property helper method for the `UsergridEntity` objects `UsergridEntityProperties.EntityType`. public var type: String { return self.getEntitySpecificProperty(.EntityType) as! String } @@ -115,6 +115,7 @@ public class UsergridEntity: NSObject, NSCoding { required public init(type:String, name:String? = nil, propertyDict:[String:AnyObject]? = nil) { self.properties = propertyDict ?? [:] super.init() + if self is UsergridUser { self.properties[UsergridEntityProperties.EntityType.stringValue] = UsergridUser.USER_ENTITY_TYPE } else if self is UsergridDevice { @@ -122,9 +123,14 @@ public class UsergridEntity: NSObject, NSCoding { } else { self.properties[UsergridEntityProperties.EntityType.stringValue] = type } + if let entityName = name { self.properties[UsergridEntityProperties.Name.stringValue] = entityName } + + if let fileMetaData = self.properties.removeValueForKey(UsergridFileMetaData.FILE_METADATA) as? [String:AnyObject] { + self.fileMetaData = UsergridFileMetaData(fileMetaDataJSON: fileMetaData) + } } internal func copyInternalsFromEntity(entity:UsergridEntity) {