Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added createdAt, updatedAt and deletedAt dates

  • Loading branch information...
commit 289513ded9bf7bf6a88856f63c2c577d4abb2e5e 1 parent 7f9280f
@matthiasplappert matthiasplappert authored
View
40 Wrapper/API Parsing/CLAPIDeserializer.m
@@ -14,6 +14,14 @@
#import "NSString+NPMimeType.h"
#import "NSURL+IFUnicodeURL.h"
+
+@interface CLAPIDeserializer (Private)
+
++ (NSDate *)_dateFromDictionary:(NSDictionary *)dict forKey:(NSString *)key;
+
+@end
+
+
@implementation CLAPIDeserializer
+ (CLAccount *)accountWithJSONDictionaryData:(NSData *)jsonData {
@@ -82,6 +90,10 @@ + (CLWebItem *)webItemWithAPIDictionary:(NSDictionary *)jsonDict {
webItem.trashed = ([jsonDict objectForKey:@"deleted_at"] != nil && ![[NSNull null] isEqual:[jsonDict objectForKey:@"deleted_at"]]);
webItem.iconURL = [NSURL URLWithString:[jsonDict objectForKey:@"icon"]];
webItem.private = [[jsonDict objectForKey:@"private"] isEqual:@"true"];
+ webItem.createdAt = [CLAPIDeserializer _dateFromDictionary:jsonDict forKey:@"created_at"];
+ webItem.updatedAt = [CLAPIDeserializer _dateFromDictionary:jsonDict forKey:@"updated_at"];
+ webItem.deletedAt = [CLAPIDeserializer _dateFromDictionary:jsonDict forKey:@"deleted_at"];
+
return webItem;
}
@@ -134,4 +146,32 @@ + (NSURLRequest *)URLRequestWithS3ParametersDictionary:(NSDictionary *)s3Dict fi
return request;
}
+#pragma mark -
+#pragma mark Private
+
++ (NSDate *)_dateFromDictionary:(NSDictionary *)dict forKey:(NSString *)key
+{
+ // Date parsing
+ static NSDateFormatter *dateFormatter = nil;
+ if (dateFormatter == nil) {
+ dateFormatter = [[NSDateFormatter alloc] init];
+
+ // Set locale to US to avoid formatting issues
+ NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"US"];
+ [dateFormatter setLocale:locale];
+ [locale release];
+
+ [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; // GMT timezone
+ [dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss'Z'"]; // example: 2010-06-21T12:51:06Z
+ }
+
+ NSString *dateString = [dict objectForKey:key];
+ if (dateString == nil || ![dateString isKindOfClass:[NSString class]]) {
+ // Invalid date
+ return nil;
+ }
+
+ return [dateFormatter dateFromString:dateString];
+}
+
@end
View
6 Wrapper/Model/CLWebItem.h
@@ -26,6 +26,9 @@
#endif
BOOL _trashed;
BOOL _private;
+ NSDate *_createdAt;
+ NSDate *_updatedAt;
+ NSDate *_deletedAt;
}
@property (nonatomic, readwrite, copy) NSString *name;
@@ -44,6 +47,9 @@
#endif
@property (nonatomic, readwrite, assign) BOOL trashed;
@property (nonatomic, readwrite, assign, getter=isPrivate) BOOL private;
+@property (nonatomic, readwrite, retain) NSDate *createdAt;
+@property (nonatomic, readwrite, retain) NSDate *updatedAt;
+@property (nonatomic, readwrite, retain) NSDate *deletedAt;
- (id)initWithName:(NSString *)theName;
- (id)initWithName:(NSString *)theName type:(CLWebItemType)theType viewCount:(NSInteger)theCount;
View
15 Wrapper/Model/CLWebItem.m
@@ -20,10 +20,14 @@
static NSString * const CLWebItemIconKey = @"CLWebItemIconKey";
static NSString * const CLWebItemTrashedKey = @"CLWebItemTrashedKey";
static NSString * const CLWebItemPrivateKey = @"CLWebItemPrivateKey";
+static NSString * const CLWebItemCreatedAtKey = @"CLWebItemCreatedAtKey";
+static NSString * const CLWebItemUpdatedAtKey = @"CLWebItemUpdatedAtKey";
+static NSString * const CLWebItemDeletedAtKey = @"CLWebItemDeletedAtKey";
@implementation CLWebItem
@synthesize name = _name, type = _type, contentURL = _contentURL, mimeType = _mimeType, viewCount = _viewCount, remoteURL = _remoteURL,
- href = _href, URL = _URL, iconURL = _iconURL, icon = _icon, trashed = _trashed, private = _private;
+ href = _href, URL = _URL, iconURL = _iconURL, icon = _icon, trashed = _trashed, private = _private, createdAt = _createdAt,
+ updatedAt = _updatedAt, deletedAt = _deletedAt;
- (id)init {
return [self initWithName:nil];
@@ -93,6 +97,9 @@ - (id)initWithCoder:(NSCoder *)decoder {
_private = [decoder decodeBoolForKey:CLWebItemPrivateKey];
_iconURL = [[decoder decodeObjectForKey:CLWebItemIconURLKey] retain];
_icon = [[decoder decodeObjectForKey:CLWebItemIconKey] retain];
+ _createdAt = [[decoder decodeObjectForKey:CLWebItemCreatedAtKey] retain];
+ _updatedAt = [[decoder decodeObjectForKey:CLWebItemUpdatedAtKey] retain];
+ _deletedAt = [[decoder decodeObjectForKey:CLWebItemDeletedAtKey] retain];
}
}
return self;
@@ -112,6 +119,9 @@ - (void)encodeWithCoder:(NSCoder *)encoder {
[encoder encodeBool:self.private forKey:CLWebItemPrivateKey];
[encoder encodeObject:self.icon forKey:CLWebItemIconKey];
[encoder encodeObject:self.iconURL forKey:CLWebItemIconURLKey];
+ [encoder encodeObject:self.createdAt forKey:CLWebItemCreatedAtKey];
+ [encoder encodeObject:self.updatedAt forKey:CLWebItemUpdatedAtKey];
+ [encoder encodeObject:self.deletedAt forKey:CLWebItemDeletedAtKey];
}
}
@@ -127,6 +137,9 @@ - (void)dealloc {
self.iconURL = nil;
self.icon = nil;
self.URL = nil;
+ self.createdAt = nil;
+ self.updatedAt = nil;
+ self.deletedAt = nil;
[super dealloc];
}
Please sign in to comment.
Something went wrong with that request. Please try again.