Permalink
Browse files

Simplify JSON formatting

  • Loading branch information...
1 parent 6a95fd4 commit 2d2d217089979afdbae660fa5be80ef7ecba4104 @zachwill committed Dec 4, 2012
@@ -44,7 +44,6 @@
797B170F16197A7800C69C4E /* arrow.png in Resources */ = {isa = PBXBuildFile; fileRef = 797B170D16197A7800C69C4E /* arrow.png */; };
797B171016197A7800C69C4E /* arrow@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 797B170E16197A7800C69C4E /* arrow@2x.png */; };
7980C97C160ED5B4006BCB34 /* GHAPIClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 7980C97B160ED5B4006BCB34 /* GHAPIClient.m */; };
- 7980C97F160ED5E4006BCB34 /* GHJSONFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 7980C97E160ED5E4006BCB34 /* GHJSONFormatter.m */; };
7980C9AF160F04B6006BCB34 /* Bar.m in Sources */ = {isa = PBXBuildFile; fileRef = 7980C9AE160F04B6006BCB34 /* Bar.m */; };
7980C9B2160F04B6006BCB34 /* Drinkup.m in Sources */ = {isa = PBXBuildFile; fileRef = 7980C9B1160F04B6006BCB34 /* Drinkup.m */; };
798C70E91621435000F446FF /* parallax_bg.png in Resources */ = {isa = PBXBuildFile; fileRef = 798C70E71621435000F446FF /* parallax_bg.png */; };
@@ -107,6 +106,7 @@
79422DE8160E814100BA702F /* Drinkups.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = Drinkups.xcdatamodel; sourceTree = "<group>"; };
79520804163DDC6C00A97E1F /* Bar+Annotation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "Bar+Annotation.h"; sourceTree = "<group>"; };
79520805163DDC6C00A97E1F /* Bar+Annotation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "Bar+Annotation.m"; sourceTree = "<group>"; };
+ 7960DCFE166E5F1F00D0A39F /* Drinkups 1d.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = file; path = "Drinkups 1d.xcdatamodel"; sourceTree = "<group>"; };
79616840162A594A00A25EDB /* UIColor+Drinkups.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIColor+Drinkups.h"; sourceTree = "<group>"; };
79616841162A594A00A25EDB /* UIColor+Drinkups.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIColor+Drinkups.m"; sourceTree = "<group>"; };
796C2CC11607D0EA00F238F2 /* GHDataModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHDataModel.h; sourceTree = "<group>"; };
@@ -123,8 +123,6 @@
797B170E16197A7800C69C4E /* arrow@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "arrow@2x.png"; sourceTree = "<group>"; };
7980C97A160ED5B4006BCB34 /* GHAPIClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHAPIClient.h; sourceTree = "<group>"; };
7980C97B160ED5B4006BCB34 /* GHAPIClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHAPIClient.m; sourceTree = "<group>"; };
- 7980C97D160ED5E4006BCB34 /* GHJSONFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GHJSONFormatter.h; sourceTree = "<group>"; };
- 7980C97E160ED5E4006BCB34 /* GHJSONFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GHJSONFormatter.m; sourceTree = "<group>"; };
7980C980160EDAF6006BCB34 /* Drinkups 1.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Drinkups 1.xcdatamodel"; sourceTree = "<group>"; };
7980C9AB160F049A006BCB34 /* Drinkups 1a.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Drinkups 1a.xcdatamodel"; sourceTree = "<group>"; };
7980C9AD160F04B6006BCB34 /* Bar.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Bar.h; sourceTree = "<group>"; };
@@ -344,8 +342,6 @@
792A02CB1607AA3300129016 /* Categories */,
7980C97A160ED5B4006BCB34 /* GHAPIClient.h */,
7980C97B160ED5B4006BCB34 /* GHAPIClient.m */,
- 7980C97D160ED5E4006BCB34 /* GHJSONFormatter.h */,
- 7980C97E160ED5E4006BCB34 /* GHJSONFormatter.m */,
7997E6F9161D465C00A332BD /* GHNotifications.h */,
7997E6FC161D494900A332BD /* GHNotifications.m */,
);
@@ -504,7 +500,6 @@
796C2CD71607D68100F238F2 /* GHIncrementalStore.m in Sources */,
79422DE9160E814100BA702F /* Drinkups.xcdatamodeld in Sources */,
7980C97C160ED5B4006BCB34 /* GHAPIClient.m in Sources */,
- 7980C97F160ED5E4006BCB34 /* GHJSONFormatter.m in Sources */,
7980C9AF160F04B6006BCB34 /* Bar.m in Sources */,
7980C9B2160F04B6006BCB34 /* Drinkup.m in Sources */,
7996E34D16189EEE00701DCE /* GHDrinkupCell.m in Sources */,
@@ -636,6 +631,7 @@
79422DE7160E814100BA702F /* Drinkups.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
+ 7960DCFE166E5F1F00D0A39F /* Drinkups 1d.xcdatamodel */,
798C70E31621294A00F446FF /* Drinkups 1c.xcdatamodel */,
798C70D716210A7500F446FF /* Drinkups 1b.xcdatamodel */,
7980C9AB160F049A006BCB34 /* Drinkups 1a.xcdatamodel */,
@@ -7,19 +7,23 @@
//
#import "GHAPIClient.h"
-#import "GHJSONFormatter.h"
// ***************************************************************************
-@interface GHAPIClient ()
-
-@property (strong, nonatomic) GHJSONFormatter *jsonFormatter;
-
-@end
+static NSString * const kAPIBaseURL = @"http://drinkups.herokuapp.com/api/v1/";
-// ***************************************************************************
+static NSNumber * const GHJSONCoordinateFormatter(NSString *coordinate) {
+ NSNumberFormatter *coordinateFormatter = [[NSNumberFormatter alloc] init];
+ [coordinateFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
+ return [coordinateFormatter numberFromString:coordinate];
+}
-static NSString * const kAPIBaseURL = @"http://drinkups.herokuapp.com/api/v1/";
+static NSDate * const GHJSONDateFormatter(NSString *date) {
+ NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
+ dateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
+ dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZ";
+ return [dateFormatter dateFromString:date];
+}
// ***************************************************************************
@@ -37,8 +41,10 @@ + (GHAPIClient *)sharedClient {
- (id)initWithBaseURL:(NSURL *)url {
self = [super initWithBaseURL:url];
- if (!self)
+ if (!self) {
return nil;
+ }
+
[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
[self setDefaultHeader:@"Accept" value:@"application/json"];
return self;
@@ -74,12 +80,12 @@ - (NSDictionary *)attributesForRepresentation:(NSDictionary *)representation
ofEntity:entity
fromResponse:response] mutableCopy];
if ([entity.name isEqualToString:@"Drinkup"]) {
- NSDate *date = [self.jsonFormatter formatDate:representation[@"date"]];
+ NSDate *date = GHJSONDateFormatter(representation[@"date"]);
mutableProperties[@"date"] = date;
mutableProperties[@"drinkup_id"] = representation[@"id"];
} else if ([entity.name isEqualToString:@"Bar"]) {
- NSNumber *latitude = [self.jsonFormatter formatCoordinate:representation[@"latitude"]];
- NSNumber *longitude = [self.jsonFormatter formatCoordinate:representation[@"longitude"]];
+ NSNumber *latitude = GHJSONCoordinateFormatter(representation[@"latitude"]);
+ NSNumber *longitude = GHJSONCoordinateFormatter(representation[@"longitude"]);
mutableProperties[@"latitude"] = latitude;
mutableProperties[@"longitude"] = longitude;
mutableProperties[@"bar_id"] = representation[@"id"];
@@ -108,13 +114,4 @@ - (BOOL)shouldFetchRemoteValuesForRelationship:(NSRelationshipDescription *)rela
return NO;
}
-#pragma mark - Private
-
-- (GHJSONFormatter *)jsonFormatter {
- if (_jsonFormatter == nil) {
- _jsonFormatter = [[GHJSONFormatter alloc] init];
- }
- return _jsonFormatter;
-}
-
@end
@@ -1,16 +0,0 @@
-//
-// GHJSONFormatter.h
-// Github
-//
-// Created by Zach Williams on 9/22/12.
-// Copyright (c) 2012 Zach Williams. All rights reserved.
-//
-
-#import <Foundation/Foundation.h>
-
-@interface GHJSONFormatter : NSObject
-
-- (NSNumber *)formatCoordinate:(NSString *)coordinate;
-- (NSDate *)formatDate:(NSString *)date;
-
-@end
@@ -1,33 +0,0 @@
-//
-// GHJSONFormatter.m
-// Github
-//
-// Created by Zach Williams on 9/22/12.
-// Copyright (c) 2012 Zach Williams. All rights reserved.
-//
-
-#import "GHJSONFormatter.h"
-
-@implementation GHJSONFormatter
-
-- (NSNumber *)formatCoordinate:(NSString *)coordinate {
- static NSNumberFormatter *coordinateFormatter = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- coordinateFormatter = [[NSNumberFormatter alloc] init];
- [coordinateFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
- });
- return [coordinateFormatter numberFromString:coordinate];
-}
-
-- (NSDate *)formatDate:(NSString *)date {
- static NSDateFormatter *dateFormatter = nil;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- dateFormatter = [[NSDateFormatter alloc] init];
- dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ssZZZZ";
- });
- return [dateFormatter dateFromString:date];
-}
-
-@end
View
@@ -30,11 +30,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
- <string>1.1</string>
+ <string>1.2</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
- <string>1.1</string>
+ <string>1.2</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIPrerenderedIcon</key>
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1810" systemVersion="12C54" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
+ <entity name="Bar" representedClassName="Bar" syncable="YES">
+ <attribute name="address" optional="YES" attributeType="String" syncable="YES"/>
+ <attribute name="bar_id" optional="YES" attributeType="String" syncable="YES"/>
+ <attribute name="city" optional="YES" attributeType="String" syncable="YES"/>
+ <attribute name="foursquare" optional="YES" attributeType="String" syncable="YES"/>
+ <attribute name="latitude" optional="YES" attributeType="Double" defaultValueString="0.0" syncable="YES"/>
+ <attribute name="longitude" optional="YES" attributeType="Double" defaultValueString="0.0" syncable="YES"/>
+ <attribute name="name" optional="YES" attributeType="String" syncable="YES"/>
+ <attribute name="phone" optional="YES" attributeType="String" syncable="YES"/>
+ <attribute name="photo" optional="YES" attributeType="String" syncable="YES"/>
+ <attribute name="twitter" optional="YES" attributeType="String" syncable="YES"/>
+ <relationship name="drinkups" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="Drinkup" inverseName="bar" inverseEntity="Drinkup" syncable="YES"/>
+ </entity>
+ <entity name="Drinkup" representedClassName="Drinkup" syncable="YES">
+ <attribute name="blog" optional="YES" attributeType="String" syncable="YES"/>
+ <attribute name="date" optional="YES" attributeType="Date" syncable="YES"/>
+ <attribute name="drinkup_id" attributeType="String" indexed="YES" syncable="YES"/>
+ <relationship name="bar" optional="YES" minCount="1" maxCount="1" deletionRule="Nullify" destinationEntity="Bar" inverseName="drinkups" inverseEntity="Bar" syncable="YES"/>
+ </entity>
+ <elements>
+ <element name="Bar" positionX="-74" positionY="192" width="128" height="210"/>
+ <element name="Drinkup" positionX="160" positionY="192" width="128" height="105"/>
+ </elements>
+</model>
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1810" systemVersion="12C54" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
+<model name="" userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="1811" systemVersion="12C60" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic">
<entity name="Bar" representedClassName="Bar" syncable="YES">
<attribute name="address" optional="YES" attributeType="String" syncable="YES"/>
<attribute name="bar_id" optional="YES" attributeType="String" syncable="YES"/>

0 comments on commit 2d2d217

Please sign in to comment.