Last active
December 16, 2015 13:49
-
-
Save brendanjerwin/5444346 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Repository.m | |
// | |
// | |
// Created by Brendan Erwin on 4/22/13. | |
// Copyright (c) 2013. All rights reserved. | |
// | |
#import "DCParserConfiguration.h" | |
#import "DCObjectMapping.h" | |
#import "Rfc3339DateConverter.h" | |
#import "RepositoryOwner.h" | |
#import "Repository.h" | |
@implementation Repository | |
+ (DCKeyValueObjectMapping *)mapper { | |
static DCKeyValueObjectMapping *mapper; | |
if (!mapper) { | |
@synchronized(self) { | |
if (!mapper) { | |
Rfc3339DateConverter *rfc3339Converter = [[Rfc3339DateConverter alloc] init]; | |
DCParserConfiguration *config = [DCParserConfiguration configuration]; | |
[config addObjectMapping:[DCObjectMapping mapKeyPath:@"id" | |
toAttribute:@"repositoryId" | |
onClass:self]]; | |
[config addObjectMapping:[DCObjectMapping mapKeyPath:@"description" | |
toAttribute:@"descriptionText" | |
onClass:self]]; | |
[config addObjectMapping:[DCObjectMapping mapKeyPath:@"pushed_at" | |
toAttribute:@"pushedAt" | |
onClass:self | |
converter:rfc3339Converter]]; | |
[config addObjectMapping:[DCObjectMapping mapKeyPath:@"created_at" | |
toAttribute:@"createdAt" | |
onClass:self | |
converter:rfc3339Converter]]; | |
[config addObjectMapping:[DCObjectMapping mapKeyPath:@"updated_at" | |
toAttribute:@"updatedAt" | |
onClass:self | |
converter:rfc3339Converter]]; | |
mapper = [DCKeyValueObjectMapping mapperForClass:self andConfiguration:config]; | |
} | |
} | |
} | |
return mapper; | |
} | |
+ (Repository *)instanceFromDictionary:(NSDictionary *)aDictionary; { | |
Repository *instance = [self.mapper parseDictionary:aDictionary]; | |
return instance; | |
} | |
@end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Rfc3339DateConverter.m | |
// PullStatus | |
// | |
// Created by Brendan Erwin on 4/23/13. | |
// Copyright (c) 2013 The Network. All rights reserved. | |
// | |
#import "Rfc3339DateConverter.h" | |
@implementation Rfc3339DateConverter | |
+(NSDateFormatter*)dateFormatter{ | |
static NSDateFormatter *formatter; | |
if (!formatter) { | |
@synchronized([self class]){ | |
if (!formatter) { | |
formatter = [[NSDateFormatter alloc] init]; | |
assert(formatter != nil); | |
NSLocale *enUSPOSIXLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]; | |
assert(enUSPOSIXLocale != nil); | |
[formatter setLocale:enUSPOSIXLocale]; | |
[formatter setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"]; | |
[formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; | |
} | |
} | |
} | |
return formatter; | |
} | |
//to date | |
- (id)transformValue:(id)value forDynamicAttribute:(DCDynamicAttribute *)attribute { | |
NSDateFormatter *formatter = [[self class] dateFormatter]; | |
return [formatter dateFromString:value]; | |
} | |
//from date to string | |
- (id)serializeValue:(id)value forDynamicAttribute:(DCDynamicAttribute *)attribute { | |
NSDateFormatter *formatter = [[self class] dateFormatter]; | |
return [formatter stringFromDate:value]; | |
} | |
- (BOOL)canTransformValueForClass:(Class)class { | |
return [class isSubclassOfClass:[NSDate class]]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment