From 2108f0c94d689dc46db67b0947daf81d22210a52 Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sat, 19 Mar 2016 20:54:27 +0000 Subject: [PATCH 01/15] Format code and optimised imports. --- .../OCGoogleDirectionsAPITests.xcscheme | 13 + .../Client/OCDirectionsAPIClient.h | 2 +- .../Client/OCDirectionsAPIClient.m | 56 +- .../OCDirectionsRequestURLCreatorJSON.h | 2 +- .../OCDirectionsRequestURLCreatorJSON.m | 162 ++-- .../Common/OCDirectionsCommonTypes.m | 77 +- .../Common/OCDirectionsRequestRestriction.h | 10 +- .../Common/OCDirectionsRequestTravelMode.h | 14 +- .../Common/OCDirectionsRequestUnit.h | 10 +- .../Common/OCDirectionsResponseVehicleType.h | 68 +- .../OCGoogleDirectionsAPI-Info.plist | 52 +- .../OCGoogleDirectionsAPI-Prefix.pch | 4 +- .../Request/OCDirectionsRequest.h | 28 +- .../Request/OCDirectionsRequest.m | 244 +++--- .../Response/Attributes/OCDirectionsBounds.h | 6 +- .../Response/Attributes/OCDirectionsBounds.m | 21 +- .../Attributes/OCDirectionsDistance.h | 6 +- .../Attributes/OCDirectionsDistance.m | 23 +- .../Attributes/OCDirectionsDuration.h | 6 +- .../Attributes/OCDirectionsDuration.m | 23 +- .../Response/Attributes/OCDirectionsLeg.h | 18 +- .../Response/Attributes/OCDirectionsLeg.m | 55 +- .../Attributes/OCDirectionsPolyline.h | 4 +- .../Attributes/OCDirectionsPolyline.m | 18 +- .../Response/Attributes/OCDirectionsRoute.h | 16 +- .../Response/Attributes/OCDirectionsRoute.m | 48 +- .../Response/Attributes/OCDirectionsStep.h | 18 +- .../Response/Attributes/OCDirectionsStep.m | 53 +- .../Attributes/OCDirectionsWaypoint.h | 8 +- .../Attributes/OCDirectionsWaypoint.m | 28 +- .../Response/OCDirectionsResponse.h | 8 +- .../Response/OCDirectionsResponse.m | 56 +- .../CLLocation+CoortindateFromDictionary.m | 6 +- .../OCDirectionsRequestURLCreatorJSONTests.m | 398 +++++----- .../OCGoogleDirectionsAPITests-Info.plist | 36 +- .../Request/OCDirectionsRequestTests.m | 711 +++++++++--------- 36 files changed, 1096 insertions(+), 1212 deletions(-) diff --git a/Source/OCGoogleDirectionsAPI.xcodeproj/xcshareddata/xcschemes/OCGoogleDirectionsAPITests.xcscheme b/Source/OCGoogleDirectionsAPI.xcodeproj/xcshareddata/xcschemes/OCGoogleDirectionsAPITests.xcscheme index 88dc3a1..129f903 100644 --- a/Source/OCGoogleDirectionsAPI.xcodeproj/xcshareddata/xcschemes/OCGoogleDirectionsAPITests.xcscheme +++ b/Source/OCGoogleDirectionsAPI.xcodeproj/xcshareddata/xcschemes/OCGoogleDirectionsAPITests.xcscheme @@ -5,6 +5,19 @@ + + + + + + requestURLCreator; +@property(nonatomic, retain) id requestURLCreator; - (instancetype)init; diff --git a/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m b/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m index 5ddc486..18f2189 100644 --- a/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m +++ b/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m @@ -10,8 +10,8 @@ @interface OCDirectionsAPIClient () -@property (nonatomic, copy) NSString *key; -@property (nonatomic) BOOL useHttps; +@property(nonatomic, copy) NSString *key; +@property(nonatomic) BOOL useHttps; @end @@ -19,76 +19,68 @@ @implementation OCDirectionsAPIClient static NSString *_defaultKey; -- (instancetype)init -{ - return [self initWithKey:_defaultKey]; +- (instancetype)init { + return [self initWithKey:_defaultKey]; } -- (instancetype)initWithNoKey -{ - return [self initWithKey:nil]; +- (instancetype)initWithNoKey { + return [self initWithKey:nil]; } -- (instancetype)initWithNoKeyUseHttps:(BOOL)useHttps -{ - return [self initWithKey:nil useHttps:useHttps]; +- (instancetype)initWithNoKeyUseHttps:(BOOL)useHttps { + return [self initWithKey:nil useHttps:useHttps]; } -- (instancetype)initWithKey:(NSString *)key -{ +- (instancetype)initWithKey:(NSString *)key { return [self initWithKey:key useHttps:YES]; } -- (instancetype)initWithKey:(NSString *)key useHttps:(BOOL)useHttps -{ +- (instancetype)initWithKey:(NSString *)key useHttps:(BOOL)useHttps { self = [super init]; if (self) { self.key = key; self.useHttps = useHttps; - self.requestURLCreator = [OCDirectionsRequestURLCreatorJSON new]; + self.requestURLCreator = [OCDirectionsRequestURLCreatorJSON new]; } return self; } -+ (void)provideAPIKey:(NSString *)key -{ ++ (void)provideAPIKey:(NSString *)key { _defaultKey = key; } -- (void)directions:(OCDirectionsRequest *)request response:(OCDirectionsRequestCallback)callback -{ +- (void)directions:(OCDirectionsRequest *)request response:(OCDirectionsRequestCallback)callback { NSURL *url = [self urlFromRequest:request]; - + NSURLSession *session = [NSURLSession sharedSession]; [[session dataTaskWithURL:url completionHandler:^(NSData *data, - NSURLResponse *response, - NSError *error) { - + NSURLResponse *response, + NSError *error) { + if (error) { callback(nil, error); return; } - + NSError *jsonParsingError = nil; NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonParsingError]; - + if (jsonParsingError) { callback(nil, jsonParsingError); return; } - + OCDirectionsResponse *directionsResponse = [OCDirectionsResponse responseFromDictionary:dictionary]; callback(directionsResponse, nil); return; - + }] resume]; } -- (NSURL *)urlFromRequest:(OCDirectionsRequest *)request -{ - NSURL *url = [self.requestURLCreator urlFromRequest:request useHttps:self.useHttps andKey:self.key]; - return url; +- (NSURL *)urlFromRequest:(OCDirectionsRequest *)request { + NSURL *url = [self.requestURLCreator urlFromRequest:request useHttps:self.useHttps andKey:self.key]; + return url; } @end diff --git a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.h b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.h index 7b57262..cb8e96c 100644 --- a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.h +++ b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.h @@ -9,6 +9,6 @@ #import #import "OCDirectionsRequestURLCreator.h" -@interface OCDirectionsRequestURLCreatorJSON : NSObject +@interface OCDirectionsRequestURLCreatorJSON : NSObject @end diff --git a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m index f43ac49..45376dc 100644 --- a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m +++ b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m @@ -31,12 +31,12 @@ @implementation OCDirectionsRequestURLCreatorJSON #pragma mark - Public methods -- (NSString *)stringFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)useHttps andKey:(NSString *)key -{ - OCAssertParameterNotNil(request, @"Request is nil."); - + +- (NSString *)stringFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)useHttps andKey:(NSString *)key { + OCAssertParameterNotNil(request, @"Request is nil."); + NSMutableString *string = [self baseStringWithHttps:useHttps]; - + [self appendOrigin:request toString:string]; [self appendDestination:request toString:string]; [self appendSensor:request toString:string]; @@ -44,27 +44,26 @@ - (NSString *)stringFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)us [self appendWaypoints:request toString:string]; [self appendRestrictions:request toString:string]; [self appendRegion:request toString:string]; - [self appendLanguage:request toString:string]; + [self appendLanguage:request toString:string]; [self appendAlternatives:request toString:string]; [self appendKey:key toString:string]; - + NSString *stringEncoded = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; return stringEncoded; } -- (NSURL *)urlFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)useHttps andKey:(NSString *)key -{ - OCAssertParameterNotNil(request, @"Request is nil."); +- (NSURL *)urlFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)useHttps andKey:(NSString *)key { + OCAssertParameterNotNil(request, @"Request is nil."); OCAssertParameterNotNil(key, @"Key is nil."); - + NSString *requestString = [self stringFromRequest:request useHttps:useHttps andKey:key]; NSURL *url = [[NSURL alloc] initWithString:requestString]; return url; } #pragma mark - Private methods -- (NSMutableString *)baseStringWithHttps:(BOOL)useHttps -{ + +- (NSMutableString *)baseStringWithHttps:(BOOL)useHttps { NSMutableString *baseString = [NSMutableString new]; if (useHttps) { [baseString appendString:kOCGoogleDirectionsAPIHTTPS]; @@ -72,15 +71,15 @@ - (NSMutableString *)baseStringWithHttps:(BOOL)useHttps [baseString appendString:kOCGoogleDirectionsAPIHTTP]; } [baseString appendString:kOCGoogleDirectionsAPIJSON]; - + return baseString; } #pragma mark - Appenders -- (void)appendOrigin:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ + +- (void)appendOrigin:(OCDirectionsRequest *)request toString:(NSMutableString *)string { [string appendString:kOCGoogleDirectionsRequestAttributeOrigin]; - + if (request.originLocation) { NSString *originString = [self stringFormCLLocation:request.originLocation]; [string appendString:originString]; @@ -89,10 +88,9 @@ - (void)appendOrigin:(OCDirectionsRequest *)request toString:(NSMutableString *) } } -- (void)appendDestination:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ +- (void)appendDestination:(OCDirectionsRequest *)request toString:(NSMutableString *)string { [string appendString:kOCGoogleDirectionsRequestAttributeDestination]; - + if (request.destinationLocation) { NSString *destinationString = [self stringFormCLLocation:request.destinationLocation]; [string appendString:destinationString]; @@ -101,166 +99,158 @@ - (void)appendDestination:(OCDirectionsRequest *)request toString:(NSMutableStri } } -- (void)appendSensor:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ - /* - Checks if sensor flag is set. If no, just skip it as it is no longer required. - */ - if (!request.sensorFlagUsed) { - return; - } - +- (void)appendSensor:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + /* + Checks if sensor flag is set. If no, just skip it as it is no longer required. + */ + if (!request.sensorFlagUsed) { + return; + } + [string appendString:kOCGoogleDirectionsRequestAttributeSensor]; - + NSString *sensorString = [self stringFromBOOL:request.sensor]; [string appendString:sensorString]; } -- (void)appendTravelMode:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ +- (void)appendTravelMode:(OCDirectionsRequest *)request toString:(NSMutableString *)string { if (request.travelMode == OCDirectionsRequestTravelModeDriving) { return; } - + [string appendString:kOCGoogleDirectionsRequestAttributeTravelMode]; - + NSString *travelModeString = [OCDirectionsCommonTypes stringFormTravelMode:request.travelMode]; [string appendString:travelModeString]; } -- (void)appendWaypoints:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ +- (void)appendWaypoints:(OCDirectionsRequest *)request toString:(NSMutableString *)string { if (request.waypoints == nil) { return; } - + if ([request.waypoints count] == 0) { return; } - + [string appendString:kOCGoogleDirectionsRequestAttributeWaypoints]; - + if (request.waypointsOptimise) { [string appendString:kOCGoogleDirectionsRequestAttributeWaypointsOptimize]; [string appendString:kOCGoogleDirectionsRequestAttributeSeparator]; } - + NSUInteger count = [request.waypoints count]; NSUInteger iter = 0; for (id waypoint in request.waypoints) { if ([waypoint isKindOfClass:[NSString class]]) { - NSString *waypointString = (NSString *)waypoint; + NSString *waypointString = (NSString *) waypoint; [string appendString:waypointString]; } else if ([waypoint isKindOfClass:[CLLocation class]]) { - CLLocation *waypointLocation = (CLLocation *)waypoint; + CLLocation *waypointLocation = (CLLocation *) waypoint; NSString *waypointString = [self stringFormCLLocation:waypointLocation]; [string appendString:waypointString]; } - + if (++iter < count) { [string appendString:kOCGoogleDirectionsRequestAttributeSeparator]; } } } -- (void)appendRestrictions:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ +- (void)appendRestrictions:(OCDirectionsRequest *)request toString:(NSMutableString *)string { if (request.restrictions == nil) { return; } - + if ([request.restrictions count] == 0) { return; } - + [string appendString:kOCGoogleDirectionsRequestAttributeRestrictions]; - + NSUInteger count = [request.waypoints count]; NSUInteger iter = 0; for (NSString *restriction in request.restrictions) { [string appendString:restriction]; - + if (++iter < count) { [string appendString:kOCGoogleDirectionsRequestAttributeSeparator]; } } } -- (void)appendUnit:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ +- (void)appendUnit:(OCDirectionsRequest *)request toString:(NSMutableString *)string { if (request.unit == OCDirectionsRequestUnitDefault) { return; } - + [string appendString:kOCGoogleDirectionsRequestAttributeUnits]; - + NSString *unitString = [self stringFormUnit:request.unit]; [string appendString:unitString]; } -- (void)appendRegion:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ +- (void)appendRegion:(OCDirectionsRequest *)request toString:(NSMutableString *)string { if (request.region == nil) { return; } - + [string appendString:kOCGoogleDirectionsRequestAttributeRegion]; [string appendString:request.region]; } -- (void)appendLanguage:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ - if (request.language == nil) { - return; - } - - [string appendString:kOCGoogleDirectionsRequestAttributeLanguage]; - [string appendString:request.language]; +- (void)appendLanguage:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + if (request.language == nil) { + return; + } + + [string appendString:kOCGoogleDirectionsRequestAttributeLanguage]; + [string appendString:request.language]; } -- (void)appendAlternatives:(OCDirectionsRequest *)request toString:(NSMutableString *)string -{ +- (void)appendAlternatives:(OCDirectionsRequest *)request toString:(NSMutableString *)string { if (request.alternatives == NO) { return; } - + [string appendString:kOCGoogleDirectionsRequestAttributeAlternatives]; - + NSString *alternativesString = [self stringFromBOOL:request.alternatives]; [string appendString:alternativesString]; } -- (void)appendKey:(NSString *)key toString:(NSMutableString *)string -{ - /** - API key is not requred. - */ - if (key) { - [string appendString:kOCGoogleDirectionsRequestAttributeKey]; - [string appendString:key]; - } +- (void)appendKey:(NSString *)key toString:(NSMutableString *)string { + /** + API key is not requred. + */ + if (key) { + [string appendString:kOCGoogleDirectionsRequestAttributeKey]; + [string appendString:key]; + } } #pragma mark - Helpers -- (NSString *)stringFormCLLocation:(CLLocation *)location -{ + +- (NSString *)stringFormCLLocation:(CLLocation *)location { NSString *string = [NSString stringWithFormat:@"%f,%f", location.coordinate.latitude, location.coordinate.longitude]; return string; } -- (NSString *)stringFromBOOL:(BOOL)boolValue -{ +- (NSString *)stringFromBOOL:(BOOL)boolValue { NSString *string = boolValue ? @"true" : @"false"; return string; } -- (NSString *)stringFormUnit:(OCDirectionsRequestUnit)unit -{ +- (NSString *)stringFormUnit:(OCDirectionsRequestUnit)unit { switch (unit) { - case OCDirectionsRequestUnitDefault: return @""; // should never happen - case OCDirectionsRequestUnitImperial: return @"imperial"; - case OCDirectionsRequestUnitMetric: return @"metric"; + case OCDirectionsRequestUnitDefault: + return @""; // should never happen + case OCDirectionsRequestUnitImperial: + return @"imperial"; + case OCDirectionsRequestUnitMetric: + return @"metric"; } } diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m index 4cfb332..1a10c6a 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m @@ -15,32 +15,29 @@ @implementation OCDirectionsCommonTypes @implementation OCDirectionsCommonTypes (TravelMode) -+ (NSString *)stringFormTravelMode:(OCDirectionsRequestTravelMode)travelMode -{ ++ (NSString *)stringFormTravelMode:(OCDirectionsRequestTravelMode)travelMode { NSArray *keys = [[[self class] travelModeDictionary] allKeysForObject:@(travelMode)]; return [keys firstObject]; } -+ (OCDirectionsRequestTravelMode)travelModeFromString:(NSString *)travelModeString -{ ++ (OCDirectionsRequestTravelMode)travelModeFromString:(NSString *)travelModeString { NSNumber *number = [[[self class] travelModeDictionary] objectForKey:travelModeString]; - OCDirectionsRequestTravelMode travelMode = (OCDirectionsRequestTravelMode)number.unsignedIntegerValue; - + OCDirectionsRequestTravelMode travelMode = (OCDirectionsRequestTravelMode) number.unsignedIntegerValue; + return travelMode; } -+ (NSDictionary *)travelModeDictionary -{ ++ (NSDictionary *)travelModeDictionary { static NSDictionary *dictionary; - + if (dictionary == nil) { - dictionary = @{@"driving" : @(OCDirectionsRequestTravelModeDriving), - @"walking" : @(OCDirectionsRequestTravelModeWalking), - @"bicycling" : @(OCDirectionsRequestTravelModeBicycling), - @"transit" : @(OCDirectionsRequestTravelModeTransit) - }; + dictionary = @{@"driving" : @(OCDirectionsRequestTravelModeDriving), + @"walking" : @(OCDirectionsRequestTravelModeWalking), + @"bicycling" : @(OCDirectionsRequestTravelModeBicycling), + @"transit" : @(OCDirectionsRequestTravelModeTransit) + }; } - + return dictionary; } @@ -48,39 +45,37 @@ + (NSDictionary *)travelModeDictionary @implementation OCDirectionsCommonTypes (VehicalType) -+ (OCDirectionsResponseVehicleType)vehicleTypeFromString:(NSString *)vehicleTypeString -{ ++ (OCDirectionsResponseVehicleType)vehicleTypeFromString:(NSString *)vehicleTypeString { NSNumber *number = [[[self class] vehicleTypesDictionary] objectForKey:vehicleTypeString]; - OCDirectionsResponseVehicleType vehicleType = (OCDirectionsResponseVehicleType)number.unsignedIntegerValue; - + OCDirectionsResponseVehicleType vehicleType = (OCDirectionsResponseVehicleType) number.unsignedIntegerValue; + return vehicleType; } -+ (NSDictionary *)vehicleTypesDictionary -{ ++ (NSDictionary *)vehicleTypesDictionary { static NSDictionary *dictionary; - + if (dictionary == nil) { - dictionary = @{@"RAIL" : @(OCDirectionsResponseVehicleTypeRail), - @"METRO_RAIL" : @(OCDirectionsResponseVehicleTypeMetroRail), - @"SUBWAY" : @(OCDirectionsResponseVehicleTypeSubway), - @"TRAM" : @(OCDirectionsResponseVehicleTypeTram), - @"MONORAIL" : @(OCDirectionsResponseVehicleTypeMonorail), - @"HEAVY_RAIL" : @(OCDirectionsResponseVehicleTypeHeavyRail), - @"COMMUTER_TRAIN" : @(OCDirectionsResponseVehicleTypeCommuterTrain), - @"HIGH_SPEED_TRAIN" : @(OCDirectionsResponseVehicleTypeHighSpeedTrain), - @"BUS" : @(OCDirectionsResponseVehicleTypeBus), - @"INTERCITY_BUS" : @(OCDirectionsResponseVehicleTypeIntercityBus), - @"TROLLEYBUS" : @(OCDirectionsResponseVehicleTypeTrolleybus), - @"SHARE_TAXI" : @(OCDirectionsResponseVehicleTypeShareTaxi), - @"FERRY" : @(OCDirectionsResponseVehicleTypeFerry), - @"CABLE_CAR" : @(OCDirectionsResponseVehicleTypeCableCar), - @"GONDOLA_LIFT" : @(OCDirectionsResponseVehicleTypeGondolaLift), - @"FUNICULAR" : @(OCDirectionsResponseVehicleTypeFunicular), - @"OTHER" : @(OCDirectionsResponseVehicleTypeOther) - }; + dictionary = @{@"RAIL" : @(OCDirectionsResponseVehicleTypeRail), + @"METRO_RAIL" : @(OCDirectionsResponseVehicleTypeMetroRail), + @"SUBWAY" : @(OCDirectionsResponseVehicleTypeSubway), + @"TRAM" : @(OCDirectionsResponseVehicleTypeTram), + @"MONORAIL" : @(OCDirectionsResponseVehicleTypeMonorail), + @"HEAVY_RAIL" : @(OCDirectionsResponseVehicleTypeHeavyRail), + @"COMMUTER_TRAIN" : @(OCDirectionsResponseVehicleTypeCommuterTrain), + @"HIGH_SPEED_TRAIN" : @(OCDirectionsResponseVehicleTypeHighSpeedTrain), + @"BUS" : @(OCDirectionsResponseVehicleTypeBus), + @"INTERCITY_BUS" : @(OCDirectionsResponseVehicleTypeIntercityBus), + @"TROLLEYBUS" : @(OCDirectionsResponseVehicleTypeTrolleybus), + @"SHARE_TAXI" : @(OCDirectionsResponseVehicleTypeShareTaxi), + @"FERRY" : @(OCDirectionsResponseVehicleTypeFerry), + @"CABLE_CAR" : @(OCDirectionsResponseVehicleTypeCableCar), + @"GONDOLA_LIFT" : @(OCDirectionsResponseVehicleTypeGondolaLift), + @"FUNICULAR" : @(OCDirectionsResponseVehicleTypeFunicular), + @"OTHER" : @(OCDirectionsResponseVehicleTypeOther) + }; } - + return dictionary; } diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestRestriction.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestRestriction.h index c8aa2aa..5df695c 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestRestriction.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestRestriction.h @@ -10,15 +10,15 @@ typedef NS_ENUM(NSUInteger, OCDirectionsRequestRestriction) { /** avoid tools */ - OCDirectionsRequestRestrictionAvoidTolls, - + OCDirectionsRequestRestrictionAvoidTolls, + /** avoid highways */ - OCDirectionsRequestRestrictionAvoidHighways, - + OCDirectionsRequestRestrictionAvoidHighways, + /** avoid ferries */ - OCDirectionsRequestRestrictionAviodFerries + OCDirectionsRequestRestrictionAviodFerries }; diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTravelMode.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTravelMode.h index a73fa48..0cb491c 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTravelMode.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTravelMode.h @@ -10,20 +10,20 @@ typedef NS_ENUM(NSUInteger, OCDirectionsRequestTravelMode) { /** (default) indicates standard driving directions using the road */ - OCDirectionsRequestTravelModeDriving, - + OCDirectionsRequestTravelModeDriving, + /** requests walking directions via pedestrian paths & sidewalks (where available). */ - OCDirectionsRequestTravelModeWalking, - + OCDirectionsRequestTravelModeWalking, + /** requests bicycling directions via bicycle paths & preferred streets (where available). */ - OCDirectionsRequestTravelModeBicycling, - + OCDirectionsRequestTravelModeBicycling, + /** requests directions via public transit routes (where available). */ - OCDirectionsRequestTravelModeTransit + OCDirectionsRequestTravelModeTransit }; \ No newline at end of file diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestUnit.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestUnit.h index 34eefcd..3904e26 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestUnit.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestUnit.h @@ -10,15 +10,15 @@ typedef NS_ENUM(NSUInteger, OCDirectionsRequestUnit) { /** when not specified */ - OCDirectionsRequestUnitDefault, - + OCDirectionsRequestUnitDefault, + /** specifies usage of the metric system. Textual distances are returned using kilometers and meters. */ - OCDirectionsRequestUnitMetric, - + OCDirectionsRequestUnitMetric, + /** specifies usage of the Imperial (English) system. Textual distances are returned using miles and feet. */ - OCDirectionsRequestUnitImperial + OCDirectionsRequestUnitImperial }; \ No newline at end of file diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsResponseVehicleType.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsResponseVehicleType.h index 16f74df..7e7e00e 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsResponseVehicleType.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsResponseVehicleType.h @@ -11,89 +11,89 @@ typedef NS_ENUM(NSUInteger, OCDirectionsResponseVehicleType) { // Not available. // */ // OCDirectionsResponseVehicleTypeNotAvailable, - + /** Rail. */ - OCDirectionsResponseVehicleTypeRail, - + OCDirectionsResponseVehicleTypeRail, + /** Light rail transit. */ - OCDirectionsResponseVehicleTypeMetroRail, - + OCDirectionsResponseVehicleTypeMetroRail, + /** Underground light rail. */ - OCDirectionsResponseVehicleTypeSubway, - + OCDirectionsResponseVehicleTypeSubway, + /** Above ground light rail. */ - OCDirectionsResponseVehicleTypeTram, - + OCDirectionsResponseVehicleTypeTram, + /** Monorail. */ - OCDirectionsResponseVehicleTypeMonorail, - + OCDirectionsResponseVehicleTypeMonorail, + /** Heavy rail. */ - OCDirectionsResponseVehicleTypeHeavyRail, - + OCDirectionsResponseVehicleTypeHeavyRail, + /** Commuter rail. */ - OCDirectionsResponseVehicleTypeCommuterTrain, - + OCDirectionsResponseVehicleTypeCommuterTrain, + /** High speed train. */ - OCDirectionsResponseVehicleTypeHighSpeedTrain, - + OCDirectionsResponseVehicleTypeHighSpeedTrain, + /** Bus. */ - OCDirectionsResponseVehicleTypeBus, - + OCDirectionsResponseVehicleTypeBus, + /** Intercity bus. */ - OCDirectionsResponseVehicleTypeIntercityBus, - + OCDirectionsResponseVehicleTypeIntercityBus, + /** Trolleybus. */ - OCDirectionsResponseVehicleTypeTrolleybus, - + OCDirectionsResponseVehicleTypeTrolleybus, + /** Share taxi is a kind of bus with the ability to drop off and pick up passengers anywhere on its route. */ - OCDirectionsResponseVehicleTypeShareTaxi, - + OCDirectionsResponseVehicleTypeShareTaxi, + /** Ferry. */ - OCDirectionsResponseVehicleTypeFerry, - + OCDirectionsResponseVehicleTypeFerry, + /** A vehicle that operates on a cable, usually on the ground. Aerial cable cars may be of the type OCDirectionsResponseVehicleTypeGondolaLift. */ - OCDirectionsResponseVehicleTypeCableCar, - + OCDirectionsResponseVehicleTypeCableCar, + /** An aerial cable car. */ - OCDirectionsResponseVehicleTypeGondolaLift, - + OCDirectionsResponseVehicleTypeGondolaLift, + /** A vehicle that is pulled up a steep incline by a cable. A Funicular typically consists of two cars, with each car acting as a counterweight for the other. */ - OCDirectionsResponseVehicleTypeFunicular, - + OCDirectionsResponseVehicleTypeFunicular, + /** All other vehicles will return this type. */ - OCDirectionsResponseVehicleTypeOther, + OCDirectionsResponseVehicleTypeOther, }; diff --git a/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Info.plist b/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Info.plist index 066c269..1dca440 100644 --- a/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Info.plist +++ b/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Info.plist @@ -1,30 +1,30 @@ - - CFBundleDevelopmentRegion - English - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIconFile - - CFBundleIdentifier - com.github.${PRODUCT_NAME:rfc1034identifier} - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - NSHumanReadableCopyright - Copyright © 2014 Marcin Iwanicki. All rights reserved. - NSPrincipalClass - - + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFile + + CFBundleIdentifier + com.github.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + NSHumanReadableCopyright + Copyright © 2014 Marcin Iwanicki. All rights reserved. + NSPrincipalClass + + diff --git a/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Prefix.pch b/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Prefix.pch index eb2007e..7b649da 100644 --- a/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Prefix.pch +++ b/Source/OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Prefix.pch @@ -5,5 +5,7 @@ // #ifdef __OBJC__ - #import + +#import + #endif diff --git a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h index a8fd17f..ad8540d 100644 --- a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h +++ b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h @@ -16,67 +16,67 @@ /** Origin - The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a string, the Directions service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values. */ -@property (nonatomic, readonly) CLLocation *originLocation; // CLLocation or NSString -@property (nonatomic, copy, readonly) NSString *originString; +@property(nonatomic, readonly) CLLocation *originLocation; // CLLocation or NSString +@property(nonatomic, copy, readonly) NSString *originString; /** Destination - The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a string, the Directions service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values. */ -@property (nonatomic, readonly) CLLocation *destinationLocation; // CLLocation or NSString -@property (nonatomic, copy, readonly) NSString *destinationString; +@property(nonatomic, readonly) CLLocation *destinationLocation; // CLLocation or NSString +@property(nonatomic, copy, readonly) NSString *destinationString; /* Indicates whether or not the directions request comes from a device with a location sensor. This value must be either true or false. */ -@property (nonatomic, readonly) BOOL sensor; +@property(nonatomic, readonly) BOOL sensor; #pragma mark - Optional -@property (nonatomic) OCDirectionsRequestTravelMode travelMode; +@property(nonatomic) OCDirectionsRequestTravelMode travelMode; /** When calculating routes using the Directions API, you may also specify waypoints for driving, walking or bicycling directions. Waypoints are not available for transit directions. Waypoints allow you to calculate routes through additional locations, in which case the returned route passes through the given waypoints. Formally it is an array of NSStrings and CLLocations. */ -@property (nonatomic) NSArray *waypoints; +@property(nonatomic) NSArray *waypoints; /** Optimizes the provided route by rearranging the waypoints in a more efficient order. (This optimization is an application of the Travelling Salesman Problem.) */ -@property (nonatomic) BOOL waypointsOptimise; +@property(nonatomic) BOOL waypointsOptimise; /** Directions may be calculated that adhere to certain restrictions. Use an array of DirectionsRequestRestriction types ie. @[DirectionsRequestAvoidTollsRestriction, DirectionsRequestAviodFerriesRestriction] */ -@property (nonatomic) NSArray *restrictions; +@property(nonatomic) NSArray *restrictions; /** Directions results contain text within distance fields that may be displayed to the user to indicate the distance of a particular "step" of the route. By default, this text uses the unit system of the origin's country or region. */ -@property (nonatomic) OCDirectionsRequestUnit unit; +@property(nonatomic) OCDirectionsRequestUnit unit; /** You can also set the Directions service to return results biased to a particular region by use of the region parameter. This parameter takes a ccTLD (country code top-level domain) argument specifying the region bias. Most ccTLD codes are identical to ISO 3166-1 codes, with some notable exceptions. For example, the United Kingdom's ccTLD is "uk" (.co.uk) while its ISO 3166-1 code is "gb" (technically for the entity of "The United Kingdom of Great Britain and Northern Ireland"). You may utilize any domain in which the main Google Maps application has launched driving directions. */ -@property (nonatomic, copy) NSString *region; +@property(nonatomic, copy) NSString *region; /** You can also set the Directions service to return results is specific language. If language is not supplied, the service will attempt to use the native language of the domain from which the request is sent. */ -@property (nonatomic, copy) NSString *language; +@property(nonatomic, copy) NSString *language; /** Directions service may return several routes if you pass alternatives. */ -@property (nonatomic) BOOL alternatives; +@property(nonatomic) BOOL alternatives; /** Indicates whether sensor flag has been used or not. */ -@property (nonatomic, getter=isSensorFlagUsed, readonly) BOOL sensorFlagUsed; +@property(nonatomic, getter=isSensorFlagUsed, readonly) BOOL sensorFlagUsed; @end diff --git a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m index bbf7e82..a974e87 100644 --- a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m +++ b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m @@ -11,22 +11,22 @@ @interface OCDirectionsRequest () -@property (nonatomic) CLLocation *originLocation; -@property (nonatomic, copy) NSString *originString; +@property(nonatomic) CLLocation *originLocation; +@property(nonatomic, copy) NSString *originString; -@property (nonatomic) CLLocation *destinationLocation; -@property (nonatomic, copy) NSString *destinationString; +@property(nonatomic) CLLocation *destinationLocation; +@property(nonatomic, copy) NSString *destinationString; -@property (nonatomic) BOOL sensor; -@property (nonatomic, getter=isSensorFlagUsed) BOOL sensorFlagUsed; +@property(nonatomic) BOOL sensor; +@property(nonatomic, getter=isSensorFlagUsed) BOOL sensorFlagUsed; @end @implementation OCDirectionsRequest #pragma mark - Public init -- (instancetype)init -{ + +- (instancetype)init { self = [super init]; if (self) { // Do nothing @@ -35,96 +35,89 @@ - (instancetype)init } #pragma mark - Private init + - (instancetype)initWithOriginLocation:(CLLocation *)origin - andDestinationLocation:(CLLocation *)destination -{ - self = [super init]; - if (self) { - self.originLocation = origin; - self.destinationLocation = destination; - } - - return self; + andDestinationLocation:(CLLocation *)destination { + self = [super init]; + if (self) { + self.originLocation = origin; + self.destinationLocation = destination; + } + + return self; } - (instancetype)initWithOriginLocation:(CLLocation *)origin andDestinationLocation:(CLLocation *)destination - sensor:(BOOL)sensor -{ + sensor:(BOOL)sensor { self = [self initWithOriginLocation:origin andDestinationLocation:destination]; if (self) { self.sensor = sensor; - self.sensorFlagUsed = YES; + self.sensorFlagUsed = YES; } - + return self; } - (instancetype)initWithOriginString:(NSString *)origin - andDestinationLocation:(CLLocation *)destination -{ - self = [super init]; - if (self) { - self.originString = origin; - self.destinationLocation = destination; - } - return self; + andDestinationLocation:(CLLocation *)destination { + self = [super init]; + if (self) { + self.originString = origin; + self.destinationLocation = destination; + } + return self; } - (instancetype)initWithOriginString:(NSString *)origin andDestinationLocation:(CLLocation *)destination - sensor:(BOOL)sensor -{ + sensor:(BOOL)sensor { self = [self initWithOriginString:origin andDestinationLocation:destination]; if (self) { self.sensor = sensor; - self.sensorFlagUsed = YES; + self.sensorFlagUsed = YES; } return self; } - (instancetype)initWithOriginLocation:(CLLocation *)origin - andDestinationString:(NSString *)destination -{ - self = [super init]; - if (self) { - self.originLocation = origin; - self.destinationString = destination; - } - return self; + andDestinationString:(NSString *)destination { + self = [super init]; + if (self) { + self.originLocation = origin; + self.destinationString = destination; + } + return self; } - (instancetype)initWithOriginLocation:(CLLocation *)origin andDestinationString:(NSString *)destination - sensor:(BOOL)sensor -{ + sensor:(BOOL)sensor { self = [self initWithOriginLocation:origin andDestinationString:destination]; if (self) { self.sensor = sensor; - self.sensorFlagUsed = YES; + self.sensorFlagUsed = YES; } return self; } - (instancetype)initWithOriginString:(NSString *)origin - andDestinationString:(NSString *)destination -{ - self = [super init]; - if (self) { - self.originString = origin; - self.destinationString = destination; - } - return self; + andDestinationString:(NSString *)destination { + self = [super init]; + if (self) { + self.originString = origin; + self.destinationString = destination; + } + return self; } - (instancetype)initWithOriginString:(NSString *)origin andDestinationString:(NSString *)destination - sensor:(BOOL)sensor -{ + sensor:(BOOL)sensor { self = [self initWithOriginString:origin andDestinationString:destination]; if (self) { self.sensor = sensor; - self.sensorFlagUsed = YES; + self.sensorFlagUsed = YES; } return self; } @@ -134,122 +127,113 @@ - (instancetype)initWithOriginString:(NSString *)origin @implementation OCDirectionsRequest (Creation) + (instancetype)requestWithOriginLocation:(CLLocation *)origin - andDestinationLocation:(CLLocation *)destination -{ - OCAssertParameterNotNil(origin, @"Origin location is nil."); - OCAssertParameterNotNil(destination, @"Destination location is nil."); - - OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginLocation:origin - andDestinationLocation:destination]; - - return request; + andDestinationLocation:(CLLocation *)destination { + OCAssertParameterNotNil(origin, @"Origin location is nil."); + OCAssertParameterNotNil(destination, @"Destination location is nil."); + + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] + initWithOriginLocation:origin + andDestinationLocation:destination]; + + return request; } + (instancetype)requestWithOriginLocation:(CLLocation *)origin andDestinationLocation:(CLLocation *)destination - sensor:(BOOL)sensor -{ + sensor:(BOOL)sensor { OCAssertParameterNotNil(origin, @"Origin location is nil."); OCAssertParameterNotNil(destination, @"Destination location is nil."); - + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginLocation:origin - andDestinationLocation:destination - sensor:sensor]; - + initWithOriginLocation:origin + andDestinationLocation:destination + sensor:sensor]; + return request; } + (instancetype)requestWithOriginString:(NSString *)origin - andDestinationLocation:(CLLocation *)destination -{ - OCAssertParameterNotNil(origin, @"Origin string is nil."); - OCAssertParameterNotNil(destination, @"Destination location is nil."); - - OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginString:origin - andDestinationLocation:destination]; - return request; + andDestinationLocation:(CLLocation *)destination { + OCAssertParameterNotNil(origin, @"Origin string is nil."); + OCAssertParameterNotNil(destination, @"Destination location is nil."); + + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] + initWithOriginString:origin + andDestinationLocation:destination]; + return request; } + (instancetype)requestWithOriginString:(NSString *)origin andDestinationLocation:(CLLocation *)destination - sensor:(BOOL)sensor -{ + sensor:(BOOL)sensor { OCAssertParameterNotNil(origin, @"Origin string is nil."); OCAssertParameterNotNil(destination, @"Destination location is nil."); - + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginString:origin - andDestinationLocation:destination - sensor:sensor]; + initWithOriginString:origin + andDestinationLocation:destination + sensor:sensor]; return request; } + (instancetype)requestWithOriginLocation:(CLLocation *)origin andDestinationString:(NSString *)destination - sensor:(BOOL)sensor -{ + sensor:(BOOL)sensor { OCAssertParameterNotNil(origin, @"Origin location is nil."); OCAssertParameterNotNil(destination, @"Destination string is nil."); - + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginLocation:origin - andDestinationString:destination - sensor:sensor]; + initWithOriginLocation:origin + andDestinationString:destination + sensor:sensor]; return request; } + (instancetype)requestWithOriginLocation:(CLLocation *)origin - andDestinationString:(NSString *)destination -{ - OCAssertParameterNotNil(origin, @"Origin location is nil."); - OCAssertParameterNotNil(destination, @"Destination string is nil."); - - OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginLocation:origin - andDestinationString:destination]; - return request; + andDestinationString:(NSString *)destination { + OCAssertParameterNotNil(origin, @"Origin location is nil."); + OCAssertParameterNotNil(destination, @"Destination string is nil."); + + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] + initWithOriginLocation:origin + andDestinationString:destination]; + return request; } + (instancetype)requestWithOriginString:(NSString *)origin - andDestinationString:(NSString *)destination -{ + andDestinationString:(NSString *)destination { OCAssertParameterNotNil(origin, @"Origin string is nil."); OCAssertParameterNotNil(destination, @"Destination string is nil."); - + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginString:origin - andDestinationString:destination]; + initWithOriginString:origin + andDestinationString:destination]; return request; } + (instancetype)requestWithOriginString:(NSString *)origin - andDestinationString:(NSString *)destination - sensor:(BOOL)sensor -{ - OCAssertParameterNotNil(origin, @"Origin string is nil."); - OCAssertParameterNotNil(destination, @"Destination string is nil."); - - OCDirectionsRequest *request = [[OCDirectionsRequest alloc] - initWithOriginString:origin - andDestinationString:destination - sensor:sensor]; - return request; -} - -- (BOOL)isValid -{ - if (self.originLocation == nil && self.originString == nil) { - return NO; - } - - if (self.destinationLocation == nil && self.destinationString == nil) { - return NO; - } - - return YES; + andDestinationString:(NSString *)destination + sensor:(BOOL)sensor { + OCAssertParameterNotNil(origin, @"Origin string is nil."); + OCAssertParameterNotNil(destination, @"Destination string is nil."); + + OCDirectionsRequest *request = [[OCDirectionsRequest alloc] + initWithOriginString:origin + andDestinationString:destination + sensor:sensor]; + return request; +} + +- (BOOL)isValid { + if (self.originLocation == nil && self.originString == nil) { + return NO; + } + + if (self.destinationLocation == nil && self.destinationString == nil) { + return NO; + } + + return YES; } @end diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h index 53b3e8b..25eccb0 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h @@ -11,10 +11,10 @@ @interface OCDirectionsBounds : NSObject -@property (nonatomic, retain, readonly) NSDictionary *dictionary; +@property(nonatomic, retain, readonly) NSDictionary *dictionary; -@property (nonatomic, assign, readonly) CLLocationCoordinate2D southwest; -@property (nonatomic, assign, readonly) CLLocationCoordinate2D northeast; +@property(nonatomic, assign, readonly) CLLocationCoordinate2D southwest; +@property(nonatomic, assign, readonly) CLLocationCoordinate2D northeast; + (instancetype)boundsFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.m index a80557f..ebd6743 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.m @@ -14,44 +14,41 @@ @implementation OCDirectionsBounds -+ (instancetype)boundsFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)boundsFromDictionary:(NSDictionary *)dictionary { OCDirectionsBounds *bounds = [[OCDirectionsBounds alloc] initWithDictionary:dictionary]; return bounds; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadSouthwest]; [self loadNortheast]; } -- (void)loadSouthwest -{ +- (void)loadSouthwest { NSDictionary *southwestDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeBoundsSouthwest]; CLLocationCoordinate2D coordinate = [CLLocation coordinateFromDictionary:southwestDictionary]; _southwest = coordinate; } -- (void)loadNortheast -{ +- (void)loadNortheast { NSDictionary *northeastDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeBoundsNortheast]; CLLocationCoordinate2D coordinate = [CLLocation coordinateFromDictionary:northeastDictionary]; - + _northeast = coordinate; } diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h index 82774eb..55cff17 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h @@ -12,10 +12,10 @@ extern NSString *const kCGGoogleDirectionsResponseAttributeDistance; @interface OCDirectionsDistance : NSObject -@property (nonatomic, retain, readonly) NSDictionary *dictionary; +@property(nonatomic, retain, readonly) NSDictionary *dictionary; -@property (nonatomic, copy, readonly) NSString *text; -@property (nonatomic, copy, readonly) NSNumber *value; +@property(nonatomic, copy, readonly) NSString *text; +@property(nonatomic, copy, readonly) NSNumber *value; + (instancetype)distanceFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.m index 72299a3..da03c1e 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.m @@ -15,42 +15,39 @@ @implementation OCDirectionsDistance -+ (instancetype)distanceFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)distanceFromDictionary:(NSDictionary *)dictionary { OCDirectionsDistance *distance = [[OCDirectionsDistance alloc] initWithDictionary:dictionary]; return distance; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadText]; [self loadValue]; } -- (void)loadText -{ +- (void)loadText { NSString *text = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDistanceText]; - + _text = text; } -- (void)loadValue -{ +- (void)loadValue { NSNumber *value = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDistanceValue]; - + _value = value; } diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h index 5d58148..d689483 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h @@ -12,10 +12,10 @@ extern NSString *const kCGGoogleDirectionsResponseAttributeDuration; @interface OCDirectionsDuration : NSObject -@property (nonatomic, retain, readonly) NSDictionary *dictionary; +@property(nonatomic, retain, readonly) NSDictionary *dictionary; -@property (nonatomic, copy, readonly) NSString *text; -@property (nonatomic, copy, readonly) NSNumber *value; +@property(nonatomic, copy, readonly) NSString *text; +@property(nonatomic, copy, readonly) NSNumber *value; + (instancetype)durationFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.m index e018d67..d6f3d2a 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.m @@ -15,42 +15,39 @@ @implementation OCDirectionsDuration -+ (instancetype)durationFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)durationFromDictionary:(NSDictionary *)dictionary { OCDirectionsDuration *duration = [[OCDirectionsDuration alloc] initWithDictionary:dictionary]; return duration; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadText]; [self loadValue]; } -- (void)loadText -{ +- (void)loadText { NSString *text = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDurationText]; - + _text = text; } -- (void)loadValue -{ +- (void)loadValue { NSNumber *value = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDurationValue]; - + _value = value; } diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h index 972e236..7d7a3b5 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h @@ -13,16 +13,16 @@ @interface OCDirectionsLeg : NSObject -@property (nonatomic, strong, readonly) NSDictionary *dictionary; +@property(nonatomic, strong, readonly) NSDictionary *dictionary; -@property (nonatomic, strong, readonly) OCDirectionsDistance *distance; -@property (nonatomic, strong, readonly) OCDirectionsDuration *duration; -@property (nonatomic, copy, readonly) NSString *endAddress; -@property (nonatomic, assign, readonly) CLLocationCoordinate2D endLocation; -@property (nonatomic, copy, readonly) NSString *startAddress; -@property (nonatomic, assign, readonly) CLLocationCoordinate2D startLocation; -@property (nonatomic, strong, readonly) NSArray *steps; -@property (nonatomic, strong, readonly) NSArray *viaWaypoint; +@property(nonatomic, strong, readonly) OCDirectionsDistance *distance; +@property(nonatomic, strong, readonly) OCDirectionsDuration *duration; +@property(nonatomic, copy, readonly) NSString *endAddress; +@property(nonatomic, assign, readonly) CLLocationCoordinate2D endLocation; +@property(nonatomic, copy, readonly) NSString *startAddress; +@property(nonatomic, assign, readonly) CLLocationCoordinate2D startLocation; +@property(nonatomic, strong, readonly) NSArray *steps; +@property(nonatomic, strong, readonly) NSArray *viaWaypoint; + (instancetype)legFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.m index b5978ff..ffaeec1 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.m @@ -19,28 +19,27 @@ @implementation OCDirectionsLeg -+ (instancetype)legFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)legFromDictionary:(NSDictionary *)dictionary { OCDirectionsLeg *leg = [[OCDirectionsLeg alloc] initWithDictionary:dictionary]; - + return leg; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadDistance]; [self loadDuration]; [self loadEndAddress]; @@ -51,74 +50,66 @@ - (void)loadAllProperties [self loadViaWaypoint]; } -- (void)loadDistance -{ +- (void)loadDistance { NSDictionary *distanceDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDistance]; OCDirectionsDistance *distance = [OCDirectionsDistance distanceFromDictionary:distanceDictionary]; - + _distance = distance; } -- (void)loadDuration -{ +- (void)loadDuration { NSDictionary *durationDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDuration]; OCDirectionsDuration *duration = [OCDirectionsDuration durationFromDictionary:durationDictionary]; - + _duration = duration; } -- (void)loadEndAddress -{ +- (void)loadEndAddress { NSString *endAddress = [_dictionary objectForKey:kCGgoogleDirectionsResponseAttributeEndAddress]; _endAddress = endAddress; } -- (void)loadEndLocation -{ +- (void)loadEndLocation { NSDictionary *endLocationDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeEndLocation]; CLLocationCoordinate2D endLocation = [CLLocation coordinateFromDictionary:endLocationDictionary]; - + _endLocation = endLocation; } -- (void)loadStartAddress -{ +- (void)loadStartAddress { NSString *startAddress = [_dictionary objectForKey:kCGgoogleDirectionsResponseAttributeStartAddress]; - + _startAddress = startAddress; } -- (void)loadStartLocation -{ +- (void)loadStartLocation { NSDictionary *startLocationDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeStartLocation]; CLLocationCoordinate2D startLocation = [CLLocation coordinateFromDictionary:startLocationDictionary]; - + _startLocation = startLocation; } -- (void)loadSteps -{ +- (void)loadSteps { NSArray *stepsArray = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeSteps]; NSMutableArray *steps = [[NSMutableArray alloc] initWithCapacity:stepsArray.count]; - + for (NSDictionary *stepDictionary in stepsArray) { OCDirectionsStep *step = [OCDirectionsStep stepFromDictionary:stepDictionary]; [steps addObject:step]; } - + _steps = steps; } -- (void)loadViaWaypoint -{ +- (void)loadViaWaypoint { NSArray *viaWaypointArray = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeViaWaypoint]; NSMutableArray *viaWaypoint = [[NSMutableArray alloc] initWithCapacity:viaWaypointArray.count]; for (NSDictionary *viaWaypointDictionary in viaWaypointArray) { OCDirectionsWaypoint *waypoint = [OCDirectionsWaypoint waypointFromDictionary:viaWaypointDictionary]; [viaWaypoint addObject:waypoint]; } - + _viaWaypoint = viaWaypoint; } diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h index 72e7aa7..2d16c13 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h @@ -10,9 +10,9 @@ @interface OCDirectionsPolyline : NSObject -@property (nonatomic, retain, readonly) NSDictionary *dictionary; +@property(nonatomic, retain, readonly) NSDictionary *dictionary; -@property (nonatomic, copy, readonly) NSString *points; +@property(nonatomic, copy, readonly) NSString *points; + (instancetype)polylineFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.m index aff858f..e91547a 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.m @@ -12,34 +12,32 @@ @implementation OCDirectionsPolyline -+ (instancetype)polylineFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)polylineFromDictionary:(NSDictionary *)dictionary { OCDirectionsPolyline *polyline = [[OCDirectionsPolyline alloc] initWithDictionary:dictionary]; return polyline; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadPoints]; } -- (void)loadPoints -{ +- (void)loadPoints { NSString *points = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributePolylinePoints]; - + _points = points; } diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h index 8ff3218..a95d794 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h @@ -12,42 +12,42 @@ @interface OCDirectionsRoute : NSObject -@property (nonatomic, retain, readonly) NSDictionary *dictionary; +@property(nonatomic, retain, readonly) NSDictionary *dictionary; /** legs[] contains an array which contains information about a leg of the route, between two locations within the given route. A separate leg will be present for each waypoint or destination specified. (A route with no waypoints will contain exactly one leg within the legs array.) Each leg consists of a series of steps. (See Directions Legs below.) */ -@property (nonatomic, strong, readonly) NSArray *legs; +@property(nonatomic, strong, readonly) NSArray *legs; /** copyrights contains the copyrights text to be displayed for this route. You must handle and display this information yourself. */ -@property (nonatomic, copy, readonly) NSString *copyrights; +@property(nonatomic, copy, readonly) NSString *copyrights; /* warnings[] contains an array of warnings to be displayed when showing these directions. You must handle and display these warnings yourself. */ -@property (nonatomic, strong, readonly) NSArray *warnings; +@property(nonatomic, strong, readonly) NSArray *warnings; /** waypoint_order contains an array indicating the order of any waypoints in the calculated route. This waypoints may be reordered if the request was passed optimize:true within its waypoints parameter. */ -@property (nonatomic, strong, readonly) NSArray *waypointOrder; +@property(nonatomic, strong, readonly) NSArray *waypointOrder; /** overview_polyline contains an object holding an array of encoded points that represent an approximate (smoothed) path of the resulting directions. */ -@property (nonatomic, strong, readonly) OCDirectionsPolyline *overviewPolyline; +@property(nonatomic, strong, readonly) OCDirectionsPolyline *overviewPolyline; /** bounds contains the viewport bounding box of the overview_polyline. */ -@property (nonatomic, strong, readonly) OCDirectionsBounds *bounds; +@property(nonatomic, strong, readonly) OCDirectionsBounds *bounds; /** summary contains a short textual description for the route, suitable for naming and disambiguating the route from alternatives. */ -@property (nonatomic, strong, readonly) NSString *summary; +@property(nonatomic, strong, readonly) NSString *summary; + (instancetype)routeFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m index 6a7f599..3d0fa60 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m @@ -19,87 +19,79 @@ @implementation OCDirectionsRoute -+ (instancetype)routeFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)routeFromDictionary:(NSDictionary *)dictionary { OCDirectionsRoute *route = [[OCDirectionsRoute alloc] initWithDictionary:dictionary]; return route; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadLegs]; [self loadCopyrights]; [self loadWarnings]; [self loadWaypointOrder]; [self loadOverviewPolyline]; [self loadBounds]; - [self loadSummary]; + [self loadSummary]; } -- (void)loadLegs -{ +- (void)loadLegs { NSArray *legsArray = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRouteLegs]; NSMutableArray *legs = [[NSMutableArray alloc] initWithCapacity:legsArray.count]; for (NSDictionary *legDictionary in legsArray) { OCDirectionsLeg *leg = [OCDirectionsLeg legFromDictionary:legDictionary]; [legs addObject:leg]; } - + _legs = legs; } -- (void)loadCopyrights -{ +- (void)loadCopyrights { NSString *copyrights = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRouteCopyrights]; - + _copyrights = copyrights; } -- (void)loadWarnings -{ +- (void)loadWarnings { NSArray *warningsArray = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRouteWarnings]; - + _warnings = warningsArray; } -- (void)loadWaypointOrder -{ +- (void)loadWaypointOrder { NSArray *waypointOrder = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRouteWaypointOrder]; - + _waypointOrder = waypointOrder; } -- (void)loadOverviewPolyline -{ +- (void)loadOverviewPolyline { NSDictionary *overviewPolyline = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRouteOverviewPolyline]; OCDirectionsPolyline *polyline = [OCDirectionsPolyline polylineFromDictionary:overviewPolyline]; - + _overviewPolyline = polyline; } -- (void)loadBounds -{ +- (void)loadBounds { NSDictionary *boundsDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRouteBounds]; OCDirectionsBounds *bounds = [OCDirectionsBounds boundsFromDictionary:boundsDictionary]; - + _bounds = bounds; } -- (void)loadSummary -{ +- (void)loadSummary { NSString *summary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRouteSummary]; _summary = summary; } diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h index 2e3178c..6fe4771 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h @@ -18,16 +18,16 @@ extern NSString *const kCGGoogleDirectionsResponseAttributeStartLocation; @interface OCDirectionsStep : NSObject -@property (nonatomic, strong, readonly) NSDictionary *dictionary; +@property(nonatomic, strong, readonly) NSDictionary *dictionary; -@property (nonatomic, strong, readonly) OCDirectionsDistance *distance; -@property (nonatomic, strong, readonly) OCDirectionsDuration *duration; -@property (nonatomic, assign, readonly) CLLocationCoordinate2D endLocation; -@property (nonatomic, copy, readonly) NSString *htmlInstructions; -@property (nonatomic, copy, readonly) NSString *maneuver; -@property (nonatomic, strong, readonly) OCDirectionsPolyline *polyline; -@property (nonatomic, assign, readonly) CLLocationCoordinate2D startLocation; -@property (nonatomic, assign, readonly) OCDirectionsRequestTravelMode travelMode; +@property(nonatomic, strong, readonly) OCDirectionsDistance *distance; +@property(nonatomic, strong, readonly) OCDirectionsDuration *duration; +@property(nonatomic, assign, readonly) CLLocationCoordinate2D endLocation; +@property(nonatomic, copy, readonly) NSString *htmlInstructions; +@property(nonatomic, copy, readonly) NSString *maneuver; +@property(nonatomic, strong, readonly) OCDirectionsPolyline *polyline; +@property(nonatomic, assign, readonly) CLLocationCoordinate2D startLocation; +@property(nonatomic, assign, readonly) OCDirectionsRequestTravelMode travelMode; + (instancetype)stepFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.m index 05e8d36..411510c 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.m @@ -20,27 +20,26 @@ @implementation OCDirectionsStep -+ (instancetype)stepFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)stepFromDictionary:(NSDictionary *)dictionary { OCDirectionsStep *step = [[OCDirectionsStep alloc] initWithDictionary:dictionary]; return step; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadDistance]; [self loadDuration]; [self loadEndLocation]; @@ -51,65 +50,57 @@ - (void)loadAllProperties [self loadTravelMode]; } -- (void)loadDistance -{ +- (void)loadDistance { NSDictionary *distanceDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDistance]; OCDirectionsDistance *distance = [OCDirectionsDistance distanceFromDictionary:distanceDictionary]; - + _distance = distance; } -- (void)loadDuration -{ +- (void)loadDuration { NSDictionary *durationDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDuration]; OCDirectionsDuration *duration = [OCDirectionsDuration durationFromDictionary:durationDictionary]; - + _duration = duration; } -- (void)loadEndLocation -{ +- (void)loadEndLocation { NSDictionary *endLocationDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeEndLocation]; CLLocationCoordinate2D endLocation = [CLLocation coordinateFromDictionary:endLocationDictionary]; - + _endLocation = endLocation; } -- (void)loadHtmlInstructions -{ +- (void)loadHtmlInstructions { NSString *htmlInstructions = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeHtmlInstructions]; - + _htmlInstructions = htmlInstructions; } -- (void)loadManeuver -{ +- (void)loadManeuver { NSString *maneuver = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributManeuver]; - + _maneuver = maneuver; } -- (void)loadPolyline -{ +- (void)loadPolyline { NSDictionary *polylineDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributPolyline]; OCDirectionsPolyline *polyline = [OCDirectionsPolyline polylineFromDictionary:polylineDictionary]; - + _polyline = polyline; } -- (void)loadStartLocation -{ +- (void)loadStartLocation { NSDictionary *startLocationDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeStartLocation]; CLLocationCoordinate2D startLocation = [CLLocation coordinateFromDictionary:startLocationDictionary]; - + _startLocation = startLocation; } -- (void)loadTravelMode -{ +- (void)loadTravelMode { NSString *travelModeString = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributTravelMode]; OCDirectionsRequestTravelMode travelMode = [OCDirectionsCommonTypes travelModeFromString:travelModeString]; - + _travelMode = travelMode; } diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h index c6836ac..140fc7d 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h @@ -11,22 +11,22 @@ @interface OCDirectionsWaypoint : NSObject -@property (nonatomic, retain, readonly) NSDictionary *dictionary; +@property(nonatomic, retain, readonly) NSDictionary *dictionary; /** Not documented yet. */ -@property (nonatomic, assign, readonly) CLLocationCoordinate2D location; +@property(nonatomic, assign, readonly) CLLocationCoordinate2D location; /** Not documented yet. */ -@property (nonatomic, retain, readonly) NSNumber *stepIndex; +@property(nonatomic, retain, readonly) NSNumber *stepIndex; /** Not documented yet. */ -@property (nonatomic, retain, readonly) NSNumber *stepInterpolation; +@property(nonatomic, retain, readonly) NSNumber *stepInterpolation; + (instancetype)waypointFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.m index b675c80..316640f 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.m @@ -15,51 +15,47 @@ @implementation OCDirectionsWaypoint -+ (instancetype)waypointFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)waypointFromDictionary:(NSDictionary *)dictionary { OCDirectionsWaypoint *waypoint = [[OCDirectionsWaypoint alloc] initWithDictionary:dictionary]; return waypoint; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadAllProperties]; } return self; } #pragma mark - Load properties from dictionary -- (void)loadAllProperties -{ + +- (void)loadAllProperties { [self loadLocation]; [self loadStepIndex]; [self loadStepInterpolation]; } -- (void)loadLocation -{ +- (void)loadLocation { NSDictionary *locationDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeLocation]; CLLocationCoordinate2D location = [CLLocation coordinateFromDictionary:locationDictionary]; - + _location = location; } -- (void)loadStepIndex -{ +- (void)loadStepIndex { NSNumber *stepIndex = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeStepIndex]; - + _stepIndex = stepIndex; } -- (void)loadStepInterpolation -{ +- (void)loadStepInterpolation { NSNumber *stepInterpolation = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeStepInterpolation]; - + _stepInterpolation = stepInterpolation; } diff --git a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h index 4d01fce..d8fef6c 100644 --- a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h +++ b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h @@ -23,22 +23,22 @@ typedef NS_ENUM(NSUInteger, OCDirectionsResponseStatus) { @interface OCDirectionsResponse : NSObject -@property (nonatomic, strong, readonly) NSDictionary *dictionary; +@property(nonatomic, strong, readonly) NSDictionary *dictionary; /** "status" contains metadata on the request. See Status Codes above. */ -@property (nonatomic, assign, readonly) OCDirectionsResponseStatus status; +@property(nonatomic, assign, readonly) OCDirectionsResponseStatus status; /** "routes" contains an array of routes from the origin to the destination. */ -@property (nonatomic, strong, readonly) NSArray *routes; +@property(nonatomic, strong, readonly) NSArray *routes; /** "errorMessage" (optional) field contains more detailed information about the reasons behind the given status code. */ -@property (nonatomic, copy, readonly) NSString *errorMessage; +@property(nonatomic, copy, readonly) NSString *errorMessage; + (instancetype)responseFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m index 2c41135..85f9ba2 100644 --- a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m +++ b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m @@ -14,24 +14,22 @@ @implementation OCDirectionsResponse -+ (instancetype)responseFromDictionary:(NSDictionary *)dictionary -{ ++ (instancetype)responseFromDictionary:(NSDictionary *)dictionary { OCDirectionsResponse *response = [[OCDirectionsResponse alloc] initWithDictionary:dictionary]; return response; } -- (OCDirectionsRoute *)route -{ +- (OCDirectionsRoute *)route { return self.routes.firstObject; } #pragma mark - Private init -- (instancetype)initWithDictionary:(NSDictionary *)dictionary -{ + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { self = [super init]; if (self) { _dictionary = dictionary; - + [self loadStatus]; [self loadRoutes]; [self loadErrorMessage]; @@ -40,51 +38,49 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary } #pragma mark - Private methods -+ (NSDictionary *)statusDictionary -{ + ++ (NSDictionary *)statusDictionary { static NSDictionary *dictionary; - + if (dictionary == nil) { - dictionary = @{@"OK" : @(OCDirectionsResponseStatusOK), - @"NOT_FOUND" : @(OCDirectionsResponseStatusNotFound), - @"ZERO_RESULTS" : @(OCDirectionsResponseStatusZeroResults), - @"MAX_WAYPOINTS_EXCEEDED" : @(OCDirectionsResponseStatusMaxWaypointsExceeded), - @"INVALID_REQUEST" : @(OCDirectionsResponseStatusInvalidRequest), - @"OVER_QUERY_LIMIT" : @(OCDirectionsResponseStatusOverQueryLimit), - @"REQUEST_DENIED" : @(OCDirectionsResponseStatusRequestDenied), - @"UNKNOWN_ERROR" : @(OCDirectionsResponseStatusUnknownError) - }; + dictionary = @{@"OK" : @(OCDirectionsResponseStatusOK), + @"NOT_FOUND" : @(OCDirectionsResponseStatusNotFound), + @"ZERO_RESULTS" : @(OCDirectionsResponseStatusZeroResults), + @"MAX_WAYPOINTS_EXCEEDED" : @(OCDirectionsResponseStatusMaxWaypointsExceeded), + @"INVALID_REQUEST" : @(OCDirectionsResponseStatusInvalidRequest), + @"OVER_QUERY_LIMIT" : @(OCDirectionsResponseStatusOverQueryLimit), + @"REQUEST_DENIED" : @(OCDirectionsResponseStatusRequestDenied), + @"UNKNOWN_ERROR" : @(OCDirectionsResponseStatusUnknownError) + }; } return dictionary; } #pragma mark - Load attributes from dictionary -- (void)loadStatus -{ + +- (void)loadStatus { NSString *statusString = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeStatus]; - + NSNumber *statusNumber = [[OCDirectionsResponse statusDictionary] objectForKey:statusString]; - + _status = [statusNumber unsignedIntegerValue]; } -- (void)loadRoutes -{ +- (void)loadRoutes { NSArray *routesArray = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeRoutes]; - + NSMutableArray *routes = [[NSMutableArray alloc] initWithCapacity:routesArray.count]; for (NSDictionary *routeDictionary in routesArray) { OCDirectionsRoute *route = [OCDirectionsRoute routeFromDictionary:routeDictionary]; [routes addObject:route]; } - + _routes = routes; } -- (void)loadErrorMessage -{ +- (void)loadErrorMessage { NSString *errorMessage = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeErrorMessage]; - + _errorMessage = errorMessage; } diff --git a/Source/OCGoogleDirectionsAPI/Shared Classes/CLLocation/CLLocation+CoortindateFromDictionary.m b/Source/OCGoogleDirectionsAPI/Shared Classes/CLLocation/CLLocation+CoortindateFromDictionary.m index 2105a51..ec4ca74 100644 --- a/Source/OCGoogleDirectionsAPI/Shared Classes/CLLocation/CLLocation+CoortindateFromDictionary.m +++ b/Source/OCGoogleDirectionsAPI/Shared Classes/CLLocation/CLLocation+CoortindateFromDictionary.m @@ -7,18 +7,16 @@ // #import "CLLocation+CoortindateFromDictionary.h" -#import static NSString *const kCGGoogleDirectionsResponseAttributeLat = @"lat"; static NSString *const kCGGoogleDirectionsResponseAttributeLng = @"lng"; @implementation CLLocation (CoortindateFromDictionary) -+ (CLLocationCoordinate2D)coordinateFromDictionary:(NSDictionary *)dictionary -{ ++ (CLLocationCoordinate2D)coordinateFromDictionary:(NSDictionary *)dictionary { NSNumber *lat = [dictionary objectForKey:kCGGoogleDirectionsResponseAttributeLat]; NSNumber *lng = [dictionary objectForKey:kCGGoogleDirectionsResponseAttributeLng]; - + CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(lat.doubleValue, lng.doubleValue); return coordinate; } diff --git a/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m b/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m index 7e9eba3..1d19e1e 100644 --- a/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m +++ b/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m @@ -10,14 +10,12 @@ #import #import "OCDirectionsRequestURLCreator.h" #import "OCDirectionsRequestURLCreatorJSON.h" -#import "OCDirectionsRequest.h" -#import "OCDirectionsResponse.h" static NSString *const kTestKey = @"0123456789abcdef"; @interface OCDirectionsRequestURLCreatorJSONTests : XCTestCase -@property (nonatomic, strong) OCDirectionsRequestURLCreatorJSON *urlCreator; +@property(nonatomic, strong) OCDirectionsRequestURLCreatorJSON *urlCreator; @end @@ -26,264 +24,244 @@ @implementation OCDirectionsRequestURLCreatorJSONTests #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" -- (void)setUp -{ +- (void)setUp { [super setUp]; - self.urlCreator = [OCDirectionsRequestURLCreatorJSON new]; + self.urlCreator = [OCDirectionsRequestURLCreatorJSON new]; } -- (void)tearDown -{ +- (void)tearDown { self.urlCreator = nil; - + [super tearDown]; } -- (void)testConformsToOCDiretionsRequestURLCreatorProtocol -{ +- (void)testConformsToOCDiretionsRequestURLCreatorProtocol { XCTAssertTrue([self.urlCreator conformsToProtocol:@protocol(OCDirectionsRequestURLCreator)]); } #pragma mark - Test stringFromRequest:useHttps:andKey: when arguments are invalid -- (void)testStringFromRequestWhenRequestIsNil -{ - // given - OCDirectionsRequest *request = nil; - NSString *key = [self prepareTestKey]; - - // then - XCTAssertThrowsSpecificNamed([self.urlCreator stringFromRequest:request useHttps:YES andKey:key], NSException, NSInvalidArgumentException); + +- (void)testStringFromRequestWhenRequestIsNil { + // given + OCDirectionsRequest *request = nil; + NSString *key = [self prepareTestKey]; + + // then + XCTAssertThrowsSpecificNamed([self.urlCreator stringFromRequest:request useHttps:YES andKey:key], NSException, NSInvalidArgumentException); } -- (void)testStringFromRequestWhenKeyIsNil -{ - // given - OCDirectionsRequest *request = [self prepareRequest]; - NSString *key = nil; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false", response); +- (void)testStringFromRequestWhenKeyIsNil { + // given + OCDirectionsRequest *request = [self prepareRequest]; + NSString *key = nil; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false", response); } -- (void)testStringFromRequestWhenRequestAndKeyAreNil -{ - // given - OCDirectionsRequest *request = nil; - NSString *key = nil; - - // then - XCTAssertThrowsSpecificNamed([self.urlCreator stringFromRequest:request useHttps:YES andKey:key], NSException, NSInvalidArgumentException); +- (void)testStringFromRequestWhenRequestAndKeyAreNil { + // given + OCDirectionsRequest *request = nil; + NSString *key = nil; + + // then + XCTAssertThrowsSpecificNamed([self.urlCreator stringFromRequest:request useHttps:YES andKey:key], NSException, NSInvalidArgumentException); } #pragma mark - Test stringFromRequest:useHttps:andKey: when arguments are valid -- (void)testStringFromRequestWhenAllArgumentsAreValid -{ - // given - OCDirectionsRequest *request = [self prepareRequest]; - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&key=0123456789abcdef", response); + +- (void)testStringFromRequestWhenAllArgumentsAreValid { + // given + OCDirectionsRequest *request = [self prepareRequest]; + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&key=0123456789abcdef", response); } -- (void)testStringFromRequestWhenAllArgumentsAreValidButNoSensor -{ - // given - OCDirectionsRequest *request = [self prepareNoSensorRequest]; - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&key=0123456789abcdef", response); +- (void)testStringFromRequestWhenAllArgumentsAreValidButNoSensor { + // given + OCDirectionsRequest *request = [self prepareNoSensorRequest]; + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&key=0123456789abcdef", response); } -- (void)testStringFromRequestWhenSensorIsTrue -{ - // given - OCDirectionsRequest *request = [self prepareRequestWithSensor]; - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=true&key=0123456789abcdef", response); +- (void)testStringFromRequestWhenSensorIsTrue { + // given + OCDirectionsRequest *request = [self prepareRequestWithSensor]; + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=true&key=0123456789abcdef", response); } -- (void)testStringFromRequestWhenOriginAndDestinationAreLocations -{ - // given - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:[self prepareFirstLocation] - andDestinationLocation:[self prepareSecondLocation] - sensor:NO]; - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=20.100000,30.100000&destination=40.100000,50.100000&sensor=false&key=0123456789abcdef", response); +- (void)testStringFromRequestWhenOriginAndDestinationAreLocations { + // given + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:[self prepareFirstLocation] + andDestinationLocation:[self prepareSecondLocation] + sensor:NO]; + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=20.100000,30.100000&destination=40.100000,50.100000&sensor=false&key=0123456789abcdef", response); } -- (void)testStringFromRequestWhenOriginAndDestinationAreLocationsButNoSensor -{ - // given - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:[self prepareFirstLocation] - andDestinationLocation:[self prepareSecondLocation]]; - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=20.100000,30.100000&destination=40.100000,50.100000&key=0123456789abcdef", response); +- (void)testStringFromRequestWhenOriginAndDestinationAreLocationsButNoSensor { + // given + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:[self prepareFirstLocation] + andDestinationLocation:[self prepareSecondLocation]]; + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=20.100000,30.100000&destination=40.100000,50.100000&key=0123456789abcdef", response); } -- (void)testStringFromRequestWhenOriginIsStringAndDestinationIsLocation -{ - // given - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"Lodz" - andDestinationLocation:[self prepareSecondLocation] - sensor:NO]; - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=Lodz&destination=40.100000,50.100000&sensor=false&key=0123456789abcdef", response); +- (void)testStringFromRequestWhenOriginIsStringAndDestinationIsLocation { + // given + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"Lodz" + andDestinationLocation:[self prepareSecondLocation] + sensor:NO]; + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=Lodz&destination=40.100000,50.100000&sensor=false&key=0123456789abcdef", response); } -- (void)testStringFromRequestWhenOriginIsLocationAndDestinationIsString -{ - // given - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:[self prepareFirstLocation] - andDestinationString:@"Lodz" - sensor:NO]; - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=20.100000,30.100000&destination=Lodz&sensor=false&key=0123456789abcdef", response); +- (void)testStringFromRequestWhenOriginIsLocationAndDestinationIsString { + // given + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:[self prepareFirstLocation] + andDestinationString:@"Lodz" + sensor:NO]; + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=20.100000,30.100000&destination=Lodz&sensor=false&key=0123456789abcdef", response); } -- (void)testStringFromRequestWhenTravelModeIsDriving -{ - // given - OCDirectionsRequest *request = [self prepareRequest]; - request.travelMode = OCDirectionsRequestTravelModeDriving; - - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&key=0123456789abcdef", response); // no mode parameter, it is default mode +- (void)testStringFromRequestWhenTravelModeIsDriving { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.travelMode = OCDirectionsRequestTravelModeDriving; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&key=0123456789abcdef", response); // no mode parameter, it is default mode } -- (void)testStringFromRequestWhenTravelModeIsWalking -{ - // given - OCDirectionsRequest *request = [self prepareRequest]; - request.travelMode = OCDirectionsRequestTravelModeWalking; - - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&mode=walking&key=0123456789abcdef", response); +- (void)testStringFromRequestWhenTravelModeIsWalking { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.travelMode = OCDirectionsRequestTravelModeWalking; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&mode=walking&key=0123456789abcdef", response); } -- (void)testStringFromRequestWhenTravelModeIsBicycling -{ - // given - OCDirectionsRequest *request = [self prepareRequest]; - request.travelMode = OCDirectionsRequestTravelModeBicycling; - - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&mode=bicycling&key=0123456789abcdef", response); +- (void)testStringFromRequestWhenTravelModeIsBicycling { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.travelMode = OCDirectionsRequestTravelModeBicycling; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&mode=bicycling&key=0123456789abcdef", response); } -- (void)testStringFromRequestWhenTravelModeIsTransit -{ - // given - OCDirectionsRequest *request = [self prepareRequest]; - request.travelMode = OCDirectionsRequestTravelModeTransit; - - NSString *key = [self prepareTestKey]; - - // when - NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; - - // then - XCTAssertNotNil(response); - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&mode=transit&key=0123456789abcdef", response); +- (void)testStringFromRequestWhenTravelModeIsTransit { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.travelMode = OCDirectionsRequestTravelModeTransit; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertNotNil(response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&mode=transit&key=0123456789abcdef", response); } #pragma mark - Helpers -- (NSString *)prepareTestKey -{ - return kTestKey; + +- (NSString *)prepareTestKey { + return kTestKey; } -- (OCDirectionsRequest *)prepareRequest -{ - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"London" andDestinationString:@"Lodz" sensor:NO]; - return request; +- (OCDirectionsRequest *)prepareRequest { + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"London" andDestinationString:@"Lodz" sensor:NO]; + return request; } -- (OCDirectionsRequest *)prepareNoSensorRequest -{ - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"London" andDestinationString:@"Lodz"]; - return request; +- (OCDirectionsRequest *)prepareNoSensorRequest { + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"London" andDestinationString:@"Lodz"]; + return request; } - -- (OCDirectionsRequest *)prepareRequestWithSensor -{ - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"London" andDestinationString:@"Lodz" sensor:YES]; - return request; + +- (OCDirectionsRequest *)prepareRequestWithSensor { + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:@"London" andDestinationString:@"Lodz" sensor:YES]; + return request; } -- (CLLocation *)prepareFirstLocation -{ - CLLocation *location = [[CLLocation alloc] initWithLatitude:20.1 longitude:30.1]; - return location; +- (CLLocation *)prepareFirstLocation { + CLLocation *location = [[CLLocation alloc] initWithLatitude:20.1 longitude:30.1]; + return location; } -- (CLLocation *)prepareSecondLocation -{ - CLLocation *location = [[CLLocation alloc] initWithLatitude:40.1 longitude:50.1]; - return location; +- (CLLocation *)prepareSecondLocation { + CLLocation *location = [[CLLocation alloc] initWithLatitude:40.1 longitude:50.1]; + return location; } #pragma clang diagnostic pop diff --git a/Source/OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist b/Source/OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist index 5f3a288..99d20ce 100644 --- a/Source/OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist +++ b/Source/OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist @@ -1,22 +1,22 @@ - - CFBundleDevelopmentRegion - en - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIdentifier - cx.idev.${PRODUCT_NAME:rfc1034identifier} - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + cx.idev.${PRODUCT_NAME:rfc1034identifier} + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + diff --git a/Source/OCGoogleDirectionsAPITests/Request/OCDirectionsRequestTests.m b/Source/OCGoogleDirectionsAPITests/Request/OCDirectionsRequestTests.m index d698e7f..aa2f966 100644 --- a/Source/OCGoogleDirectionsAPITests/Request/OCDirectionsRequestTests.m +++ b/Source/OCGoogleDirectionsAPITests/Request/OCDirectionsRequestTests.m @@ -6,7 +6,6 @@ // // -#import #import #import "OCDirectionsRequest.h" @@ -20,448 +19,426 @@ @implementation OCDIrestionsRequestTests #pragma clang diagnostic ignored "-Wdeprecated-declarations" #pragma mark - Test helpers -- (void)testPrepareFirstLocationHelper -{ - // when - CLLocation *location = [self prepareFirstLocation]; - - // then - XCTAssertNotNil(location); - XCTAssertTrue([location isMemberOfClass:[CLLocation class]]); + +- (void)testPrepareFirstLocationHelper { + // when + CLLocation *location = [self prepareFirstLocation]; + + // then + XCTAssertNotNil(location); + XCTAssertTrue([location isMemberOfClass:[CLLocation class]]); } -- (void)testPrepareSecondLocationHelper -{ - // when - CLLocation *location = [self prepareSecondLocation]; - - // then - XCTAssertNotNil(location); - XCTAssertTrue([location isMemberOfClass:[CLLocation class]]); +- (void)testPrepareSecondLocationHelper { + // when + CLLocation *location = [self prepareSecondLocation]; + + // then + XCTAssertNotNil(location); + XCTAssertTrue([location isMemberOfClass:[CLLocation class]]); } -- (void)testPrepareFirstStringHelper -{ - // when - NSString *string = [self prepareFirstString]; - - // then - XCTAssertNotNil(string); - XCTAssertEqual(@"London", string); +- (void)testPrepareFirstStringHelper { + // when + NSString *string = [self prepareFirstString]; + + // then + XCTAssertNotNil(string); + XCTAssertEqual(@"London", string); } -- (void)testPreapreSecondStringHelper -{ - // when - NSString *string = [self prepareSecondString]; - - // then - XCTAssertNotNil(string); - XCTAssertEqual(@"Reading", string); +- (void)testPreapreSecondStringHelper { + // when + NSString *string = [self prepareSecondString]; + + // then + XCTAssertNotNil(string); + XCTAssertEqual(@"Reading", string); } #pragma mark - Test requestWithOriginLocation:andDestinationLocation:sensor: -- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginIsNil -{ - // given - CLLocation *originLocation = nil; - CLLocation *destinationLocation = [self prepareSecondLocation]; - - // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationLocation:destinationLocation - sensor:NO], NSException, NSInvalidArgumentException); + +- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginIsNil { + // given + CLLocation *originLocation = nil; + CLLocation *destinationLocation = [self prepareSecondLocation]; + + // then + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationLocation:destinationLocation + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginLocationAndDestinationLocationWhenDestinationIsNil -{ - // given - CLLocation *originLocation = [self prepareFirstLocation]; - CLLocation *destinationLocation = nil; - +- (void)testRequestWithOriginLocationAndDestinationLocationWhenDestinationIsNil { + // given + CLLocation *originLocation = [self prepareFirstLocation]; + CLLocation *destinationLocation = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationLocation:destinationLocation - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationLocation:destinationLocation + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginAndDestinationAreNil -{ - // given - CLLocation *originLocation = nil; - CLLocation *destinationLocation = nil; - +- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginAndDestinationAreNil { + // given + CLLocation *originLocation = nil; + CLLocation *destinationLocation = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationLocation:destinationLocation - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationLocation:destinationLocation + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginAndDestinationAreNotNil -{ - // given - CLLocation *originLocation = [self prepareFirstLocation]; - CLLocation *destinationLocation = [self prepareSecondLocation]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationLocation:destinationLocation - sensor:NO]; - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originLocation, request.originLocation); - XCTAssertNil(request.originString); - XCTAssertEqual(destinationLocation, request.destinationLocation); - XCTAssertNil(request.destinationString); - XCTAssertFalse(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginAndDestinationAreNotNil { + // given + CLLocation *originLocation = [self prepareFirstLocation]; + CLLocation *destinationLocation = [self prepareSecondLocation]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationLocation:destinationLocation + sensor:NO]; + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originLocation, request.originLocation); + XCTAssertNil(request.originString); + XCTAssertEqual(destinationLocation, request.destinationLocation); + XCTAssertNil(request.destinationString); + XCTAssertFalse(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } -- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginAndDestinationAreNotNilAndSensorIsTrue -{ - // given - CLLocation *originLocation = [self prepareFirstLocation]; - CLLocation *destinationLocation = [self prepareSecondLocation]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationLocation:destinationLocation - sensor:YES]; - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originLocation, request.originLocation); - XCTAssertNil(request.originString); - XCTAssertEqual(destinationLocation, request.destinationLocation); - XCTAssertNil(request.destinationString); - XCTAssertTrue(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginLocationAndDestinationLocationWhenOriginAndDestinationAreNotNilAndSensorIsTrue { + // given + CLLocation *originLocation = [self prepareFirstLocation]; + CLLocation *destinationLocation = [self prepareSecondLocation]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationLocation:destinationLocation + sensor:YES]; + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originLocation, request.originLocation); + XCTAssertNil(request.originString); + XCTAssertEqual(destinationLocation, request.destinationLocation); + XCTAssertNil(request.destinationString); + XCTAssertTrue(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } #pragma mark - Test requestWithOriginString:andDestinationLocation:sensor: -- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginIsNil -{ - // given - NSString *originString = nil; - CLLocation *destinationLocation = [self prepareSecondLocation]; - + +- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginIsNil { + // given + NSString *originString = nil; + CLLocation *destinationLocation = [self prepareSecondLocation]; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString - andDestinationLocation:destinationLocation - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString + andDestinationLocation:destinationLocation + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginStringAndDestinationLocationWhenDestinationIsNil -{ - // given - NSString *originString = [self prepareFirstString]; - CLLocation *destinationLocation = nil; - +- (void)testRequestWithOriginStringAndDestinationLocationWhenDestinationIsNil { + // given + NSString *originString = [self prepareFirstString]; + CLLocation *destinationLocation = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString - andDestinationLocation:destinationLocation - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString + andDestinationLocation:destinationLocation + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginAndDestinationAreNil -{ - // given - NSString *originString = nil; - CLLocation *destinationLocation = nil; - +- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginAndDestinationAreNil { + // given + NSString *originString = nil; + CLLocation *destinationLocation = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString - andDestinationLocation:destinationLocation - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString + andDestinationLocation:destinationLocation + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginAndDestinationAreNotNil -{ - // given - NSString *originString = [self prepareFirstString]; - CLLocation *destinationLocation = [self prepareSecondLocation]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString - andDestinationLocation:destinationLocation - sensor:NO]; - - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originString, request.originString); - XCTAssertNil(request.originLocation); - XCTAssertEqual(destinationLocation, request.destinationLocation); - XCTAssertNil(request.destinationString); - XCTAssertFalse(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginAndDestinationAreNotNil { + // given + NSString *originString = [self prepareFirstString]; + CLLocation *destinationLocation = [self prepareSecondLocation]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString + andDestinationLocation:destinationLocation + sensor:NO]; + + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originString, request.originString); + XCTAssertNil(request.originLocation); + XCTAssertEqual(destinationLocation, request.destinationLocation); + XCTAssertNil(request.destinationString); + XCTAssertFalse(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } -- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginAndDestinationAreNotNilAndSensorIsTrue -{ - // given - NSString *originString = [self prepareFirstString]; - CLLocation *destinationLocation = [self prepareSecondLocation]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString - andDestinationLocation:destinationLocation - sensor:YES]; - - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originString, request.originString); - XCTAssertNil(request.originLocation); - XCTAssertEqual(destinationLocation, request.destinationLocation); - XCTAssertNil(request.destinationString); - XCTAssertTrue(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginStringAndDestinationLocationWhenOriginAndDestinationAreNotNilAndSensorIsTrue { + // given + NSString *originString = [self prepareFirstString]; + CLLocation *destinationLocation = [self prepareSecondLocation]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString + andDestinationLocation:destinationLocation + sensor:YES]; + + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originString, request.originString); + XCTAssertNil(request.originLocation); + XCTAssertEqual(destinationLocation, request.destinationLocation); + XCTAssertNil(request.destinationString); + XCTAssertTrue(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } #pragma mark - Test requestWithOriginLocation:andDestinationString:sensor: -- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginIsNil -{ - // given - CLLocation *originLocation = nil; - NSString *destinationString = [self prepareSecondString]; - + +- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginIsNil { + // given + CLLocation *originLocation = nil; + NSString *destinationString = [self prepareSecondString]; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationString:destinationString - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationString:destinationString + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginLocationAndDestinationStringWhenDestinationIsNil -{ - // given - CLLocation *originLocation = [self prepareFirstLocation]; - NSString *destinationString = nil; - +- (void)testRequestWithOriginLocationAndDestinationStringWhenDestinationIsNil { + // given + CLLocation *originLocation = [self prepareFirstLocation]; + NSString *destinationString = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationString:destinationString - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationString:destinationString + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginAndDestinationAreNil -{ - // given - CLLocation *originLocation = nil; - NSString *destinationString = nil; - +- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginAndDestinationAreNil { + // given + CLLocation *originLocation = nil; + NSString *destinationString = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationString:destinationString - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationString:destinationString + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginAndDestinationAreNotNil -{ - // given - CLLocation *originLocation = [self prepareFirstLocation]; - NSString *destinationString = [self prepareSecondString]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationString:destinationString - sensor:NO]; - - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originLocation, request.originLocation); - XCTAssertNil(request.originString); - XCTAssertEqual(destinationString, request.destinationString); - XCTAssertNil(request.destinationLocation); - XCTAssertFalse(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginAndDestinationAreNotNil { + // given + CLLocation *originLocation = [self prepareFirstLocation]; + NSString *destinationString = [self prepareSecondString]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationString:destinationString + sensor:NO]; + + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originLocation, request.originLocation); + XCTAssertNil(request.originString); + XCTAssertEqual(destinationString, request.destinationString); + XCTAssertNil(request.destinationLocation); + XCTAssertFalse(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } -- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginAndDestinationAreNotNilAndSensorIsTrue -{ - // given - CLLocation *originLocation = [self prepareFirstLocation]; - NSString *destinationString = [self prepareSecondString]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationString:destinationString - sensor:YES]; - - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originLocation, request.originLocation); - XCTAssertNil(request.originString); - XCTAssertEqual(destinationString, request.destinationString); - XCTAssertNil(request.destinationLocation); - XCTAssertTrue(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginLocationAndDestinationStringWhenOriginAndDestinationAreNotNilAndSensorIsTrue { + // given + CLLocation *originLocation = [self prepareFirstLocation]; + NSString *destinationString = [self prepareSecondString]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationString:destinationString + sensor:YES]; + + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originLocation, request.originLocation); + XCTAssertNil(request.originString); + XCTAssertEqual(destinationString, request.destinationString); + XCTAssertNil(request.destinationLocation); + XCTAssertTrue(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } #pragma mark - Test requestWithOriginString:andDestinationString:sensor: -- (void)testRequestWithOriginStringAndDestinationStringWhenOriginIsNil -{ - // given - NSString *originString = nil; - NSString *destinationString = [self prepareSecondString]; - + +- (void)testRequestWithOriginStringAndDestinationStringWhenOriginIsNil { + // given + NSString *originString = nil; + NSString *destinationString = [self prepareSecondString]; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString - andDestinationString:destinationString - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString + andDestinationString:destinationString + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginStringAndDestinationStringWhenDestinationIsNil -{ - // given - NSString *originString = [self prepareFirstString]; - NSString *destinationString = nil; - +- (void)testRequestWithOriginStringAndDestinationStringWhenDestinationIsNil { + // given + NSString *originString = [self prepareFirstString]; + NSString *destinationString = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString - andDestinationString:destinationString - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString + andDestinationString:destinationString + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginStringAndDestinationStringWhenOriginAndDestinationAreNil -{ - // given - NSString *originString = nil; - NSString *destinationString = nil; - +- (void)testRequestWithOriginStringAndDestinationStringWhenOriginAndDestinationAreNil { + // given + NSString *originString = nil; + NSString *destinationString = nil; + // then - XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString - andDestinationString:destinationString - sensor:NO], NSException, NSInvalidArgumentException); + XCTAssertThrowsSpecificNamed([OCDirectionsRequest requestWithOriginString:originString + andDestinationString:destinationString + sensor:NO], NSException, NSInvalidArgumentException); } -- (void)testRequestWithOriginStringAndDestinationStringWhenOriginAndDestinationAreNotNil -{ - // given - NSString *originString = [self prepareFirstString]; - NSString *destinationString = [self prepareSecondString]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString - andDestinationString:destinationString - sensor:NO]; - - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originString, request.originString); - XCTAssertNil(request.originLocation); - XCTAssertEqual(destinationString, request.destinationString); - XCTAssertNil(request.destinationLocation); - XCTAssertFalse(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginStringAndDestinationStringWhenOriginAndDestinationAreNotNil { + // given + NSString *originString = [self prepareFirstString]; + NSString *destinationString = [self prepareSecondString]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString + andDestinationString:destinationString + sensor:NO]; + + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originString, request.originString); + XCTAssertNil(request.originLocation); + XCTAssertEqual(destinationString, request.destinationString); + XCTAssertNil(request.destinationLocation); + XCTAssertFalse(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } -- (void)testRequestWithOriginStringAndDestinationStringWhenOriginAndDestinationAreNotNilAndSensorIsTrue -{ - // given - NSString *originString = [self prepareFirstString]; - NSString *destinationString = [self prepareSecondString]; - - // when - OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString - andDestinationString:destinationString - sensor:YES]; - - // then - XCTAssertNotNil(request); - XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); - XCTAssertEqual(originString, request.originString); - XCTAssertNil(request.originLocation); - XCTAssertEqual(destinationString, request.destinationString); - XCTAssertNil(request.destinationLocation); - XCTAssertTrue(request.sensor); - - [self verifyPropertiesWithDefaultValuesOfRequest:request]; +- (void)testRequestWithOriginStringAndDestinationStringWhenOriginAndDestinationAreNotNilAndSensorIsTrue { + // given + NSString *originString = [self prepareFirstString]; + NSString *destinationString = [self prepareSecondString]; + + // when + OCDirectionsRequest *request = [OCDirectionsRequest requestWithOriginString:originString + andDestinationString:destinationString + sensor:YES]; + + // then + XCTAssertNotNil(request); + XCTAssertTrue([request isMemberOfClass:[OCDirectionsRequest class]]); + XCTAssertEqual(originString, request.originString); + XCTAssertNil(request.originLocation); + XCTAssertEqual(destinationString, request.destinationString); + XCTAssertNil(request.destinationLocation); + XCTAssertTrue(request.sensor); + + [self verifyPropertiesWithDefaultValuesOfRequest:request]; } #pragma mark - isValid -- (void)testIsValidWhenParametersAreFine -{ - // given - NSString *originString = [self prepareFirstString]; - CLLocation *originLocation = [self prepareFirstLocation]; - NSString *destinationString = [self prepareSecondString]; - CLLocation *destinationLocation = [self prepareSecondLocation]; - - OCDirectionsRequest *requestLL = [OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationLocation:destinationLocation - sensor:YES]; - - OCDirectionsRequest *requestLS = [OCDirectionsRequest requestWithOriginLocation:originLocation - andDestinationString:destinationString - sensor:YES]; - - OCDirectionsRequest *requestSL = [OCDirectionsRequest requestWithOriginString:originString - andDestinationLocation:destinationLocation - sensor:YES]; - - OCDirectionsRequest *requestSS = [OCDirectionsRequest requestWithOriginString:originString - andDestinationString:destinationString - sensor:YES]; - - // when - BOOL requestLLIsValid = [requestLL isValid]; - BOOL requestLSIsValid = [requestLS isValid]; - BOOL requestSLIsValid = [requestSL isValid]; - BOOL requestSSIsValid = [requestSS isValid]; - - //then - XCTAssertTrue(requestLLIsValid); - XCTAssertTrue(requestLSIsValid); - XCTAssertTrue(requestSLIsValid); - XCTAssertTrue(requestSSIsValid); + +- (void)testIsValidWhenParametersAreFine { + // given + NSString *originString = [self prepareFirstString]; + CLLocation *originLocation = [self prepareFirstLocation]; + NSString *destinationString = [self prepareSecondString]; + CLLocation *destinationLocation = [self prepareSecondLocation]; + + OCDirectionsRequest *requestLL = [OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationLocation:destinationLocation + sensor:YES]; + + OCDirectionsRequest *requestLS = [OCDirectionsRequest requestWithOriginLocation:originLocation + andDestinationString:destinationString + sensor:YES]; + + OCDirectionsRequest *requestSL = [OCDirectionsRequest requestWithOriginString:originString + andDestinationLocation:destinationLocation + sensor:YES]; + + OCDirectionsRequest *requestSS = [OCDirectionsRequest requestWithOriginString:originString + andDestinationString:destinationString + sensor:YES]; + + // when + BOOL requestLLIsValid = [requestLL isValid]; + BOOL requestLSIsValid = [requestLS isValid]; + BOOL requestSLIsValid = [requestSL isValid]; + BOOL requestSSIsValid = [requestSS isValid]; + + //then + XCTAssertTrue(requestLLIsValid); + XCTAssertTrue(requestLSIsValid); + XCTAssertTrue(requestSLIsValid); + XCTAssertTrue(requestSSIsValid); } #pragma mark - Custom verifiers -- (void)verifyPropertiesWithDefaultValuesOfRequest:(OCDirectionsRequest *)request -{ - XCTAssertFalse(request.alternatives); - XCTAssertTrue(request.isValid); - XCTAssertEqual(OCDirectionsRequestTravelModeDriving, request.travelMode); - XCTAssertEqual(OCDirectionsRequestUnitDefault, request.unit); - XCTAssertNil(request.waypoints); - XCTAssertFalse(request.waypointsOptimise); + +- (void)verifyPropertiesWithDefaultValuesOfRequest:(OCDirectionsRequest *)request { + XCTAssertFalse(request.alternatives); + XCTAssertTrue(request.isValid); + XCTAssertEqual(OCDirectionsRequestTravelModeDriving, request.travelMode); + XCTAssertEqual(OCDirectionsRequestUnitDefault, request.unit); + XCTAssertNil(request.waypoints); + XCTAssertFalse(request.waypointsOptimise); } #pragma mark - Helpers -- (CLLocation *)prepareFirstLocation -{ - CLLocation *location = [[CLLocation alloc] initWithLatitude:10.0 longitude:20.0]; - return location; + +- (CLLocation *)prepareFirstLocation { + CLLocation *location = [[CLLocation alloc] initWithLatitude:10.0 longitude:20.0]; + return location; } -- (CLLocation *)prepareSecondLocation -{ - CLLocation *location = [[CLLocation alloc] initWithLatitude:30.0 longitude:40.0]; - return location; +- (CLLocation *)prepareSecondLocation { + CLLocation *location = [[CLLocation alloc] initWithLatitude:30.0 longitude:40.0]; + return location; } -- (NSString *)prepareFirstString -{ - NSString *string = @"London"; - return string; +- (NSString *)prepareFirstString { + NSString *string = @"London"; + return string; } -- (NSString *)prepareSecondString -{ - NSString *string = @"Reading"; - return string; +- (NSString *)prepareSecondString { + NSString *string = @"Reading"; + return string; } #pragma clang diagnostic pop From e6c0d6509d2a3ce0a916418cebabd0c03fc80a3b Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sun, 20 Mar 2016 10:52:19 +0000 Subject: [PATCH 02/15] Remove property attributes which are not needed anymore. --- .../Client/OCDirectionsAPIClient.h | 2 +- .../OCDirectionsRequestURLCreatorJSON.m | 4 ++-- .../Request/OCDirectionsRequest.h | 1 + .../Response/Attributes/OCDirectionsBounds.h | 6 +++--- .../Response/Attributes/OCDirectionsDistance.h | 4 ++-- .../Response/Attributes/OCDirectionsDuration.h | 4 ++-- .../Response/Attributes/OCDirectionsLeg.h | 14 +++++++------- .../Response/Attributes/OCDirectionsPolyline.h | 2 +- .../Response/Attributes/OCDirectionsRoute.h | 14 +++++++------- .../Response/Attributes/OCDirectionsStep.h | 14 +++++++------- .../Response/Attributes/OCDirectionsWaypoint.h | 8 ++++---- .../Response/OCDirectionsResponse.h | 6 +++--- 12 files changed, 40 insertions(+), 39 deletions(-) diff --git a/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.h b/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.h index 0e3a245..78f91c9 100644 --- a/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.h +++ b/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.h @@ -16,7 +16,7 @@ typedef void (^OCDirectionsRequestCallback)(OCDirectionsResponse *response, NSEr @interface OCDirectionsAPIClient : NSObject -@property(nonatomic, retain) id requestURLCreator; +@property(nonatomic) id requestURLCreator; - (instancetype)init; diff --git a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m index 45376dc..e973657 100644 --- a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m +++ b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m @@ -75,7 +75,7 @@ - (NSMutableString *)baseStringWithHttps:(BOOL)useHttps { return baseString; } -#pragma mark - Appenders +#pragma mark - - (void)appendOrigin:(OCDirectionsRequest *)request toString:(NSMutableString *)string { [string appendString:kOCGoogleDirectionsRequestAttributeOrigin]; @@ -222,7 +222,7 @@ - (void)appendAlternatives:(OCDirectionsRequest *)request toString:(NSMutableStr - (void)appendKey:(NSString *)key toString:(NSMutableString *)string { /** - API key is not requred. + API key is not required. */ if (key) { [string appendString:kOCGoogleDirectionsRequestAttributeKey]; diff --git a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h index ad8540d..94d26f8 100644 --- a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h +++ b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h @@ -31,6 +31,7 @@ @property(nonatomic, readonly) BOOL sensor; #pragma mark - Optional + @property(nonatomic) OCDirectionsRequestTravelMode travelMode; /** diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h index 25eccb0..ae5dce1 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h @@ -11,10 +11,10 @@ @interface OCDirectionsBounds : NSObject -@property(nonatomic, retain, readonly) NSDictionary *dictionary; +@property(nonatomic, readonly) NSDictionary *dictionary; -@property(nonatomic, assign, readonly) CLLocationCoordinate2D southwest; -@property(nonatomic, assign, readonly) CLLocationCoordinate2D northeast; +@property(nonatomic, readonly) CLLocationCoordinate2D southwest; +@property(nonatomic, readonly) CLLocationCoordinate2D northeast; + (instancetype)boundsFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h index 55cff17..251cddb 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h @@ -12,10 +12,10 @@ extern NSString *const kCGGoogleDirectionsResponseAttributeDistance; @interface OCDirectionsDistance : NSObject -@property(nonatomic, retain, readonly) NSDictionary *dictionary; +@property(nonatomic, readonly) NSDictionary *dictionary; @property(nonatomic, copy, readonly) NSString *text; -@property(nonatomic, copy, readonly) NSNumber *value; +@property(nonatomic, readonly) NSNumber *value; + (instancetype)distanceFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h index d689483..e21f35a 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h @@ -12,10 +12,10 @@ extern NSString *const kCGGoogleDirectionsResponseAttributeDuration; @interface OCDirectionsDuration : NSObject -@property(nonatomic, retain, readonly) NSDictionary *dictionary; +@property(nonatomic, readonly) NSDictionary *dictionary; @property(nonatomic, copy, readonly) NSString *text; -@property(nonatomic, copy, readonly) NSNumber *value; +@property(nonatomic, readonly) NSNumber *value; + (instancetype)durationFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h index 7d7a3b5..9583387 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h @@ -13,16 +13,16 @@ @interface OCDirectionsLeg : NSObject -@property(nonatomic, strong, readonly) NSDictionary *dictionary; +@property(nonatomic, readonly) NSDictionary *dictionary; -@property(nonatomic, strong, readonly) OCDirectionsDistance *distance; -@property(nonatomic, strong, readonly) OCDirectionsDuration *duration; +@property(nonatomic, readonly) OCDirectionsDistance *distance; +@property(nonatomic, readonly) OCDirectionsDuration *duration; @property(nonatomic, copy, readonly) NSString *endAddress; -@property(nonatomic, assign, readonly) CLLocationCoordinate2D endLocation; +@property(nonatomic, readonly) CLLocationCoordinate2D endLocation; @property(nonatomic, copy, readonly) NSString *startAddress; -@property(nonatomic, assign, readonly) CLLocationCoordinate2D startLocation; -@property(nonatomic, strong, readonly) NSArray *steps; -@property(nonatomic, strong, readonly) NSArray *viaWaypoint; +@property(nonatomic, readonly) CLLocationCoordinate2D startLocation; +@property(nonatomic, readonly) NSArray *steps; +@property(nonatomic, readonly) NSArray *viaWaypoint; + (instancetype)legFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h index 2d16c13..e93d340 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h @@ -10,7 +10,7 @@ @interface OCDirectionsPolyline : NSObject -@property(nonatomic, retain, readonly) NSDictionary *dictionary; +@property(nonatomic, readonly) NSDictionary *dictionary; @property(nonatomic, copy, readonly) NSString *points; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h index a95d794..cb93e5d 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h @@ -12,12 +12,12 @@ @interface OCDirectionsRoute : NSObject -@property(nonatomic, retain, readonly) NSDictionary *dictionary; +@property(nonatomic, readonly) NSDictionary *dictionary; /** legs[] contains an array which contains information about a leg of the route, between two locations within the given route. A separate leg will be present for each waypoint or destination specified. (A route with no waypoints will contain exactly one leg within the legs array.) Each leg consists of a series of steps. (See Directions Legs below.) */ -@property(nonatomic, strong, readonly) NSArray *legs; +@property(nonatomic, readonly) NSArray *legs; /** copyrights contains the copyrights text to be displayed for this route. You must handle and display this information yourself. @@ -27,27 +27,27 @@ /* warnings[] contains an array of warnings to be displayed when showing these directions. You must handle and display these warnings yourself. */ -@property(nonatomic, strong, readonly) NSArray *warnings; +@property(nonatomic, readonly) NSArray *warnings; /** waypoint_order contains an array indicating the order of any waypoints in the calculated route. This waypoints may be reordered if the request was passed optimize:true within its waypoints parameter. */ -@property(nonatomic, strong, readonly) NSArray *waypointOrder; +@property(nonatomic, readonly) NSArray *waypointOrder; /** overview_polyline contains an object holding an array of encoded points that represent an approximate (smoothed) path of the resulting directions. */ -@property(nonatomic, strong, readonly) OCDirectionsPolyline *overviewPolyline; +@property(nonatomic, readonly) OCDirectionsPolyline *overviewPolyline; /** bounds contains the viewport bounding box of the overview_polyline. */ -@property(nonatomic, strong, readonly) OCDirectionsBounds *bounds; +@property(nonatomic, readonly) OCDirectionsBounds *bounds; /** summary contains a short textual description for the route, suitable for naming and disambiguating the route from alternatives. */ -@property(nonatomic, strong, readonly) NSString *summary; +@property(nonatomic, copy, readonly) NSString *summary; + (instancetype)routeFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h index 6fe4771..46000f4 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h @@ -18,16 +18,16 @@ extern NSString *const kCGGoogleDirectionsResponseAttributeStartLocation; @interface OCDirectionsStep : NSObject -@property(nonatomic, strong, readonly) NSDictionary *dictionary; +@property(nonatomic, readonly) NSDictionary *dictionary; -@property(nonatomic, strong, readonly) OCDirectionsDistance *distance; -@property(nonatomic, strong, readonly) OCDirectionsDuration *duration; -@property(nonatomic, assign, readonly) CLLocationCoordinate2D endLocation; +@property(nonatomic, readonly) OCDirectionsDistance *distance; +@property(nonatomic, readonly) OCDirectionsDuration *duration; +@property(nonatomic, readonly) CLLocationCoordinate2D endLocation; @property(nonatomic, copy, readonly) NSString *htmlInstructions; @property(nonatomic, copy, readonly) NSString *maneuver; -@property(nonatomic, strong, readonly) OCDirectionsPolyline *polyline; -@property(nonatomic, assign, readonly) CLLocationCoordinate2D startLocation; -@property(nonatomic, assign, readonly) OCDirectionsRequestTravelMode travelMode; +@property(nonatomic, readonly) OCDirectionsPolyline *polyline; +@property(nonatomic, readonly) CLLocationCoordinate2D startLocation; +@property(nonatomic, readonly) OCDirectionsRequestTravelMode travelMode; + (instancetype)stepFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h index 140fc7d..c34ee55 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h @@ -11,22 +11,22 @@ @interface OCDirectionsWaypoint : NSObject -@property(nonatomic, retain, readonly) NSDictionary *dictionary; +@property(nonatomic, readonly) NSDictionary *dictionary; /** Not documented yet. */ -@property(nonatomic, assign, readonly) CLLocationCoordinate2D location; +@property(nonatomic, readonly) CLLocationCoordinate2D location; /** Not documented yet. */ -@property(nonatomic, retain, readonly) NSNumber *stepIndex; +@property(nonatomic, readonly) NSNumber *stepIndex; /** Not documented yet. */ -@property(nonatomic, retain, readonly) NSNumber *stepInterpolation; +@property(nonatomic, readonly) NSNumber *stepInterpolation; + (instancetype)waypointFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h index d8fef6c..35a0f97 100644 --- a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h +++ b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h @@ -23,17 +23,17 @@ typedef NS_ENUM(NSUInteger, OCDirectionsResponseStatus) { @interface OCDirectionsResponse : NSObject -@property(nonatomic, strong, readonly) NSDictionary *dictionary; +@property(nonatomic, readonly) NSDictionary *dictionary; /** "status" contains metadata on the request. See Status Codes above. */ -@property(nonatomic, assign, readonly) OCDirectionsResponseStatus status; +@property(nonatomic, readonly) OCDirectionsResponseStatus status; /** "routes" contains an array of routes from the origin to the destination. */ -@property(nonatomic, strong, readonly) NSArray *routes; +@property(nonatomic, readonly) NSArray *routes; /** "errorMessage" (optional) field contains more detailed information about the reasons behind the given status code. From 5396be3319b0ba6ab6eaed75387647dde5916718 Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sun, 20 Mar 2016 10:58:30 +0000 Subject: [PATCH 03/15] Format properties. --- .../Client/OCDirectionsAPIClient.h | 2 +- .../Client/OCDirectionsAPIClient.m | 4 +-- .../Request/OCDirectionsRequest.h | 28 +++++++++---------- .../Request/OCDirectionsRequest.m | 12 ++++---- .../Response/Attributes/OCDirectionsBounds.h | 6 ++-- .../Attributes/OCDirectionsDistance.h | 6 ++-- .../Attributes/OCDirectionsDuration.h | 6 ++-- .../Response/Attributes/OCDirectionsLeg.h | 18 ++++++------ .../Attributes/OCDirectionsPolyline.h | 4 +-- .../Response/Attributes/OCDirectionsRoute.h | 16 +++++------ .../Response/Attributes/OCDirectionsStep.h | 18 ++++++------ .../Attributes/OCDirectionsWaypoint.h | 8 +++--- .../Response/OCDirectionsResponse.h | 8 +++--- .../OCDirectionsRequestURLCreatorJSONTests.m | 2 +- 14 files changed, 69 insertions(+), 69 deletions(-) diff --git a/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.h b/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.h index 78f91c9..0a98659 100644 --- a/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.h +++ b/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.h @@ -16,7 +16,7 @@ typedef void (^OCDirectionsRequestCallback)(OCDirectionsResponse *response, NSEr @interface OCDirectionsAPIClient : NSObject -@property(nonatomic) id requestURLCreator; +@property (nonatomic) id requestURLCreator; - (instancetype)init; diff --git a/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m b/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m index 18f2189..0490fff 100644 --- a/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m +++ b/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m @@ -10,8 +10,8 @@ @interface OCDirectionsAPIClient () -@property(nonatomic, copy) NSString *key; -@property(nonatomic) BOOL useHttps; +@property (nonatomic, copy) NSString *key; +@property (nonatomic) BOOL useHttps; @end diff --git a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h index 94d26f8..48e47f9 100644 --- a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h +++ b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h @@ -16,68 +16,68 @@ /** Origin - The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a string, the Directions service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values. */ -@property(nonatomic, readonly) CLLocation *originLocation; // CLLocation or NSString -@property(nonatomic, copy, readonly) NSString *originString; +@property (nonatomic, readonly) CLLocation *originLocation; // CLLocation or NSString +@property (nonatomic, copy, readonly) NSString *originString; /** Destination - The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a string, the Directions service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values. */ -@property(nonatomic, readonly) CLLocation *destinationLocation; // CLLocation or NSString -@property(nonatomic, copy, readonly) NSString *destinationString; +@property (nonatomic, readonly) CLLocation *destinationLocation; // CLLocation or NSString +@property (nonatomic, copy, readonly) NSString *destinationString; /* Indicates whether or not the directions request comes from a device with a location sensor. This value must be either true or false. */ -@property(nonatomic, readonly) BOOL sensor; +@property (nonatomic, readonly) BOOL sensor; #pragma mark - Optional -@property(nonatomic) OCDirectionsRequestTravelMode travelMode; +@property (nonatomic) OCDirectionsRequestTravelMode travelMode; /** When calculating routes using the Directions API, you may also specify waypoints for driving, walking or bicycling directions. Waypoints are not available for transit directions. Waypoints allow you to calculate routes through additional locations, in which case the returned route passes through the given waypoints. Formally it is an array of NSStrings and CLLocations. */ -@property(nonatomic) NSArray *waypoints; +@property (nonatomic) NSArray *waypoints; /** Optimizes the provided route by rearranging the waypoints in a more efficient order. (This optimization is an application of the Travelling Salesman Problem.) */ -@property(nonatomic) BOOL waypointsOptimise; +@property (nonatomic) BOOL waypointsOptimise; /** Directions may be calculated that adhere to certain restrictions. Use an array of DirectionsRequestRestriction types ie. @[DirectionsRequestAvoidTollsRestriction, DirectionsRequestAviodFerriesRestriction] */ -@property(nonatomic) NSArray *restrictions; +@property (nonatomic) NSArray *restrictions; /** Directions results contain text within distance fields that may be displayed to the user to indicate the distance of a particular "step" of the route. By default, this text uses the unit system of the origin's country or region. */ -@property(nonatomic) OCDirectionsRequestUnit unit; +@property (nonatomic) OCDirectionsRequestUnit unit; /** You can also set the Directions service to return results biased to a particular region by use of the region parameter. This parameter takes a ccTLD (country code top-level domain) argument specifying the region bias. Most ccTLD codes are identical to ISO 3166-1 codes, with some notable exceptions. For example, the United Kingdom's ccTLD is "uk" (.co.uk) while its ISO 3166-1 code is "gb" (technically for the entity of "The United Kingdom of Great Britain and Northern Ireland"). You may utilize any domain in which the main Google Maps application has launched driving directions. */ -@property(nonatomic, copy) NSString *region; +@property (nonatomic, copy) NSString *region; /** You can also set the Directions service to return results is specific language. If language is not supplied, the service will attempt to use the native language of the domain from which the request is sent. */ -@property(nonatomic, copy) NSString *language; +@property (nonatomic, copy) NSString *language; /** Directions service may return several routes if you pass alternatives. */ -@property(nonatomic) BOOL alternatives; +@property (nonatomic) BOOL alternatives; /** Indicates whether sensor flag has been used or not. */ -@property(nonatomic, getter=isSensorFlagUsed, readonly) BOOL sensorFlagUsed; +@property (nonatomic, getter=isSensorFlagUsed, readonly) BOOL sensorFlagUsed; @end diff --git a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m index a974e87..ec43e2d 100644 --- a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m +++ b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m @@ -11,14 +11,14 @@ @interface OCDirectionsRequest () -@property(nonatomic) CLLocation *originLocation; -@property(nonatomic, copy) NSString *originString; +@property (nonatomic) CLLocation *originLocation; +@property (nonatomic, copy) NSString *originString; -@property(nonatomic) CLLocation *destinationLocation; -@property(nonatomic, copy) NSString *destinationString; +@property (nonatomic) CLLocation *destinationLocation; +@property (nonatomic, copy) NSString *destinationString; -@property(nonatomic) BOOL sensor; -@property(nonatomic, getter=isSensorFlagUsed) BOOL sensorFlagUsed; +@property (nonatomic) BOOL sensor; +@property (nonatomic, getter=isSensorFlagUsed) BOOL sensorFlagUsed; @end diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h index ae5dce1..d157c68 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsBounds.h @@ -11,10 +11,10 @@ @interface OCDirectionsBounds : NSObject -@property(nonatomic, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; -@property(nonatomic, readonly) CLLocationCoordinate2D southwest; -@property(nonatomic, readonly) CLLocationCoordinate2D northeast; +@property (nonatomic, readonly) CLLocationCoordinate2D southwest; +@property (nonatomic, readonly) CLLocationCoordinate2D northeast; + (instancetype)boundsFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h index 251cddb..c38a195 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDistance.h @@ -12,10 +12,10 @@ extern NSString *const kCGGoogleDirectionsResponseAttributeDistance; @interface OCDirectionsDistance : NSObject -@property(nonatomic, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; -@property(nonatomic, copy, readonly) NSString *text; -@property(nonatomic, readonly) NSNumber *value; +@property (nonatomic, copy, readonly) NSString *text; +@property (nonatomic, readonly) NSNumber *value; + (instancetype)distanceFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h index e21f35a..7ead45f 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h @@ -12,10 +12,10 @@ extern NSString *const kCGGoogleDirectionsResponseAttributeDuration; @interface OCDirectionsDuration : NSObject -@property(nonatomic, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; -@property(nonatomic, copy, readonly) NSString *text; -@property(nonatomic, readonly) NSNumber *value; +@property (nonatomic, copy, readonly) NSString *text; +@property (nonatomic, readonly) NSNumber *value; + (instancetype)durationFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h index 9583387..8e6eba3 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h @@ -13,16 +13,16 @@ @interface OCDirectionsLeg : NSObject -@property(nonatomic, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; -@property(nonatomic, readonly) OCDirectionsDistance *distance; -@property(nonatomic, readonly) OCDirectionsDuration *duration; -@property(nonatomic, copy, readonly) NSString *endAddress; -@property(nonatomic, readonly) CLLocationCoordinate2D endLocation; -@property(nonatomic, copy, readonly) NSString *startAddress; -@property(nonatomic, readonly) CLLocationCoordinate2D startLocation; -@property(nonatomic, readonly) NSArray *steps; -@property(nonatomic, readonly) NSArray *viaWaypoint; +@property (nonatomic, readonly) OCDirectionsDistance *distance; +@property (nonatomic, readonly) OCDirectionsDuration *duration; +@property (nonatomic, copy, readonly) NSString *endAddress; +@property (nonatomic, readonly) CLLocationCoordinate2D endLocation; +@property (nonatomic, copy, readonly) NSString *startAddress; +@property (nonatomic, readonly) CLLocationCoordinate2D startLocation; +@property (nonatomic, readonly) NSArray *steps; +@property (nonatomic, readonly) NSArray *viaWaypoint; + (instancetype)legFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h index e93d340..5a36c80 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsPolyline.h @@ -10,9 +10,9 @@ @interface OCDirectionsPolyline : NSObject -@property(nonatomic, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; -@property(nonatomic, copy, readonly) NSString *points; +@property (nonatomic, copy, readonly) NSString *points; + (instancetype)polylineFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h index cb93e5d..ed14d0b 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h @@ -12,42 +12,42 @@ @interface OCDirectionsRoute : NSObject -@property(nonatomic, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; /** legs[] contains an array which contains information about a leg of the route, between two locations within the given route. A separate leg will be present for each waypoint or destination specified. (A route with no waypoints will contain exactly one leg within the legs array.) Each leg consists of a series of steps. (See Directions Legs below.) */ -@property(nonatomic, readonly) NSArray *legs; +@property (nonatomic, readonly) NSArray *legs; /** copyrights contains the copyrights text to be displayed for this route. You must handle and display this information yourself. */ -@property(nonatomic, copy, readonly) NSString *copyrights; +@property (nonatomic, copy, readonly) NSString *copyrights; /* warnings[] contains an array of warnings to be displayed when showing these directions. You must handle and display these warnings yourself. */ -@property(nonatomic, readonly) NSArray *warnings; +@property (nonatomic, readonly) NSArray *warnings; /** waypoint_order contains an array indicating the order of any waypoints in the calculated route. This waypoints may be reordered if the request was passed optimize:true within its waypoints parameter. */ -@property(nonatomic, readonly) NSArray *waypointOrder; +@property (nonatomic, readonly) NSArray *waypointOrder; /** overview_polyline contains an object holding an array of encoded points that represent an approximate (smoothed) path of the resulting directions. */ -@property(nonatomic, readonly) OCDirectionsPolyline *overviewPolyline; +@property (nonatomic, readonly) OCDirectionsPolyline *overviewPolyline; /** bounds contains the viewport bounding box of the overview_polyline. */ -@property(nonatomic, readonly) OCDirectionsBounds *bounds; +@property (nonatomic, readonly) OCDirectionsBounds *bounds; /** summary contains a short textual description for the route, suitable for naming and disambiguating the route from alternatives. */ -@property(nonatomic, copy, readonly) NSString *summary; +@property (nonatomic, copy, readonly) NSString *summary; + (instancetype)routeFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h index 46000f4..c7cd730 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsStep.h @@ -18,16 +18,16 @@ extern NSString *const kCGGoogleDirectionsResponseAttributeStartLocation; @interface OCDirectionsStep : NSObject -@property(nonatomic, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; -@property(nonatomic, readonly) OCDirectionsDistance *distance; -@property(nonatomic, readonly) OCDirectionsDuration *duration; -@property(nonatomic, readonly) CLLocationCoordinate2D endLocation; -@property(nonatomic, copy, readonly) NSString *htmlInstructions; -@property(nonatomic, copy, readonly) NSString *maneuver; -@property(nonatomic, readonly) OCDirectionsPolyline *polyline; -@property(nonatomic, readonly) CLLocationCoordinate2D startLocation; -@property(nonatomic, readonly) OCDirectionsRequestTravelMode travelMode; +@property (nonatomic, readonly) OCDirectionsDistance *distance; +@property (nonatomic, readonly) OCDirectionsDuration *duration; +@property (nonatomic, readonly) CLLocationCoordinate2D endLocation; +@property (nonatomic, copy, readonly) NSString *htmlInstructions; +@property (nonatomic, copy, readonly) NSString *maneuver; +@property (nonatomic, readonly) OCDirectionsPolyline *polyline; +@property (nonatomic, readonly) CLLocationCoordinate2D startLocation; +@property (nonatomic, readonly) OCDirectionsRequestTravelMode travelMode; + (instancetype)stepFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h index c34ee55..fd0fa51 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsWaypoint.h @@ -11,22 +11,22 @@ @interface OCDirectionsWaypoint : NSObject -@property(nonatomic, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; /** Not documented yet. */ -@property(nonatomic, readonly) CLLocationCoordinate2D location; +@property (nonatomic, readonly) CLLocationCoordinate2D location; /** Not documented yet. */ -@property(nonatomic, readonly) NSNumber *stepIndex; +@property (nonatomic, readonly) NSNumber *stepIndex; /** Not documented yet. */ -@property(nonatomic, readonly) NSNumber *stepInterpolation; +@property (nonatomic, readonly) NSNumber *stepInterpolation; + (instancetype)waypointFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h index 35a0f97..1981905 100644 --- a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h +++ b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.h @@ -23,22 +23,22 @@ typedef NS_ENUM(NSUInteger, OCDirectionsResponseStatus) { @interface OCDirectionsResponse : NSObject -@property(nonatomic, readonly) NSDictionary *dictionary; +@property (nonatomic, readonly) NSDictionary *dictionary; /** "status" contains metadata on the request. See Status Codes above. */ -@property(nonatomic, readonly) OCDirectionsResponseStatus status; +@property (nonatomic, readonly) OCDirectionsResponseStatus status; /** "routes" contains an array of routes from the origin to the destination. */ -@property(nonatomic, readonly) NSArray *routes; +@property (nonatomic, readonly) NSArray *routes; /** "errorMessage" (optional) field contains more detailed information about the reasons behind the given status code. */ -@property(nonatomic, copy, readonly) NSString *errorMessage; +@property (nonatomic, copy, readonly) NSString *errorMessage; + (instancetype)responseFromDictionary:(NSDictionary *)dictionary; diff --git a/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m b/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m index 1d19e1e..ae3c2d0 100644 --- a/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m +++ b/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m @@ -15,7 +15,7 @@ @interface OCDirectionsRequestURLCreatorJSONTests : XCTestCase -@property(nonatomic, strong) OCDirectionsRequestURLCreatorJSON *urlCreator; +@property (nonatomic, strong) OCDirectionsRequestURLCreatorJSON *urlCreator; @end From 847289decc7dc681a9400aa322fdb56726d96116 Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sun, 20 Mar 2016 13:41:25 +0000 Subject: [PATCH 04/15] Add arrival_time and departure_time parameters to request object. Fix missing units parameter. --- .../OCDirectionsRequestURLCreatorJSON.m | 73 ++++++++++++++----- .../Request/OCDirectionsRequest.h | 19 +++++ .../Request/OCDirectionsRequest.m | 4 + .../OCDirectionsRequestURLCreatorJSONTests.m | 56 ++++++++++++++ 4 files changed, 134 insertions(+), 18 deletions(-) diff --git a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m index e973657..4536a79 100644 --- a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m +++ b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m @@ -22,12 +22,16 @@ static NSString *const kOCGoogleDirectionsRequestAttributeRestrictions = @"&avoid="; static NSString *const kOCGoogleDirectionsRequestAttributeUnits = @"&units="; static NSString *const kOCGoogleDirectionsRequestAttributeRegion = @"®ion="; +static NSString *const kOCGoogleDirectionsRequestAttributeArrivalTime = @"&arrival_time="; +static NSString *const kOCGoogleDirectionsRequestAttributeDepartureTime = @"&departure_time="; static NSString *const kOCGoogleDirectionsRequestAttributeLanguage = @"&language="; static NSString *const kOCGoogleDirectionsRequestAttributeKey = @"&key="; static NSString *const kOCGoogleDirectionsRequestAttributeAlternatives = @"&alternatives="; static NSString *const kOCGoogleDirectionsRequestAttributeSeparator = @"|"; +static NSString *const kOCGoogleDirectionsRequestAttributeValueDepartureTimeNow = @"now"; + @implementation OCDirectionsRequestURLCreatorJSON #pragma mark - Public methods @@ -43,13 +47,15 @@ - (NSString *)stringFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)us [self appendTravelMode:request toString:string]; [self appendWaypoints:request toString:string]; [self appendRestrictions:request toString:string]; - [self appendRegion:request toString:string]; [self appendLanguage:request toString:string]; + [self appendUnit:request toString:string]; + [self appendRegion:request toString:string]; + [self appendArrivalTime:request toString:string]; + [self appendDepartureTime:request toString:string]; [self appendAlternatives:request toString:string]; [self appendKey:key toString:string]; - NSString *stringEncoded = [string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - return stringEncoded; + return string; } - (NSURL *)urlFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)useHttps andKey:(NSString *)key { @@ -82,9 +88,9 @@ - (void)appendOrigin:(OCDirectionsRequest *)request toString:(NSMutableString *) if (request.originLocation) { NSString *originString = [self stringFormCLLocation:request.originLocation]; - [string appendString:originString]; + [string appendString:[self encodeParameter:originString]]; } else { - [string appendString:request.originString]; + [string appendString:[self encodeParameter:request.originString]]; } } @@ -93,9 +99,9 @@ - (void)appendDestination:(OCDirectionsRequest *)request toString:(NSMutableStri if (request.destinationLocation) { NSString *destinationString = [self stringFormCLLocation:request.destinationLocation]; - [string appendString:destinationString]; + [string appendString:[self encodeParameter:destinationString]]; } else { - [string appendString:request.destinationString]; + [string appendString:[self encodeParameter:request.destinationString]]; } } @@ -110,7 +116,7 @@ - (void)appendSensor:(OCDirectionsRequest *)request toString:(NSMutableString *) [string appendString:kOCGoogleDirectionsRequestAttributeSensor]; NSString *sensorString = [self stringFromBOOL:request.sensor]; - [string appendString:sensorString]; + [string appendString:[self encodeParameter:sensorString]]; } - (void)appendTravelMode:(OCDirectionsRequest *)request toString:(NSMutableString *)string { @@ -121,7 +127,7 @@ - (void)appendTravelMode:(OCDirectionsRequest *)request toString:(NSMutableStrin [string appendString:kOCGoogleDirectionsRequestAttributeTravelMode]; NSString *travelModeString = [OCDirectionsCommonTypes stringFormTravelMode:request.travelMode]; - [string appendString:travelModeString]; + [string appendString:[self encodeParameter:travelModeString]]; } - (void)appendWaypoints:(OCDirectionsRequest *)request toString:(NSMutableString *)string { @@ -145,11 +151,11 @@ - (void)appendWaypoints:(OCDirectionsRequest *)request toString:(NSMutableString for (id waypoint in request.waypoints) { if ([waypoint isKindOfClass:[NSString class]]) { NSString *waypointString = (NSString *) waypoint; - [string appendString:waypointString]; + [string appendString:[self encodeParameter:waypointString]]; } else if ([waypoint isKindOfClass:[CLLocation class]]) { CLLocation *waypointLocation = (CLLocation *) waypoint; NSString *waypointString = [self stringFormCLLocation:waypointLocation]; - [string appendString:waypointString]; + [string appendString:[self encodeParameter:waypointString]]; } if (++iter < count) { @@ -172,7 +178,7 @@ - (void)appendRestrictions:(OCDirectionsRequest *)request toString:(NSMutableStr NSUInteger count = [request.waypoints count]; NSUInteger iter = 0; for (NSString *restriction in request.restrictions) { - [string appendString:restriction]; + [string appendString:[self encodeParameter:restriction]]; if (++iter < count) { [string appendString:kOCGoogleDirectionsRequestAttributeSeparator]; @@ -188,7 +194,7 @@ - (void)appendUnit:(OCDirectionsRequest *)request toString:(NSMutableString *)st [string appendString:kOCGoogleDirectionsRequestAttributeUnits]; NSString *unitString = [self stringFormUnit:request.unit]; - [string appendString:unitString]; + [string appendString:[self encodeParameter:unitString]]; } - (void)appendRegion:(OCDirectionsRequest *)request toString:(NSMutableString *)string { @@ -197,7 +203,31 @@ - (void)appendRegion:(OCDirectionsRequest *)request toString:(NSMutableString *) } [string appendString:kOCGoogleDirectionsRequestAttributeRegion]; - [string appendString:request.region]; + [string appendString:[self encodeParameter:request.region]]; +} + +- (void)appendArrivalTime:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + if (request.arrivalTime == nil) { + return; + } + + NSString *arrivalTimeValue = @(request.arrivalTime.timeIntervalSince1970).stringValue; + + [string appendString:kOCGoogleDirectionsRequestAttributeArrivalTime]; + [string appendString:[self encodeParameter:arrivalTimeValue]]; +} + +- (void)appendDepartureTime:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + if (request.departureTime == nil) { + return; + } + + NSString *departureTimeValue = [request.departureTime isEqualToDate:kOCDirectionsRequestDepartureTimeNow] + ? kOCGoogleDirectionsRequestAttributeValueDepartureTimeNow + : @(request.departureTime.timeIntervalSince1970).stringValue; + + [string appendString:kOCGoogleDirectionsRequestAttributeDepartureTime]; + [string appendString:[self encodeParameter:departureTimeValue]]; } - (void)appendLanguage:(OCDirectionsRequest *)request toString:(NSMutableString *)string { @@ -206,18 +236,18 @@ - (void)appendLanguage:(OCDirectionsRequest *)request toString:(NSMutableString } [string appendString:kOCGoogleDirectionsRequestAttributeLanguage]; - [string appendString:request.language]; + [string appendString:[self encodeParameter:request.language]]; } - (void)appendAlternatives:(OCDirectionsRequest *)request toString:(NSMutableString *)string { - if (request.alternatives == NO) { + if (!request.alternatives) { return; } [string appendString:kOCGoogleDirectionsRequestAttributeAlternatives]; NSString *alternativesString = [self stringFromBOOL:request.alternatives]; - [string appendString:alternativesString]; + [string appendString:[self encodeParameter:alternativesString]]; } - (void)appendKey:(NSString *)key toString:(NSMutableString *)string { @@ -226,7 +256,7 @@ - (void)appendKey:(NSString *)key toString:(NSMutableString *)string { */ if (key) { [string appendString:kOCGoogleDirectionsRequestAttributeKey]; - [string appendString:key]; + [string appendString:[self encodeParameter:key]]; } } @@ -252,6 +282,13 @@ - (NSString *)stringFormUnit:(OCDirectionsRequestUnit)unit { case OCDirectionsRequestUnitMetric: return @"metric"; } + return @""; +} + +- (NSString *)encodeParameter:(NSString *)parameter { + NSCharacterSet *set = [NSCharacterSet URLHostAllowedCharacterSet]; + NSString *encodedParameter = [parameter stringByAddingPercentEncodingWithAllowedCharacters:set]; + return encodedParameter; } @end diff --git a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h index 48e47f9..95f893b 100644 --- a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h +++ b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h @@ -10,6 +10,8 @@ #import #import "OCDirectionsCommonTypes.h" +#define kOCDirectionsRequestDepartureTimeNow [OCDirectionsRequest departureTimeNow] + @interface OCDirectionsRequest : NSObject #pragma mark - Required @@ -63,6 +65,21 @@ */ @property (nonatomic, copy) NSString *region; +/** + * Specifies the desired time of arrival for transit directions. + * You can specify either departure_time or arrival_time, but not both. + */ +@property (nonatomic) NSDate *arrivalTime; + +/** + * Specifies the desired time of departure. According to the doc you can specify a value of now, + * which sets the departure time to the current time (correct to the nearest second). However due to + * client/server time differences [NSDate new] might work incorrectly, please use kOCDirectionsRequestDepartureTimeNow + * for that kind of requests. + */ +@property (nonatomic) NSDate *departureTime; + + /** You can also set the Directions service to return results is specific language. If language is not supplied, the service will attempt to use the native language of the domain from which the request is sent. @@ -113,4 +130,6 @@ - (BOOL)isValid; ++ (NSDate *)departureTimeNow; + @end \ No newline at end of file diff --git a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m index ec43e2d..bcda606 100644 --- a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m +++ b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.m @@ -236,4 +236,8 @@ - (BOOL)isValid { return YES; } ++ (NSDate *)departureTimeNow { + return [NSDate dateWithTimeIntervalSince1970:0]; +} + @end diff --git a/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m b/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m index ae3c2d0..1806675 100644 --- a/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m +++ b/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m @@ -233,6 +233,62 @@ - (void)testStringFromRequestWhenTravelModeIsTransit { XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&mode=transit&key=0123456789abcdef", response); } +- (void)testStringWhenUnitsIsSet { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.unit = OCDirectionsRequestUnitMetric; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&units=metric&key=0123456789abcdef", response); +} + +- (void)testStringWhenArrivalTimeIsSet { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.arrivalTime = [NSDate dateWithTimeIntervalSince1970:2524668300000]; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&arrival_time=2524668300000&key=0123456789abcdef", response); +} + +- (void)testStringWhenDepartureTimeIsSet { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.departureTime = [NSDate dateWithTimeIntervalSince1970:2524668300000]; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&departure_time=2524668300000&key=0123456789abcdef", response); +} + +- (void)testStringWhenDepartureTimeIsNow { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.departureTime = kOCDirectionsRequestDepartureTimeNow; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&departure_time=now&key=0123456789abcdef", response); +} + #pragma mark - Helpers - (NSString *)prepareTestKey { From 77316a55e0928364e11e7baeafec75cbcbe0744f Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sun, 20 Mar 2016 15:13:25 +0000 Subject: [PATCH 05/15] Add transit_mode parameter to request. --- .../project.pbxproj | 2 + .../OCDirectionsRequestURLCreatorJSON.m | 41 ++++++++++++++ .../Common/OCDirectionsRequestTransitMode.h | 40 +++++++++++++ .../Request/OCDirectionsRequest.h | 49 ++++++++++------ .../OCDirectionsRequestURLCreatorJSONTests.m | 56 +++++++++++++++++++ 5 files changed, 171 insertions(+), 17 deletions(-) create mode 100644 Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h diff --git a/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj b/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj index d92ca7e..185a9c2 100644 --- a/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj +++ b/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj @@ -116,6 +116,7 @@ 27C6ECC318C6608E0035B80F /* OCGoogleDirectionsAPI-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "OCGoogleDirectionsAPI-Info.plist"; sourceTree = ""; }; 27C6ECCB18C67A910035B80F /* libOCGoogleDirectionsAPI.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libOCGoogleDirectionsAPI.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27C6ECCC18C67A910035B80F /* OCGoogleDirectionsAPITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OCGoogleDirectionsAPITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 524E8AD319197A088907F852 /* OCDirectionsRequestTransitMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsRequestTransitMode.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -292,6 +293,7 @@ 27C6E91218C65A580035B80F /* OCDirectionsRequestTravelMode.h */, 27C6E91318C65A580035B80F /* OCDirectionsRequestUnit.h */, 27C6E91418C65A580035B80F /* OCDirectionsResponseVehicleType.h */, + 524E8AD319197A088907F852 /* OCDirectionsRequestTransitMode.h */, ); path = Common; sourceTree = ""; diff --git a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m index 4536a79..87066fa 100644 --- a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m +++ b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m @@ -27,6 +27,7 @@ static NSString *const kOCGoogleDirectionsRequestAttributeLanguage = @"&language="; static NSString *const kOCGoogleDirectionsRequestAttributeKey = @"&key="; static NSString *const kOCGoogleDirectionsRequestAttributeAlternatives = @"&alternatives="; +static NSString *const kOCGoogleDirectionsRequestAttributeTransitMode = @"&transit_mode="; static NSString *const kOCGoogleDirectionsRequestAttributeSeparator = @"|"; @@ -53,6 +54,7 @@ - (NSString *)stringFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)us [self appendArrivalTime:request toString:string]; [self appendDepartureTime:request toString:string]; [self appendAlternatives:request toString:string]; + [self appendTransitMode:request toString:string]; [self appendKey:key toString:string]; return string; @@ -250,6 +252,31 @@ - (void)appendAlternatives:(OCDirectionsRequest *)request toString:(NSMutableStr [string appendString:[self encodeParameter:alternativesString]]; } +- (void)appendTransitMode:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + if (request.transitMode == OCDirectionsRequestTransitModeNotSpecified) { + return; + } + + NSMutableString *transitModeValue = [NSMutableString string]; + for (OCDirectionsRequestTransitMode transitMode = OCDirectionsRequestTransitModeBus; + transitMode < (OCDirectionsRequestTransitModeRail << 1); + transitMode <<= 1) { + + if ((request.transitMode & transitMode) == 0) { + continue; + } + + if (transitModeValue.length > 0) { + [transitModeValue appendString:kOCGoogleDirectionsRequestAttributeSeparator]; + } + + [transitModeValue appendString:[self transitModeDictionary][@(transitMode)]]; + } + + [string appendString:kOCGoogleDirectionsRequestAttributeTransitMode]; + [string appendString:[self encodeParameter:transitModeValue]]; +} + - (void)appendKey:(NSString *)key toString:(NSMutableString *)string { /** API key is not required. @@ -285,6 +312,20 @@ - (NSString *)stringFormUnit:(OCDirectionsRequestUnit)unit { return @""; } +- (NSDictionary *)transitModeDictionary { + static NSDictionary *transitModeDictionary; + if (transitModeDictionary == nil) { + transitModeDictionary = @{ + @(OCDirectionsRequestTransitModeBus) : @"bus", + @(OCDirectionsRequestTransitModeSubway) : @"subway", + @(OCDirectionsRequestTransitModeTrain) : @"train", + @(OCDirectionsRequestTransitModeTram) : @"tram", + @(OCDirectionsRequestTransitModeRail) : @"rail" + }; + } + return transitModeDictionary; +} + - (NSString *)encodeParameter:(NSString *)parameter { NSCharacterSet *set = [NSCharacterSet URLHostAllowedCharacterSet]; NSString *encodedParameter = [parameter stringByAddingPercentEncodingWithAllowedCharacters:set]; diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h new file mode 100644 index 0000000..1dc3ebe --- /dev/null +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h @@ -0,0 +1,40 @@ +// +// OCDirectionsRequestTravelMode.h +// OCGoogleDirectionsAPI +// +// Created by Marcin Iwanicki on 3/20/16. +// Copyright (c) 2014 Marcin Iwanicki. All rights reserved. +// + +typedef NS_OPTIONS(NSUInteger, OCDirectionsRequestTransitMode) { + /** + * default + */ + OCDirectionsRequestTransitModeNotSpecified = 0, + + /** + * indicates that the calculated route should prefer travel by bus. + */ + OCDirectionsRequestTransitModeBus = 1 << 1, + + /** + * indicates that the calculated route should prefer travel by subway. + */ + OCDirectionsRequestTransitModeSubway = 1 << 2, + + /** + * indicates that the calculated route should prefer travel by train. + */ + OCDirectionsRequestTransitModeTrain = 1 << 3, + + /** + * indicates that the calculated route should prefer travel by tram and light rail. + */ + OCDirectionsRequestTransitModeTram = 1 << 4, + + /** + * indicates that the calculated route should prefer travel by train, tram, light rail, and subway. + * This is equivalent to train|tram|subway. + */ + OCDirectionsRequestTransitModeRail = 1 << 5 +}; \ No newline at end of file diff --git a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h index 95f893b..f17e447 100644 --- a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h +++ b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h @@ -9,6 +9,7 @@ #import #import #import "OCDirectionsCommonTypes.h" +#import "OCDirectionsRequestTransitMode.h" #define kOCDirectionsRequestDepartureTimeNow [OCDirectionsRequest departureTimeNow] @@ -16,19 +17,19 @@ #pragma mark - Required /** - Origin - The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a string, the Directions service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values. + * Origin - The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a string, the Directions service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values. */ @property (nonatomic, readonly) CLLocation *originLocation; // CLLocation or NSString @property (nonatomic, copy, readonly) NSString *originString; /** - Destination - The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a string, the Directions service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values. + * Destination - The address or textual latitude/longitude value from which you wish to calculate directions. If you pass an address as a string, the Directions service will geocode the string and convert it to a latitude/longitude coordinate to calculate directions. If you pass coordinates, ensure that no space exists between the latitude and longitude values. */ @property (nonatomic, readonly) CLLocation *destinationLocation; // CLLocation or NSString @property (nonatomic, copy, readonly) NSString *destinationString; /* - Indicates whether or not the directions request comes from a device with a location sensor. This value must be either true or false. + * Indicates whether or not the directions request comes from a device with a location sensor. This value must be either true or false. */ @property (nonatomic, readonly) BOOL sensor; @@ -37,31 +38,40 @@ @property (nonatomic) OCDirectionsRequestTravelMode travelMode; /** - When calculating routes using the Directions API, you may also specify waypoints for driving, walking or bicycling directions. Waypoints are not available for transit directions. Waypoints allow you to calculate routes through additional locations, in which case the returned route passes through the given waypoints. - - Formally it is an array of NSStrings and CLLocations. + * When calculating routes using the Directions API, you may also specify waypoints for driving, walking or bicycling + * directions. Waypoints are not available for transit directions. Waypoints allow you to calculate routes through + * additional locations, in which case the returned route passes through the given waypoints. + * + * Formally it is an array of NSStrings and CLLocations. */ @property (nonatomic) NSArray *waypoints; /** - Optimizes the provided route by rearranging the waypoints in a more efficient order. (This optimization is an application of the Travelling Salesman Problem.) + * Optimizes the provided route by rearranging the waypoints in a more efficient order. + * (This optimization is an application of the Travelling Salesman Problem.) */ @property (nonatomic) BOOL waypointsOptimise; /** - Directions may be calculated that adhere to certain restrictions. - Use an array of DirectionsRequestRestriction types ie. @[DirectionsRequestAvoidTollsRestriction, DirectionsRequestAviodFerriesRestriction] + * Directions may be calculated that adhere to certain restrictions. + * Use an array of DirectionsRequestRestriction types ie. + * @[DirectionsRequestAvoidTollsRestriction, DirectionsRequestAviodFerriesRestriction] */ @property (nonatomic) NSArray *restrictions; /** - Directions results contain text within distance fields that may be displayed to the user to indicate the distance of a particular "step" of the route. By default, this text uses the unit system of the origin's country or region. + * Directions results contain text within distance fields that may be displayed to the user to indicate + * the distance of a particular "step" of the route. By default, this text uses the unit system of the origin's country + * or region. */ @property (nonatomic) OCDirectionsRequestUnit unit; /** - You can also set the Directions service to return results biased to a particular region by use of the region parameter. This parameter takes a ccTLD (country code top-level domain) argument specifying the region bias. Most ccTLD codes are identical to ISO 3166-1 codes, with some notable exceptions. For example, the United Kingdom's ccTLD is "uk" (.co.uk) while its ISO 3166-1 code is "gb" (technically for the entity of "The United Kingdom of Great Britain and Northern Ireland"). - - You may utilize any domain in which the main Google Maps application has launched driving directions. + * You can also set the Directions service to return results biased to a particular region by use of the region parameter. + * This parameter takes a ccTLD (country code top-level domain) argument specifying the region bias. + * Most ccTLD codes are identical to ISO 3166-1 codes, with some notable exceptions. For example, + * the United Kingdom's ccTLD is "uk" (.co.uk) while its ISO 3166-1 code is "gb" + * (technically for the entity of "The United Kingdom of Great Britain and Northern Ireland"). + * You may utilize any domain in which the main Google Maps application has launched driving directions. */ @property (nonatomic, copy) NSString *region; @@ -81,18 +91,23 @@ /** - You can also set the Directions service to return results is specific language. - If language is not supplied, the service will attempt to use the native language of the domain from which the request is sent. + * You can also set the Directions service to return results is specific language. + * If language is not supplied, the service will attempt to use the native language of the domain from which the request is sent. */ @property (nonatomic, copy) NSString *language; /** - Directions service may return several routes if you pass alternatives. + * Directions service may return several routes if you pass alternatives. */ @property (nonatomic) BOOL alternatives; /** - Indicates whether sensor flag has been used or not. + * Specifies one or more preferred modes of transit. + */ +@property (nonatomic) OCDirectionsRequestTransitMode transitMode; + +/** + * Indicates whether sensor flag has been used or not. */ @property (nonatomic, getter=isSensorFlagUsed, readonly) BOOL sensorFlagUsed; diff --git a/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m b/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m index 1806675..f333fff 100644 --- a/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m +++ b/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m @@ -289,6 +289,62 @@ - (void)testStringWhenDepartureTimeIsNow { XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&departure_time=now&key=0123456789abcdef", response); } +- (void)testStringWhenTransitModeIsNotSpecified { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.transitMode = OCDirectionsRequestTransitModeNotSpecified; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&key=0123456789abcdef", response); +} + +- (void)testStringWhenTransitModeIsBus { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.transitMode = OCDirectionsRequestTransitModeBus; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&transit_mode=bus&key=0123456789abcdef", response); +} + +- (void)testStringWhenTransitModeIsRail { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.transitMode = OCDirectionsRequestTransitModeRail; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&transit_mode=rail&key=0123456789abcdef", response); +} + +- (void)testStringWhenTransitModeIsSubwayAndTram { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.transitMode = OCDirectionsRequestTransitModeSubway | OCDirectionsRequestTransitModeTram; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&transit_mode=subway%7Ctram&key=0123456789abcdef", response); +} + #pragma mark - Helpers - (NSString *)prepareTestKey { From cc8487f16f00cf5b4eeba0f47b70400c51a5fa6b Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sun, 20 Mar 2016 16:31:40 +0000 Subject: [PATCH 06/15] Add traffic_model parameter to request. --- .../project.pbxproj | 2 + .../OCDirectionsRequestURLCreatorJSON.m | 43 +++++++------- .../Common/OCDirectionsCommonTypes.h | 17 ++++++ .../Common/OCDirectionsCommonTypes.m | 57 ++++++++++++++++--- .../Common/OCDirectionsRequestTrafficModel.h | 34 +++++++++++ .../Common/OCDirectionsRequestTransitMode.h | 4 +- .../Request/OCDirectionsRequest.h | 5 ++ .../OCDirectionsRequestURLCreatorJSONTests.m | 17 +++++- 8 files changed, 147 insertions(+), 32 deletions(-) create mode 100644 Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTrafficModel.h diff --git a/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj b/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj index 185a9c2..5bdc1b2 100644 --- a/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj +++ b/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj @@ -116,6 +116,7 @@ 27C6ECC318C6608E0035B80F /* OCGoogleDirectionsAPI-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "OCGoogleDirectionsAPI-Info.plist"; sourceTree = ""; }; 27C6ECCB18C67A910035B80F /* libOCGoogleDirectionsAPI.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libOCGoogleDirectionsAPI.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27C6ECCC18C67A910035B80F /* OCGoogleDirectionsAPITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OCGoogleDirectionsAPITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 524E82C69FF2B59CF5097950 /* OCDirectionsRequestTrafficModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsRequestTrafficModel.h; sourceTree = ""; }; 524E8AD319197A088907F852 /* OCDirectionsRequestTransitMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsRequestTransitMode.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -294,6 +295,7 @@ 27C6E91318C65A580035B80F /* OCDirectionsRequestUnit.h */, 27C6E91418C65A580035B80F /* OCDirectionsResponseVehicleType.h */, 524E8AD319197A088907F852 /* OCDirectionsRequestTransitMode.h */, + 524E82C69FF2B59CF5097950 /* OCDirectionsRequestTrafficModel.h */, ); path = Common; sourceTree = ""; diff --git a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m index 87066fa..313256f 100644 --- a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m +++ b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m @@ -27,6 +27,7 @@ static NSString *const kOCGoogleDirectionsRequestAttributeLanguage = @"&language="; static NSString *const kOCGoogleDirectionsRequestAttributeKey = @"&key="; static NSString *const kOCGoogleDirectionsRequestAttributeAlternatives = @"&alternatives="; +static NSString *const kOCGoogleDirectionsRequestAttributeTrafficModel = @"&traffic_model="; static NSString *const kOCGoogleDirectionsRequestAttributeTransitMode = @"&transit_mode="; static NSString *const kOCGoogleDirectionsRequestAttributeSeparator = @"|"; @@ -54,6 +55,7 @@ - (NSString *)stringFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)us [self appendArrivalTime:request toString:string]; [self appendDepartureTime:request toString:string]; [self appendAlternatives:request toString:string]; + [self appendTrafficModel:request toString:string]; [self appendTransitMode:request toString:string]; [self appendKey:key toString:string]; @@ -224,12 +226,12 @@ - (void)appendDepartureTime:(OCDirectionsRequest *)request toString:(NSMutableSt return; } - NSString *departureTimeValue = [request.departureTime isEqualToDate:kOCDirectionsRequestDepartureTimeNow] + NSString *departureTimeString = [request.departureTime isEqualToDate:kOCDirectionsRequestDepartureTimeNow] ? kOCGoogleDirectionsRequestAttributeValueDepartureTimeNow : @(request.departureTime.timeIntervalSince1970).stringValue; [string appendString:kOCGoogleDirectionsRequestAttributeDepartureTime]; - [string appendString:[self encodeParameter:departureTimeValue]]; + [string appendString:[self encodeParameter:departureTimeString]]; } - (void)appendLanguage:(OCDirectionsRequest *)request toString:(NSMutableString *)string { @@ -252,12 +254,23 @@ - (void)appendAlternatives:(OCDirectionsRequest *)request toString:(NSMutableStr [string appendString:[self encodeParameter:alternativesString]]; } +- (void)appendTrafficModel:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + if (request.trafficModel == OCDirectionsRequestTrafficModelDefault) { + return; + } + + NSString *trafficModelString = [OCDirectionsCommonTypes stringFromTrafficModel:request.trafficModel]; + + [string appendString:kOCGoogleDirectionsRequestAttributeTrafficModel]; + [string appendString:trafficModelString]; +} + - (void)appendTransitMode:(OCDirectionsRequest *)request toString:(NSMutableString *)string { - if (request.transitMode == OCDirectionsRequestTransitModeNotSpecified) { + if (request.transitMode == OCDirectionsRequestTransitModeDefault) { return; } - NSMutableString *transitModeValue = [NSMutableString string]; + NSMutableString *transitModeString = [NSMutableString string]; for (OCDirectionsRequestTransitMode transitMode = OCDirectionsRequestTransitModeBus; transitMode < (OCDirectionsRequestTransitModeRail << 1); transitMode <<= 1) { @@ -266,15 +279,15 @@ - (void)appendTransitMode:(OCDirectionsRequest *)request toString:(NSMutableStri continue; } - if (transitModeValue.length > 0) { - [transitModeValue appendString:kOCGoogleDirectionsRequestAttributeSeparator]; + if (transitModeString.length > 0) { + [transitModeString appendString:kOCGoogleDirectionsRequestAttributeSeparator]; } - [transitModeValue appendString:[self transitModeDictionary][@(transitMode)]]; + [transitModeString appendString:[OCDirectionsCommonTypes stringFromTransitModel:transitMode]]; } [string appendString:kOCGoogleDirectionsRequestAttributeTransitMode]; - [string appendString:[self encodeParameter:transitModeValue]]; + [string appendString:[self encodeParameter:transitModeString]]; } - (void)appendKey:(NSString *)key toString:(NSMutableString *)string { @@ -312,20 +325,6 @@ - (NSString *)stringFormUnit:(OCDirectionsRequestUnit)unit { return @""; } -- (NSDictionary *)transitModeDictionary { - static NSDictionary *transitModeDictionary; - if (transitModeDictionary == nil) { - transitModeDictionary = @{ - @(OCDirectionsRequestTransitModeBus) : @"bus", - @(OCDirectionsRequestTransitModeSubway) : @"subway", - @(OCDirectionsRequestTransitModeTrain) : @"train", - @(OCDirectionsRequestTransitModeTram) : @"tram", - @(OCDirectionsRequestTransitModeRail) : @"rail" - }; - } - return transitModeDictionary; -} - - (NSString *)encodeParameter:(NSString *)parameter { NSCharacterSet *set = [NSCharacterSet URLHostAllowedCharacterSet]; NSString *encodedParameter = [parameter stringByAddingPercentEncodingWithAllowedCharacters:set]; diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h index 425f2b0..345a5cd 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h @@ -12,6 +12,8 @@ #import "OCDirectionsRequestRestriction.h" #import "OCDirectionsRequestUnit.h" #import "OCDirectionsResponseVehicleType.h" +#import "OCDirectionsRequestTransitMode.h" +#import "OCDirectionsRequestTrafficModel.h" @interface OCDirectionsCommonTypes : NSObject @@ -33,5 +35,20 @@ + (NSDictionary *)vehicleTypesDictionary; +@end + +@interface OCDirectionsCommonTypes (TransitMode) + ++ (NSString *)stringFromTransitModel:(OCDirectionsRequestTransitMode)transitMode; + ++ (NSDictionary *)transitModeDictionary; @end + +@interface OCDirectionsCommonTypes (TrafficModel) + ++ (NSString *)stringFromTrafficModel:(OCDirectionsRequestTrafficModel)trafficModel; + ++ (NSDictionary *)trafficModelDictionary; + +@end \ No newline at end of file diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m index 1a10c6a..bb274fd 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m @@ -16,14 +16,13 @@ @implementation OCDirectionsCommonTypes @implementation OCDirectionsCommonTypes (TravelMode) + (NSString *)stringFormTravelMode:(OCDirectionsRequestTravelMode)travelMode { - NSArray *keys = [[[self class] travelModeDictionary] allKeysForObject:@(travelMode)]; + NSArray *keys = [[self travelModeDictionary] allKeysForObject:@(travelMode)]; return [keys firstObject]; } + (OCDirectionsRequestTravelMode)travelModeFromString:(NSString *)travelModeString { - NSNumber *number = [[[self class] travelModeDictionary] objectForKey:travelModeString]; + NSNumber *number = [self travelModeDictionary][travelModeString]; OCDirectionsRequestTravelMode travelMode = (OCDirectionsRequestTravelMode) number.unsignedIntegerValue; - return travelMode; } @@ -31,7 +30,8 @@ + (NSDictionary *)travelModeDictionary { static NSDictionary *dictionary; if (dictionary == nil) { - dictionary = @{@"driving" : @(OCDirectionsRequestTravelModeDriving), + dictionary = @{ + @"driving" : @(OCDirectionsRequestTravelModeDriving), @"walking" : @(OCDirectionsRequestTravelModeWalking), @"bicycling" : @(OCDirectionsRequestTravelModeBicycling), @"transit" : @(OCDirectionsRequestTravelModeTransit) @@ -46,9 +46,8 @@ + (NSDictionary *)travelModeDictionary { @implementation OCDirectionsCommonTypes (VehicalType) + (OCDirectionsResponseVehicleType)vehicleTypeFromString:(NSString *)vehicleTypeString { - NSNumber *number = [[[self class] vehicleTypesDictionary] objectForKey:vehicleTypeString]; + NSNumber *number = [self vehicleTypesDictionary][vehicleTypeString]; OCDirectionsResponseVehicleType vehicleType = (OCDirectionsResponseVehicleType) number.unsignedIntegerValue; - return vehicleType; } @@ -56,7 +55,8 @@ + (NSDictionary *)vehicleTypesDictionary { static NSDictionary *dictionary; if (dictionary == nil) { - dictionary = @{@"RAIL" : @(OCDirectionsResponseVehicleTypeRail), + dictionary = @{ + @"RAIL" : @(OCDirectionsResponseVehicleTypeRail), @"METRO_RAIL" : @(OCDirectionsResponseVehicleTypeMetroRail), @"SUBWAY" : @(OCDirectionsResponseVehicleTypeSubway), @"TRAM" : @(OCDirectionsResponseVehicleTypeTram), @@ -80,3 +80,46 @@ + (NSDictionary *)vehicleTypesDictionary { } @end + +@implementation OCDirectionsCommonTypes (TransitMode) + ++ (NSString *)stringFromTransitModel:(OCDirectionsRequestTransitMode)transitMode { + return [self transitModeDictionary][@(transitMode)]; +} + ++ (NSDictionary *)transitModeDictionary { + static NSDictionary *transitModeDictionary; + if (transitModeDictionary == nil) { + transitModeDictionary = @{ + @(OCDirectionsRequestTransitModeBus) : @"bus", + @(OCDirectionsRequestTransitModeSubway) : @"subway", + @(OCDirectionsRequestTransitModeTrain) : @"train", + @(OCDirectionsRequestTransitModeTram) : @"tram", + @(OCDirectionsRequestTransitModeRail) : @"rail" + }; + } + return transitModeDictionary; +} + +@end + +@implementation OCDirectionsCommonTypes (TrafficModel) + ++ (NSString *)stringFromTrafficModel:(OCDirectionsRequestTrafficModel)trafficModel { + return [self trafficModelDictionary][@(trafficModel)]; +} + ++ (NSDictionary *)trafficModelDictionary { + static NSDictionary *trafficModelDictionary; + if (trafficModelDictionary == nil) { + trafficModelDictionary = @{ + @(OCDirectionsRequestTrafficModelBestGuess) : @"best_guess", + @(OCDirectionsRequestTrafficModelPessimistic) : @"pessimistic", + @(OCDirectionsRequestTrafficModelOptimistic) : @"optimistic" + }; + } + return trafficModelDictionary; +} + +@end + diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTrafficModel.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTrafficModel.h new file mode 100644 index 0000000..c9d7fda --- /dev/null +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTrafficModel.h @@ -0,0 +1,34 @@ +// +// OCDirectionsRequestTrafficModel.h +// OCGoogleDirectionsAPI +// +// Created by Marcin Iwanicki on 3/20/16. +// Copyright (c) 2014 Marcin Iwanicki. All rights reserved. +// + + +typedef NS_ENUM(NSUInteger, OCDirectionsRequestTrafficModel) { + /** + * not specified + */ + OCDirectionsRequestTrafficModelDefault, + + /** + * (default) indicates that the returned duration_in_traffic should be the best estimate of travel time given + * what is known about both historical traffic conditions and live traffic. + * Live traffic becomes more important the closer the departure_time is to now. + */ + OCDirectionsRequestTrafficModelBestGuess, + + /** + * indicates that the returned duration_in_traffic should be longer than the actual travel time on most days, + * though occasional days with particularly bad traffic conditions may exceed this value. + */ + OCDirectionsRequestTrafficModelPessimistic, + + /** + * indicates that the returned duration_in_traffic should be shorter than the actual travel time on most days, + * though occasional days with particularly good traffic conditions may be faster than this value. + */ + OCDirectionsRequestTrafficModelOptimistic +}; \ No newline at end of file diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h index 1dc3ebe..b079488 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h @@ -8,9 +8,9 @@ typedef NS_OPTIONS(NSUInteger, OCDirectionsRequestTransitMode) { /** - * default + * not specified */ - OCDirectionsRequestTransitModeNotSpecified = 0, + OCDirectionsRequestTransitModeDefault = 0, /** * indicates that the calculated route should prefer travel by bus. diff --git a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h index f17e447..4cbe987 100644 --- a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h +++ b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h @@ -101,6 +101,11 @@ */ @property (nonatomic) BOOL alternatives; +/** + * Specifies the assumptions to use when calculating time in traffic. + */ +@property (nonatomic) OCDirectionsRequestTrafficModel trafficModel; + /** * Specifies one or more preferred modes of transit. */ diff --git a/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m b/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m index f333fff..f17fb5e 100644 --- a/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m +++ b/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m @@ -289,10 +289,25 @@ - (void)testStringWhenDepartureTimeIsNow { XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&departure_time=now&key=0123456789abcdef", response); } +- (void)testStringWhenTrafficModelIsOptimistic { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.trafficModel = OCDirectionsRequestTrafficModelOptimistic; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&traffic_model=optimistic&key=0123456789abcdef", response); + +} + - (void)testStringWhenTransitModeIsNotSpecified { // given OCDirectionsRequest *request = [self prepareRequest]; - request.transitMode = OCDirectionsRequestTransitModeNotSpecified; + request.transitMode = OCDirectionsRequestTransitModeDefault; NSString *key = [self prepareTestKey]; From 18372af37e42a203451df4c3df1a2f61b801dfde Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sun, 20 Mar 2016 16:56:51 +0000 Subject: [PATCH 07/15] Add transit_routing_preference parameter to request. --- .../project.pbxproj | 2 ++ .../OCDirectionsRequestURLCreatorJSON.m | 30 +++++++++++++------ .../Common/OCDirectionsCommonTypes.h | 9 ++++++ .../Common/OCDirectionsCommonTypes.m | 18 +++++++++++ ...irectionsRequestTransitRoutingPreference.h | 25 ++++++++++++++++ .../Request/OCDirectionsRequest.h | 6 ++++ .../OCDirectionsRequestURLCreatorJSONTests.m | 16 +++++++++- 7 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitRoutingPreference.h diff --git a/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj b/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj index 5bdc1b2..8da0685 100644 --- a/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj +++ b/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj @@ -117,6 +117,7 @@ 27C6ECCB18C67A910035B80F /* libOCGoogleDirectionsAPI.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libOCGoogleDirectionsAPI.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27C6ECCC18C67A910035B80F /* OCGoogleDirectionsAPITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OCGoogleDirectionsAPITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 524E82C69FF2B59CF5097950 /* OCDirectionsRequestTrafficModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsRequestTrafficModel.h; sourceTree = ""; }; + 524E8A60179A39E791889072 /* OCDirectionsRequestTransitRoutingPreference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsRequestTransitRoutingPreference.h; sourceTree = ""; }; 524E8AD319197A088907F852 /* OCDirectionsRequestTransitMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsRequestTransitMode.h; sourceTree = ""; }; /* End PBXFileReference section */ @@ -296,6 +297,7 @@ 27C6E91418C65A580035B80F /* OCDirectionsResponseVehicleType.h */, 524E8AD319197A088907F852 /* OCDirectionsRequestTransitMode.h */, 524E82C69FF2B59CF5097950 /* OCDirectionsRequestTrafficModel.h */, + 524E8A60179A39E791889072 /* OCDirectionsRequestTransitRoutingPreference.h */, ); path = Common; sourceTree = ""; diff --git a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m index 313256f..74ce336 100644 --- a/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m +++ b/Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m @@ -29,6 +29,7 @@ static NSString *const kOCGoogleDirectionsRequestAttributeAlternatives = @"&alternatives="; static NSString *const kOCGoogleDirectionsRequestAttributeTrafficModel = @"&traffic_model="; static NSString *const kOCGoogleDirectionsRequestAttributeTransitMode = @"&transit_mode="; +static NSString *const kOCGoogleDirectionsRequestAttributeTransitRoutingPreference = @"&transit_routing_preference="; static NSString *const kOCGoogleDirectionsRequestAttributeSeparator = @"|"; @@ -57,6 +58,7 @@ - (NSString *)stringFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)us [self appendAlternatives:request toString:string]; [self appendTrafficModel:request toString:string]; [self appendTransitMode:request toString:string]; + [self appendTransitRoutingPreference:request toString:string]; [self appendKey:key toString:string]; return string; @@ -92,7 +94,7 @@ - (void)appendOrigin:(OCDirectionsRequest *)request toString:(NSMutableString *) if (request.originLocation) { NSString *originString = [self stringFormCLLocation:request.originLocation]; - [string appendString:[self encodeParameter:originString]]; + [string appendString:originString]; } else { [string appendString:[self encodeParameter:request.originString]]; } @@ -103,7 +105,7 @@ - (void)appendDestination:(OCDirectionsRequest *)request toString:(NSMutableStri if (request.destinationLocation) { NSString *destinationString = [self stringFormCLLocation:request.destinationLocation]; - [string appendString:[self encodeParameter:destinationString]]; + [string appendString:destinationString]; } else { [string appendString:[self encodeParameter:request.destinationString]]; } @@ -120,7 +122,7 @@ - (void)appendSensor:(OCDirectionsRequest *)request toString:(NSMutableString *) [string appendString:kOCGoogleDirectionsRequestAttributeSensor]; NSString *sensorString = [self stringFromBOOL:request.sensor]; - [string appendString:[self encodeParameter:sensorString]]; + [string appendString:sensorString]; } - (void)appendTravelMode:(OCDirectionsRequest *)request toString:(NSMutableString *)string { @@ -131,7 +133,7 @@ - (void)appendTravelMode:(OCDirectionsRequest *)request toString:(NSMutableStrin [string appendString:kOCGoogleDirectionsRequestAttributeTravelMode]; NSString *travelModeString = [OCDirectionsCommonTypes stringFormTravelMode:request.travelMode]; - [string appendString:[self encodeParameter:travelModeString]]; + [string appendString:travelModeString]; } - (void)appendWaypoints:(OCDirectionsRequest *)request toString:(NSMutableString *)string { @@ -198,7 +200,7 @@ - (void)appendUnit:(OCDirectionsRequest *)request toString:(NSMutableString *)st [string appendString:kOCGoogleDirectionsRequestAttributeUnits]; NSString *unitString = [self stringFormUnit:request.unit]; - [string appendString:[self encodeParameter:unitString]]; + [string appendString:unitString]; } - (void)appendRegion:(OCDirectionsRequest *)request toString:(NSMutableString *)string { @@ -218,7 +220,7 @@ - (void)appendArrivalTime:(OCDirectionsRequest *)request toString:(NSMutableStri NSString *arrivalTimeValue = @(request.arrivalTime.timeIntervalSince1970).stringValue; [string appendString:kOCGoogleDirectionsRequestAttributeArrivalTime]; - [string appendString:[self encodeParameter:arrivalTimeValue]]; + [string appendString:arrivalTimeValue]; } - (void)appendDepartureTime:(OCDirectionsRequest *)request toString:(NSMutableString *)string { @@ -231,7 +233,7 @@ - (void)appendDepartureTime:(OCDirectionsRequest *)request toString:(NSMutableSt : @(request.departureTime.timeIntervalSince1970).stringValue; [string appendString:kOCGoogleDirectionsRequestAttributeDepartureTime]; - [string appendString:[self encodeParameter:departureTimeString]]; + [string appendString:departureTimeString]; } - (void)appendLanguage:(OCDirectionsRequest *)request toString:(NSMutableString *)string { @@ -251,7 +253,7 @@ - (void)appendAlternatives:(OCDirectionsRequest *)request toString:(NSMutableStr [string appendString:kOCGoogleDirectionsRequestAttributeAlternatives]; NSString *alternativesString = [self stringFromBOOL:request.alternatives]; - [string appendString:[self encodeParameter:alternativesString]]; + [string appendString:alternativesString]; } - (void)appendTrafficModel:(OCDirectionsRequest *)request toString:(NSMutableString *)string { @@ -287,7 +289,17 @@ - (void)appendTransitMode:(OCDirectionsRequest *)request toString:(NSMutableStri } [string appendString:kOCGoogleDirectionsRequestAttributeTransitMode]; - [string appendString:[self encodeParameter:transitModeString]]; + [string appendString:transitModeString]; +} + +- (void)appendTransitRoutingPreference:(OCDirectionsRequest *)request toString:(NSMutableString *)string { + if (request.transitRoutingPreference == OCDirectionsRequestTransitRoutingPreferenceDefault) { + return; + } + + NSString *transitRoutingPreferenceString = [OCDirectionsCommonTypes stringFromTransitRoutingPreference:request.transitRoutingPreference]; + [string appendString:kOCGoogleDirectionsRequestAttributeTransitRoutingPreference]; + [string appendString:transitRoutingPreferenceString]; } - (void)appendKey:(NSString *)key toString:(NSMutableString *)string { diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h index 345a5cd..08eaa17 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h @@ -14,6 +14,7 @@ #import "OCDirectionsResponseVehicleType.h" #import "OCDirectionsRequestTransitMode.h" #import "OCDirectionsRequestTrafficModel.h" +#import "OCDirectionsRequestTransitRoutingPreference.h" @interface OCDirectionsCommonTypes : NSObject @@ -51,4 +52,12 @@ + (NSDictionary *)trafficModelDictionary; +@end + +@interface OCDirectionsCommonTypes (TransitRoutingPreference) + ++ (NSString *)stringFromTransitRoutingPreference:(OCDirectionsRequestTransitRoutingPreference)transitRoutingPreference; + ++ (NSDictionary *)transitRoutingPreferenceDictionary; + @end \ No newline at end of file diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m index bb274fd..5b4953f 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.m @@ -123,3 +123,21 @@ + (NSDictionary *)trafficModelDictionary { @end +@implementation OCDirectionsCommonTypes (TransitRoutingPreference) + ++ (NSString *)stringFromTransitRoutingPreference:(OCDirectionsRequestTransitRoutingPreference)transitRoutingPreference { + return [self transitRoutingPreferenceDictionary][@(transitRoutingPreference)]; +} + ++ (NSDictionary *)transitRoutingPreferenceDictionary { + static NSDictionary *transitRoutingPreference; + if (transitRoutingPreference == nil) { + transitRoutingPreference = @{ + @(OCDirectionsRequestTransitRoutingPreferenceLessWalking) : @"less_walking", + @(OCDirectionsRequestTransitRoutingPreferenceFewerTransfers) : @"fewer_transfers", + }; + } + return transitRoutingPreference; +} + +@end diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitRoutingPreference.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitRoutingPreference.h new file mode 100644 index 0000000..3190ce1 --- /dev/null +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitRoutingPreference.h @@ -0,0 +1,25 @@ +// +// OCDirectionsRequestTrafficModel.h +// OCGoogleDirectionsAPI +// +// Created by Marcin Iwanicki on 3/20/16. +// Copyright (c) 2014 Marcin Iwanicki. All rights reserved. +// + + +typedef NS_ENUM(NSUInteger, OCDirectionsRequestTransitRoutingPreference) { + /** + * not specified + */ + OCDirectionsRequestTransitRoutingPreferenceDefault, + + /** + * indicates that the calculated route should prefer limited amounts of walking. + */ + OCDirectionsRequestTransitRoutingPreferenceLessWalking, + + /** + * indicates that the calculated route should prefer a limited number of transfers. + */ + OCDirectionsRequestTransitRoutingPreferenceFewerTransfers +}; \ No newline at end of file diff --git a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h index 4cbe987..7900e92 100644 --- a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h +++ b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h @@ -111,6 +111,12 @@ */ @property (nonatomic) OCDirectionsRequestTransitMode transitMode; +/** + * Specifies preferences for transit routes. Using this parameter, you can bias the options returned, + * rather than accepting the default best route chosen by the API. + */ +@property (nonatomic) OCDirectionsRequestTransitRoutingPreference transitRoutingPreference; + /** * Indicates whether sensor flag has been used or not. */ diff --git a/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m b/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m index f17fb5e..54a9991 100644 --- a/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m +++ b/Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m @@ -357,7 +357,21 @@ - (void)testStringWhenTransitModeIsSubwayAndTram { NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; // then - XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&transit_mode=subway%7Ctram&key=0123456789abcdef", response); + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&transit_mode=subway|tram&key=0123456789abcdef", response); +} + +- (void)testStringWhenTransitRoutingPreferenceIsLessWalking { + // given + OCDirectionsRequest *request = [self prepareRequest]; + request.transitRoutingPreference = OCDirectionsRequestTransitRoutingPreferenceLessWalking; + + NSString *key = [self prepareTestKey]; + + // when + NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key]; + + // then + XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false&transit_routing_preference=less_walking&key=0123456789abcdef", response); } #pragma mark - Helpers From 59006970a3774aa9cfc4a6a5b8fad12ce6254854 Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sun, 20 Mar 2016 18:42:47 +0000 Subject: [PATCH 08/15] Add duration_in_traffic to response. --- .../Response/Attributes/OCDirectionsDuration.h | 1 + .../Response/Attributes/OCDirectionsDuration.m | 1 + .../Response/Attributes/OCDirectionsLeg.h | 1 + .../Response/Attributes/OCDirectionsLeg.m | 8 ++++++++ .../OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m | 3 ++- 5 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h index 7ead45f..41e9565 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.h @@ -9,6 +9,7 @@ #import extern NSString *const kCGGoogleDirectionsResponseAttributeDuration; +extern NSString *const kCGGoogleDirectionsResponseAttributeDurationInTraffic; @interface OCDirectionsDuration : NSObject diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.m index d6f3d2a..b0763da 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsDuration.m @@ -9,6 +9,7 @@ #import "OCDirectionsDuration.h" NSString *const kCGGoogleDirectionsResponseAttributeDuration = @"duration"; +NSString *const kCGGoogleDirectionsResponseAttributeDurationInTraffic = @"duration_in_traffic"; static NSString *const kCGGoogleDirectionsResponseAttributeDurationText = @"text"; static NSString *const kCGGoogleDirectionsResponseAttributeDurationValue = @"value"; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h index 8e6eba3..e08e5cb 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.h @@ -17,6 +17,7 @@ @property (nonatomic, readonly) OCDirectionsDistance *distance; @property (nonatomic, readonly) OCDirectionsDuration *duration; +@property (nonatomic, readonly) OCDirectionsDuration *durationInTraffic; @property (nonatomic, copy, readonly) NSString *endAddress; @property (nonatomic, readonly) CLLocationCoordinate2D endLocation; @property (nonatomic, copy, readonly) NSString *startAddress; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.m index ffaeec1..34996d8 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsLeg.m @@ -42,6 +42,7 @@ - (instancetype)initWithDictionary:(NSDictionary *)dictionary { - (void)loadAllProperties { [self loadDistance]; [self loadDuration]; + [self loadDurationInTraffic]; [self loadEndAddress]; [self loadEndLocation]; [self loadStartAddress]; @@ -64,6 +65,13 @@ - (void)loadDuration { _duration = duration; } +- (void)loadDurationInTraffic { + NSDictionary *durationInTrafficDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeDurationInTraffic]; + OCDirectionsDuration *durationInTraffic = [OCDirectionsDuration durationFromDictionary:durationInTrafficDictionary]; + + _durationInTraffic = durationInTraffic; +} + - (void)loadEndAddress { NSString *endAddress = [_dictionary objectForKey:kCGgoogleDirectionsResponseAttributeEndAddress]; diff --git a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m index 85f9ba2..2be9f77 100644 --- a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m +++ b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m @@ -43,7 +43,8 @@ + (NSDictionary *)statusDictionary { static NSDictionary *dictionary; if (dictionary == nil) { - dictionary = @{@"OK" : @(OCDirectionsResponseStatusOK), + dictionary = @{ + @"OK" : @(OCDirectionsResponseStatusOK), @"NOT_FOUND" : @(OCDirectionsResponseStatusNotFound), @"ZERO_RESULTS" : @(OCDirectionsResponseStatusZeroResults), @"MAX_WAYPOINTS_EXCEEDED" : @(OCDirectionsResponseStatusMaxWaypointsExceeded), From 3df8a4749fce48717e70db33a1b4a8837dff3478 Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sun, 20 Mar 2016 19:01:00 +0000 Subject: [PATCH 09/15] Add fare to response. --- .../project.pbxproj | 6 ++ .../Response/Attributes/OCDirectionsFare.h | 30 ++++++++++ .../Response/Attributes/OCDirectionsFare.m | 57 +++++++++++++++++++ .../Response/Attributes/OCDirectionsRoute.h | 29 +++++++--- .../Response/Attributes/OCDirectionsRoute.m | 11 ++++ 5 files changed, 126 insertions(+), 7 deletions(-) create mode 100644 Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.h create mode 100644 Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.m diff --git a/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj b/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj index 8da0685..c061fb3 100644 --- a/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj +++ b/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj @@ -41,6 +41,7 @@ 27C6EBA018C65A590035B80F /* CLLocation+CoortindateFromDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E93418C65A580035B80F /* CLLocation+CoortindateFromDictionary.m */; }; 27C6ECC118C65FDC0035B80F /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 27C6E8CE18C6578B0035B80F /* InfoPlist.strings */; }; 27C6ECCD18C67ACC0035B80F /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27C6E8C318C6578B0035B80F /* XCTest.framework */; }; + 524E8C2300316B8EBFB04BDB /* OCDirectionsFare.m in Sources */ = {isa = PBXBuildFile; fileRef = 524E8125ADC56AD2FA29F498 /* OCDirectionsFare.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -116,9 +117,11 @@ 27C6ECC318C6608E0035B80F /* OCGoogleDirectionsAPI-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "OCGoogleDirectionsAPI-Info.plist"; sourceTree = ""; }; 27C6ECCB18C67A910035B80F /* libOCGoogleDirectionsAPI.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libOCGoogleDirectionsAPI.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27C6ECCC18C67A910035B80F /* OCGoogleDirectionsAPITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OCGoogleDirectionsAPITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 524E8125ADC56AD2FA29F498 /* OCDirectionsFare.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCDirectionsFare.m; sourceTree = ""; }; 524E82C69FF2B59CF5097950 /* OCDirectionsRequestTrafficModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsRequestTrafficModel.h; sourceTree = ""; }; 524E8A60179A39E791889072 /* OCDirectionsRequestTransitRoutingPreference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsRequestTransitRoutingPreference.h; sourceTree = ""; }; 524E8AD319197A088907F852 /* OCDirectionsRequestTransitMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsRequestTransitMode.h; sourceTree = ""; }; + 524E8EF40C63F7BA5F9C6A91 /* OCDirectionsFare.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsFare.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -340,6 +343,8 @@ 27C6E92A18C65A580035B80F /* OCDirectionsStep.m */, 27C6E92B18C65A580035B80F /* OCDirectionsWaypoint.h */, 27C6E92C18C65A580035B80F /* OCDirectionsWaypoint.m */, + 524E8125ADC56AD2FA29F498 /* OCDirectionsFare.m */, + 524E8EF40C63F7BA5F9C6A91 /* OCDirectionsFare.h */, ); path = Attributes; sourceTree = ""; @@ -469,6 +474,7 @@ 27C6EB9818C65A590035B80F /* OCDirectionsRoute.m in Sources */, 27C6EB8E18C65A590035B80F /* OCDirectionsBounds.m in Sources */, 27C6EB9A18C65A590035B80F /* OCDirectionsStep.m in Sources */, + 524E8C2300316B8EBFB04BDB /* OCDirectionsFare.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.h new file mode 100644 index 0000000..1a697e6 --- /dev/null +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.h @@ -0,0 +1,30 @@ +// +// Created by Marcin Iwanicki on 20/03/2016. +// + +#import + +extern NSString *const kCGGoogleDirectionsResponseAttributeFare; + +@interface OCDirectionsFare : NSObject + +@property (nonatomic, readonly) NSDictionary *dictionary; + +/** + * An ISO 4217 currency code indicating the currency that the amount is expressed in. + */ +@property (nonatomic, copy, readonly) NSString *currency; + +/** + * The total fare amount, formatted in the requested language. + */ +@property (nonatomic, copy, readonly) NSString *text; + +/** + * The total fare amount, in the currency specified above. + */ +@property (nonatomic, readonly) NSNumber *value; + ++ (instancetype)fareFromDictionary:(NSDictionary *)dictionary; + +@end \ No newline at end of file diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.m new file mode 100644 index 0000000..4d10e6a --- /dev/null +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.m @@ -0,0 +1,57 @@ +// +// Created by Marcin Iwanicki on 20/03/2016. +// + +#import "OCDirectionsFare.h" + +NSString *const kCGGoogleDirectionsResponseAttributeFare = @"fare"; + +static NSString *const kCGGoogleDirectionsResponseAttributeFareCurrency = @"currency"; +static NSString *const kCGGoogleDirectionsResponseAttributeFareValue = @"value"; +static NSString *const kCGGoogleDirectionsResponseAttributeFareText = @"text"; + +@implementation OCDirectionsFare + +#pragma mark - Public + ++ (instancetype)fareFromDictionary:(NSDictionary *)dictionary { + return [[OCDirectionsFare alloc] initWithDictionary:dictionary]; +} + +#pragma mark - Private + +- (instancetype)initWithDictionary:(NSDictionary *)dictionary { + self = [super init]; + if (self) { + _dictionary = dictionary; + + [self loadAllProperties]; + } + return self; +} + +- (void)loadAllProperties { + [self loadCurrency]; + [self loadText]; + [self loadValue]; +} + +- (void)loadCurrency { + NSString *currency = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeFareCurrency]; + + _currency = currency; +} + +- (void)loadText { + NSString *text = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeFareText]; + + _text = text; +} + +- (void)loadValue { + NSNumber *value = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeFareValue]; + + _value = value; +} + +@end \ No newline at end of file diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h index ed14d0b..817d4fa 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.h @@ -10,45 +10,60 @@ #import "OCDirectionsPolyline.h" #import "OCDirectionsBounds.h" +@class OCDirectionsFare; + @interface OCDirectionsRoute : NSObject @property (nonatomic, readonly) NSDictionary *dictionary; /** - legs[] contains an array which contains information about a leg of the route, between two locations within the given route. A separate leg will be present for each waypoint or destination specified. (A route with no waypoints will contain exactly one leg within the legs array.) Each leg consists of a series of steps. (See Directions Legs below.) + * legs[] contains an array which contains information about a leg of the route, between two locations within the given + * route. A separate leg will be present for each waypoint or destination specified. (A route with no waypoints will + * contain exactly one leg within the legs array.) Each leg consists of a series of steps. (See Directions Legs below.) */ @property (nonatomic, readonly) NSArray *legs; /** - copyrights contains the copyrights text to be displayed for this route. You must handle and display this information yourself. + * copyrights contains the copyrights text to be displayed for this route. You must handle and display this information + * yourself. */ @property (nonatomic, copy, readonly) NSString *copyrights; /* - warnings[] contains an array of warnings to be displayed when showing these directions. You must handle and display these warnings yourself. + * warnings[] contains an array of warnings to be displayed when showing these directions. You must handle and display + * these warnings yourself. */ @property (nonatomic, readonly) NSArray *warnings; /** - waypoint_order contains an array indicating the order of any waypoints in the calculated route. This waypoints may be reordered if the request was passed optimize:true within its waypoints parameter. + * waypoint_order contains an array indicating the order of any waypoints in the calculated route. This waypoints may be + * reordered if the request was passed optimize:true within its waypoints parameter. */ @property (nonatomic, readonly) NSArray *waypointOrder; /** - overview_polyline contains an object holding an array of encoded points that represent an approximate (smoothed) path of the resulting directions. + * overview_polyline contains an object holding an array of encoded points that represent an approximate (smoothed) path + * of the resulting directions. */ @property (nonatomic, readonly) OCDirectionsPolyline *overviewPolyline; /** - bounds contains the viewport bounding box of the overview_polyline. + * bounds contains the viewport bounding box of the overview_polyline. */ @property (nonatomic, readonly) OCDirectionsBounds *bounds; /** - summary contains a short textual description for the route, suitable for naming and disambiguating the route from alternatives. + * summary contains a short textual description for the route, suitable for naming and disambiguating the route from + * alternatives. */ @property (nonatomic, copy, readonly) NSString *summary; +/** + * fare, if present, contains the total fare (that is, the total ticket costs) on this route. This property is only + * returned for transit requests and only for routes where fare information is available for all transit legs. + */ +@property (nonatomic, readonly) OCDirectionsFare *fare; + + (instancetype)routeFromDictionary:(NSDictionary *)dictionary; @end diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m index 3d0fa60..26d8ff9 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m @@ -8,6 +8,7 @@ #import "OCDirectionsRoute.h" #import "OCDirectionsLeg.h" +#import "OCDirectionsFare.h" static NSString *const kCGGoogleDirectionsResponseAttributeRouteSummary = @"summary"; static NSString *const kCGGoogleDirectionsResponseAttributeRouteLegs = @"legs"; @@ -46,6 +47,7 @@ - (void)loadAllProperties { [self loadOverviewPolyline]; [self loadBounds]; [self loadSummary]; + [self loadFare]; } - (void)loadLegs { @@ -96,4 +98,13 @@ - (void)loadSummary { _summary = summary; } +- (void)loadFare { + NSDictionary *fareDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeFare]: + if (fareDictionary) { + OCDirectionsFare *fare = [OCDirectionsFare fareFromDictionary:fareDictionary]; + + _fare = fare; + } +} + @end From fa5ae8144655f098d798600388bdb9f8ff20434e Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sun, 20 Mar 2016 19:24:51 +0000 Subject: [PATCH 10/15] Fix project issues. --- Bin/run-build.sh | 6 + Bin/run-tests.sh | 6 + CHANGELOG.md | 13 +- Rakefile | 148 ------------------ .../project.pbxproj | 47 +----- .../xcschemes/OCGoogleDirectionsAPI.xcscheme | 22 ++- .../OCGoogleDirectionsAPITests.xcscheme | 27 +++- .../OCDirectionsRequestURLCreatorJSON.m | 2 +- .../OCGoogleDirectionsAPI-Info.plist | 52 +++--- .../Response/Attributes/OCDirectionsRoute.m | 2 +- .../OCGoogleDirectionsAPITests-Info.plist | 36 ++--- 11 files changed, 112 insertions(+), 249 deletions(-) create mode 100755 Bin/run-build.sh create mode 100755 Bin/run-tests.sh delete mode 100644 Rakefile diff --git a/Bin/run-build.sh b/Bin/run-build.sh new file mode 100755 index 0000000..678172c --- /dev/null +++ b/Bin/run-build.sh @@ -0,0 +1,6 @@ +#!/bin/bash +if [ ! -d Source ]; then + cd .. +fi +cd Source +xctool build -project OCGoogleDirectionsAPI.xcodeproj -scheme OCGoogleDirectionsAPI -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO diff --git a/Bin/run-tests.sh b/Bin/run-tests.sh new file mode 100755 index 0000000..94cf089 --- /dev/null +++ b/Bin/run-tests.sh @@ -0,0 +1,6 @@ +#!/bin/bash +if [ ! -d Source ]; then + cd .. +fi +cd Source +xctool test -project OCGoogleDirectionsAPI.xcodeproj -scheme OCGoogleDirectionsAPITests -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a15ad2..21c3c6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,16 +1,19 @@ # OCGoogleDirectionsAPI CHANGELOG -## 0.1.0 +## 0.1.5 -Initial release. +- + + +## 0.1.2 +- Fixed copy-paste error of kCGGoogleDirectionsResponseAttributeBounds. (thanks @djmadcat) ## 0.1.1 - Fixed init method to initialise locationString property properly. - Fixed missing summary parsing. (thanks @DmitryPR) +## 0.1.0 -## 0.1.2 - -- Fixed copy-paste error of kCGGoogleDirectionsResponseAttributeBounds. (thanks @djmadcat) \ No newline at end of file +Initial release. diff --git a/Rakefile b/Rakefile deleted file mode 100644 index 2a2fb5f..0000000 --- a/Rakefile +++ /dev/null @@ -1,148 +0,0 @@ -desc "Runs the specs [EMPTY]" -task :spec do - # Provide your own implementation -end - -task :version do - git_remotes = `git remote`.strip.split("\n") - - if git_remotes.count > 0 - puts "-- fetching version number from github" - sh 'git fetch' - - remote_version = remote_spec_version - end - - if remote_version.nil? - puts "There is no current released version. You're about to release a new Pod." - version = "0.0.1" - else - puts "The current released version of your pod is " + remote_spec_version.to_s() - version = suggested_version_number - end - - puts "Enter the version you want to release (" + version + ") " - new_version_number = $stdin.gets.strip - if new_version_number == "" - new_version_number = version - end - - replace_version_number(new_version_number) -end - -desc "Release a new version of the Pod" -task :release do - - puts "* Running version" - sh "rake version" - - unless ENV['SKIP_CHECKS'] - if `git symbolic-ref HEAD 2>/dev/null`.strip.split('/').last != 'master' - $stderr.puts "[!] You need to be on the `master' branch in order to be able to do a release." - exit 1 - end - - if `git tag`.strip.split("\n").include?(spec_version) - $stderr.puts "[!] A tag for version `#{spec_version}' already exists. Change the version in the podspec" - exit 1 - end - - puts "You are about to release `#{spec_version}`, is that correct? [y/n]" - exit if $stdin.gets.strip.downcase != 'y' - end - - puts "* Running specs" - sh "rake spec" - - puts "* Linting the podspec" - sh "pod lib lint" - - # Then release - sh "git commit #{podspec_path} CHANGELOG.md -m 'Release #{spec_version}'" - sh "git tag -a #{spec_version} -m 'Release #{spec_version}'" - sh "git push origin master" - sh "git push origin --tags" - sh "pod push master #{podspec_path}" -end - -# @return [Pod::Version] The version as reported by the Podspec. -# -def spec_version - require 'cocoapods' - spec = Pod::Specification.from_file(podspec_path) - spec.version -end - -# @return [Pod::Version] The version as reported by the Podspec from remote. -# -def remote_spec_version - require 'cocoapods-core' - - if spec_file_exist_on_remote? - remote_spec = eval(`git show origin/master:#{podspec_path}`) - remote_spec.version - else - nil - end -end - -# @return [Bool] If the remote repository has a copy of the podpesc file or not. -# -def spec_file_exist_on_remote? - test_condition = `if git rev-parse --verify --quiet origin/master:#{podspec_path} >/dev/null; - then - echo 'true' - else - echo 'false' - fi` - - 'true' == test_condition.strip -end - -# @return [String] The relative path of the Podspec. -# -def podspec_path - podspecs = Dir.glob('*.podspec') - if podspecs.count == 1 - podspecs.first - else - raise "Could not select a podspec" - end -end - -# @return [String] The suggested version number based on the local and remote version numbers. -# -def suggested_version_number - if spec_version != remote_spec_version - spec_version.to_s() - else - next_version(spec_version).to_s() - end -end - -# @param [Pod::Version] version -# the version for which you need the next version -# -# @note It is computed by bumping the last component of the versino string by 1. -# -# @return [Pod::Version] The version that comes next after the version supplied. -# -def next_version(version) - version_components = version.to_s().split("."); - last = (version_components.last.to_i() + 1).to_s - version_components[-1] = last - Pod::Version.new(version_components.join(".")) -end - -# @param [String] new_version_number -# the new version number -# -# @note This methods replaces the version number in the podspec file with a new version number. -# -# @return void -# -def replace_version_number(new_version_number) - text = File.read(podspec_path) - text.gsub!(/(s.version( )*= ")#{spec_version}(")/, "\\1#{new_version_number}\\3") - File.open(podspec_path, "w") { |file| file.puts text } -end \ No newline at end of file diff --git a/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj b/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj index c061fb3..5d18701 100644 --- a/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj +++ b/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj @@ -9,20 +9,6 @@ /* Begin PBXBuildFile section */ 2793762A18E8C3890059C103 /* OCDirectionsRequestURLCreatorJSONTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2793762918E8C3890059C103 /* OCDirectionsRequestURLCreatorJSONTests.m */; }; 27A8A2E718CF8B9900C24A6A /* OCDirectionsRequestTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 27A8A2E618CF8B9900C24A6A /* OCDirectionsRequestTests.m */; }; - 27A8A2E818CF8E8900C24A6A /* OCDirectionsRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E91718C65A580035B80F /* OCDirectionsRequest.m */; }; - 27A8A2E918CF8ED000C24A6A /* OCDirectionsCommonTypes.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E91018C65A580035B80F /* OCDirectionsCommonTypes.m */; }; - 27A8A2EA18CF8EDA00C24A6A /* OCDirectionsAPIClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E90918C65A580035B80F /* OCDirectionsAPIClient.m */; }; - 27A8A2EB18CF8EE000C24A6A /* OCDirectionsRequestURLCreatorJSON.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E90D18C65A580035B80F /* OCDirectionsRequestURLCreatorJSON.m */; }; - 27A8A2ED18CF8EE900C24A6A /* OCDirectionsBounds.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E91E18C65A580035B80F /* OCDirectionsBounds.m */; }; - 27A8A2EE18CF8EEC00C24A6A /* OCDirectionsDistance.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92018C65A580035B80F /* OCDirectionsDistance.m */; }; - 27A8A2EF18CF8EEE00C24A6A /* OCDirectionsDuration.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92218C65A580035B80F /* OCDirectionsDuration.m */; }; - 27A8A2F018CF8EF100C24A6A /* OCDirectionsLeg.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92418C65A580035B80F /* OCDirectionsLeg.m */; }; - 27A8A2F118CF8EF400C24A6A /* OCDirectionsPolyline.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92618C65A580035B80F /* OCDirectionsPolyline.m */; }; - 27A8A2F218CF8EF700C24A6A /* OCDirectionsRoute.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92818C65A580035B80F /* OCDirectionsRoute.m */; }; - 27A8A2F318CF8EFB00C24A6A /* OCDirectionsStep.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92A18C65A580035B80F /* OCDirectionsStep.m */; }; - 27A8A2F418CF8EFE00C24A6A /* OCDirectionsWaypoint.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92C18C65A580035B80F /* OCDirectionsWaypoint.m */; }; - 27A8A2F518CF8F0000C24A6A /* OCDirectionsResponse.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E92E18C65A580035B80F /* OCDirectionsResponse.m */; }; - 27A8A2F618CF8F0D00C24A6A /* CLLocation+CoortindateFromDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E93418C65A580035B80F /* CLLocation+CoortindateFromDictionary.m */; }; 27C6E8B618C6578B0035B80F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27C6E8B518C6578B0035B80F /* Foundation.framework */; }; 27C6E8C518C6578B0035B80F /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27C6E8B518C6578B0035B80F /* Foundation.framework */; }; 27C6EB8418C65A590035B80F /* OCDirectionsAPIClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E90918C65A580035B80F /* OCDirectionsAPIClient.m */; }; @@ -41,6 +27,7 @@ 27C6EBA018C65A590035B80F /* CLLocation+CoortindateFromDictionary.m in Sources */ = {isa = PBXBuildFile; fileRef = 27C6E93418C65A580035B80F /* CLLocation+CoortindateFromDictionary.m */; }; 27C6ECC118C65FDC0035B80F /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 27C6E8CE18C6578B0035B80F /* InfoPlist.strings */; }; 27C6ECCD18C67ACC0035B80F /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 27C6E8C318C6578B0035B80F /* XCTest.framework */; }; + 516C94BB1C9F2E8F0095322F /* libOCGoogleDirectionsAPI.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 27C6ECCB18C67A910035B80F /* libOCGoogleDirectionsAPI.a */; }; 524E8C2300316B8EBFB04BDB /* OCDirectionsFare.m in Sources */ = {isa = PBXBuildFile; fileRef = 524E8125ADC56AD2FA29F498 /* OCDirectionsFare.m */; }; /* End PBXBuildFile section */ @@ -137,6 +124,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 516C94BB1C9F2E8F0095322F /* libOCGoogleDirectionsAPI.a in Frameworks */, 27C6ECCD18C67ACC0035B80F /* XCTest.framework in Frameworks */, 27C6E8C518C6578B0035B80F /* Foundation.framework in Frameworks */, ); @@ -419,7 +407,7 @@ 27C6E87C18C654650035B80F /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0510; + LastUpgradeCheck = 0720; TargetAttributes = { 27C6E8C118C6578B0035B80F = { TestTargetID = 27C6E8DD18C658B70035B80F; @@ -482,22 +470,8 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 27A8A2EB18CF8EE000C24A6A /* OCDirectionsRequestURLCreatorJSON.m in Sources */, 27A8A2E718CF8B9900C24A6A /* OCDirectionsRequestTests.m in Sources */, - 27A8A2EE18CF8EEC00C24A6A /* OCDirectionsDistance.m in Sources */, - 27A8A2EF18CF8EEE00C24A6A /* OCDirectionsDuration.m in Sources */, - 27A8A2F518CF8F0000C24A6A /* OCDirectionsResponse.m in Sources */, - 27A8A2ED18CF8EE900C24A6A /* OCDirectionsBounds.m in Sources */, - 27A8A2F318CF8EFB00C24A6A /* OCDirectionsStep.m in Sources */, - 27A8A2EA18CF8EDA00C24A6A /* OCDirectionsAPIClient.m in Sources */, - 27A8A2F118CF8EF400C24A6A /* OCDirectionsPolyline.m in Sources */, - 27A8A2F618CF8F0D00C24A6A /* CLLocation+CoortindateFromDictionary.m in Sources */, - 27A8A2E918CF8ED000C24A6A /* OCDirectionsCommonTypes.m in Sources */, - 27A8A2F418CF8EFE00C24A6A /* OCDirectionsWaypoint.m in Sources */, - 27A8A2F018CF8EF100C24A6A /* OCDirectionsLeg.m in Sources */, - 27A8A2E818CF8E8900C24A6A /* OCDirectionsRequest.m in Sources */, 2793762A18E8C3890059C103 /* OCDirectionsRequestURLCreatorJSONTests.m in Sources */, - 27A8A2F218CF8EF700C24A6A /* OCDirectionsRoute.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -526,6 +500,7 @@ 27C6E88018C654650035B80F /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ENABLE_TESTABILITY = YES; INFOPLIST_FILE = "OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 7.0; ONLY_ACTIVE_ARCH = YES; @@ -579,6 +554,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 7.0; ONLY_ACTIVE_ARCH = YES; OTHER_LDFLAGS = "-ObjC"; + PRODUCT_BUNDLE_IDENTIFIER = "com.github.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -615,6 +591,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 7.0; OTHER_LDFLAGS = "-ObjC"; + PRODUCT_BUNDLE_IDENTIFIER = "com.github.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; SKIP_INSTALL = YES; @@ -639,11 +616,6 @@ CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - "$(DEVELOPER_FRAMEWORKS_DIR)", - ); GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; @@ -663,6 +635,7 @@ INFOPLIST_FILE = "OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 7.0; ONLY_ACTIVE_ARCH = YES; + PRODUCT_BUNDLE_IDENTIFIER = "cx.idev.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; TEST_HOST = "$(BUNDLE_LOADER)"; @@ -689,11 +662,6 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = YES; ENABLE_NS_ASSERTIONS = NO; - FRAMEWORK_SEARCH_PATHS = ( - "$(SDKROOT)/Developer/Library/Frameworks", - "$(inherited)", - "$(DEVELOPER_FRAMEWORKS_DIR)", - ); GCC_C_LANGUAGE_STANDARD = gnu99; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Prefix.pch"; @@ -705,6 +673,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; INFOPLIST_FILE = "OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 7.0; + PRODUCT_BUNDLE_IDENTIFIER = "cx.idev.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; TEST_HOST = "$(BUNDLE_LOADER)"; diff --git a/Source/OCGoogleDirectionsAPI.xcodeproj/xcshareddata/xcschemes/OCGoogleDirectionsAPI.xcscheme b/Source/OCGoogleDirectionsAPI.xcodeproj/xcshareddata/xcschemes/OCGoogleDirectionsAPI.xcscheme index 5355682..fa055a1 100644 --- a/Source/OCGoogleDirectionsAPI.xcodeproj/xcshareddata/xcschemes/OCGoogleDirectionsAPI.xcscheme +++ b/Source/OCGoogleDirectionsAPI.xcodeproj/xcshareddata/xcschemes/OCGoogleDirectionsAPI.xcscheme @@ -1,6 +1,6 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> + + + + + + + buildForProfiling = "YES" + buildForArchiving = "YES" + buildForAnalyzing = "YES"> + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -36,24 +39,36 @@ + + + + + + - - CFBundleDevelopmentRegion - English - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIconFile - - CFBundleIdentifier - com.github.${PRODUCT_NAME:rfc1034identifier} - CFBundleInfoDictionaryVersion - 6.0 - CFBundleName - ${PRODUCT_NAME} - CFBundlePackageType - FMWK - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - NSHumanReadableCopyright - Copyright © 2014 Marcin Iwanicki. All rights reserved. - NSPrincipalClass - - + + CFBundleDevelopmentRegion + English + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + ${PRODUCT_NAME} + CFBundlePackageType + FMWK + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + NSHumanReadableCopyright + Copyright © 2014 Marcin Iwanicki. All rights reserved. + NSPrincipalClass + + diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m index 26d8ff9..4fdf19f 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsRoute.m @@ -99,7 +99,7 @@ - (void)loadSummary { } - (void)loadFare { - NSDictionary *fareDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeFare]: + NSDictionary *fareDictionary = [_dictionary objectForKey:kCGGoogleDirectionsResponseAttributeFare]; if (fareDictionary) { OCDirectionsFare *fare = [OCDirectionsFare fareFromDictionary:fareDictionary]; diff --git a/Source/OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist b/Source/OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist index 99d20ce..169b6f7 100644 --- a/Source/OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist +++ b/Source/OCGoogleDirectionsAPITests/OCGoogleDirectionsAPITests-Info.plist @@ -1,22 +1,22 @@ - - CFBundleDevelopmentRegion - en - CFBundleExecutable - ${EXECUTABLE_NAME} - CFBundleIdentifier - cx.idev.${PRODUCT_NAME:rfc1034identifier} - CFBundleInfoDictionaryVersion - 6.0 - CFBundlePackageType - BNDL - CFBundleShortVersionString - 1.0 - CFBundleSignature - ???? - CFBundleVersion - 1 - + + CFBundleDevelopmentRegion + en + CFBundleExecutable + ${EXECUTABLE_NAME} + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + From 3aa5d9dda612dfbe0b298d6e1b3c385d1bd7cc76 Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sun, 20 Mar 2016 19:33:03 +0000 Subject: [PATCH 11/15] Use more restrictive build flags. --- Source/OCGoogleDirectionsAPI.xcconfig | 94 +++++++++++++++++++ .../project.pbxproj | 4 + .../Client/OCDirectionsAPIClient.m | 2 +- .../Common/OCDirectionsCommonTypes.h | 2 +- .../Common/OCDirectionsRequestTrafficModel.h | 2 +- .../Common/OCDirectionsRequestTransitMode.h | 2 +- ...irectionsRequestTransitRoutingPreference.h | 2 +- .../Common/OCDirectionsRequestTravelMode.h | 2 +- .../Common/OCDirectionsRequestUnit.h | 2 +- .../Request/OCDirectionsRequest.h | 2 +- .../Response/Attributes/OCDirectionsFare.h | 2 +- .../Response/Attributes/OCDirectionsFare.m | 2 +- .../Response/OCDirectionsResponse.m | 2 +- .../Assertions/OCAssertParameter.h | 2 +- 14 files changed, 110 insertions(+), 12 deletions(-) create mode 100644 Source/OCGoogleDirectionsAPI.xcconfig diff --git a/Source/OCGoogleDirectionsAPI.xcconfig b/Source/OCGoogleDirectionsAPI.xcconfig new file mode 100644 index 0000000..5183934 --- /dev/null +++ b/Source/OCGoogleDirectionsAPI.xcconfig @@ -0,0 +1,94 @@ +// XcodeWarnings by Jon Reid, http://qualitycoding.org/about/ +// Source: https://github.com/jonreid/XcodeWarnings + +// Apple LLVM 7.0 - Warning Policies +GCC_TREAT_WARNINGS_AS_ERRORS = YES + +// Apple LLVM 7.0 - Warnings - All languages +GCC_WARN_CHECK_SWITCH_STATEMENTS = YES +GCC_WARN_ABOUT_DEPRECATED_FUNCTIONS = YES +CLANG_WARN_DOCUMENTATION_COMMENTS = YES +CLANG_WARN_EMPTY_BODY = YES +GCC_WARN_FOUR_CHARACTER_CONSTANTS = YES +GCC_WARN_SHADOW = YES +CLANG_WARN_BOOL_CONVERSION = YES +CLANG_WARN_CONSTANT_CONVERSION = YES +GCC_WARN_64_TO_32_BIT_CONVERSION = YES +CLANG_WARN_ENUM_CONVERSION = YES +CLANG_WARN_INT_CONVERSION = YES +CLANG_WARN_IMPLICIT_SIGN_CONVERSION = YES +CLANG_WARN_NULLABLE_TO_NONNULL_CONVERSION = YES +GCC_WARN_INITIALIZER_NOT_FULLY_BRACKETED = YES +GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR +GCC_WARN_MISSING_PARENTHESES = YES +GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES +GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES +GCC_WARN_ABOUT_MISSING_NEWLINE = YES +CLANG_WARN_ASSIGN_ENUM = YES +GCC_WARN_ABOUT_POINTER_SIGNEDNESS = YES +GCC_WARN_SIGN_COMPARE = YES +CLANG_WARN_SUSPICIOUS_IMPLICIT_CONVERSION = YES +GCC_TREAT_INCOMPATIBLE_POINTER_TYPE_WARNINGS_AS_ERRORS = YES +GCC_TREAT_IMPLICIT_FUNCTION_DECLARATIONS_AS_ERRORS = YES +GCC_WARN_TYPECHECK_CALLS_TO_PRINTF = YES +GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE +GCC_WARN_UNKNOWN_PRAGMAS = YES +CLANG_WARN_UNREACHABLE_CODE = YES +GCC_WARN_UNUSED_FUNCTION = YES +GCC_WARN_UNUSED_LABEL = YES +//GCC_WARN_UNUSED_PARAMETER = YES +GCC_WARN_UNUSED_VALUE = YES +GCC_WARN_UNUSED_VARIABLE = YES + +// Apple LLVM 7.0 - Warnings - C++ +CLANG_WARN__EXIT_TIME_DESTRUCTORS = YES +GCC_WARN_NON_VIRTUAL_DESTRUCTOR = YES +GCC_WARN_HIDDEN_VIRTUAL_FUNCTIONS = YES +GCC_WARN_ABOUT_INVALID_OFFSETOF_MACRO = YES +CLANG_WARN_CXX0X_EXTENSIONS = YES + +// Apple LLVM 7.0 - Warnings - Objective-C +CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR +CLANG_WARN__DUPLICATE_METHOD_MATCH = YES +CLANG_WARN_OBJC_IMPLICIT_ATOMIC_PROPERTIES = YES +GCC_WARN_ALLOW_INCOMPLETE_PROTOCOL = YES +//GCC_WARN_MULTIPLE_DEFINITION_TYPES_FOR_SELECTOR = YES +CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES +GCC_WARN_STRICT_SELECTOR_MATCH = YES +GCC_WARN_UNDECLARED_SELECTOR = YES +CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR + +// Apple LLVM 7.0 - Warnings - Objective-C and ARC +CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = YES +CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES +CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = YES +CLANG_WARN__ARC_BRIDGE_CAST_NONARC = YES + +// Static Analyzer - Analysis Policy +RUN_CLANG_STATIC_ANALYZER = YES +CLANG_STATIC_ANALYZER_MODE_ON_ANALYZE_ACTION = Deep +CLANG_STATIC_ANALYZER_MODE = Deep + +// Static Analyzer - Generic Issues +CLANG_ANALYZER_DEADCODE_DEADSTORES = YES +CLANG_ANALYZER_MEMORY_MANAGEMENT = YES +CLANG_ANALYZER_GCD = YES + +// Static Analyzer - Checks - Objective-C +CLANG_ANALYZER_OBJC_ATSYNC = YES +CLANG_ANALYZER_OBJC_NSCFERROR = YES +CLANG_ANALYZER_OBJC_INCOMP_METHOD_TYPES = YES +CLANG_ANALYZER_OBJC_COLLECTIONS = YES +CLANG_ANALYZER_OBJC_UNUSED_IVARS = YES +CLANG_ANALYZER_OBJC_SELF_INIT = YES +CLANG_ANALYZER_OBJC_RETAIN_COUNT = YES + +// Static Analyzer - Checks - Security +CLANG_ANALYZER_SECURITY_FLOATLOOPCOUNTER = YES +CLANG_ANALYZER_SECURITY_KEYCHAIN_API = YES +CLANG_ANALYZER_SECURITY_INSECUREAPI_UNCHECKEDRETURN = YES +CLANG_ANALYZER_SECURITY_INSECUREAPI_GETPW_GETS = YES +CLANG_ANALYZER_SECURITY_INSECUREAPI_MKSTEMP = YES +CLANG_ANALYZER_SECURITY_INSECUREAPI_RAND = YES +CLANG_ANALYZER_SECURITY_INSECUREAPI_STRCPY = YES +CLANG_ANALYZER_SECURITY_INSECUREAPI_VFORK = YES diff --git a/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj b/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj index 5d18701..6f8e4c8 100644 --- a/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj +++ b/Source/OCGoogleDirectionsAPI.xcodeproj/project.pbxproj @@ -104,6 +104,7 @@ 27C6ECC318C6608E0035B80F /* OCGoogleDirectionsAPI-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "OCGoogleDirectionsAPI-Info.plist"; sourceTree = ""; }; 27C6ECCB18C67A910035B80F /* libOCGoogleDirectionsAPI.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libOCGoogleDirectionsAPI.a; sourceTree = BUILT_PRODUCTS_DIR; }; 27C6ECCC18C67A910035B80F /* OCGoogleDirectionsAPITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = OCGoogleDirectionsAPITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 516C94BC1C9F31550095322F /* OCGoogleDirectionsAPI.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = OCGoogleDirectionsAPI.xcconfig; sourceTree = ""; }; 524E8125ADC56AD2FA29F498 /* OCDirectionsFare.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OCDirectionsFare.m; sourceTree = ""; }; 524E82C69FF2B59CF5097950 /* OCDirectionsRequestTrafficModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsRequestTrafficModel.h; sourceTree = ""; }; 524E8A60179A39E791889072 /* OCDirectionsRequestTransitRoutingPreference.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OCDirectionsRequestTransitRoutingPreference.h; sourceTree = ""; }; @@ -182,6 +183,7 @@ 27C6E87B18C654650035B80F = { isa = PBXGroup; children = ( + 516C94BC1C9F31550095322F /* OCGoogleDirectionsAPI.xcconfig */, 27C6E8B718C6578B0035B80F /* OCGoogleDirectionsAPI */, 27C6E8CB18C6578B0035B80F /* OCGoogleDirectionsAPITests */, 27C6E8B418C6578B0035B80F /* Frameworks */, @@ -499,6 +501,7 @@ /* Begin XCBuildConfiguration section */ 27C6E88018C654650035B80F /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 516C94BC1C9F31550095322F /* OCGoogleDirectionsAPI.xcconfig */; buildSettings = { ENABLE_TESTABILITY = YES; INFOPLIST_FILE = "OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Info.plist"; @@ -510,6 +513,7 @@ }; 27C6E88118C654650035B80F /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 516C94BC1C9F31550095322F /* OCGoogleDirectionsAPI.xcconfig */; buildSettings = { INFOPLIST_FILE = "OCGoogleDirectionsAPI/OCGoogleDirectionsAPI-Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 7.0; diff --git a/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m b/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m index 0490fff..ba26e1e 100644 --- a/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m +++ b/Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m @@ -64,7 +64,7 @@ - (void)directions:(OCDirectionsRequest *)request response:(OCDirectionsRequestC } NSError *jsonParsingError = nil; - NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&jsonParsingError]; + NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&jsonParsingError]; if (jsonParsingError) { callback(nil, jsonParsingError); diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h index 08eaa17..431ac03 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsCommonTypes.h @@ -60,4 +60,4 @@ + (NSDictionary *)transitRoutingPreferenceDictionary; -@end \ No newline at end of file +@end diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTrafficModel.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTrafficModel.h index c9d7fda..37b464e 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTrafficModel.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTrafficModel.h @@ -31,4 +31,4 @@ typedef NS_ENUM(NSUInteger, OCDirectionsRequestTrafficModel) { * though occasional days with particularly good traffic conditions may be faster than this value. */ OCDirectionsRequestTrafficModelOptimistic -}; \ No newline at end of file +}; diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h index b079488..773f1dc 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitMode.h @@ -37,4 +37,4 @@ typedef NS_OPTIONS(NSUInteger, OCDirectionsRequestTransitMode) { * This is equivalent to train|tram|subway. */ OCDirectionsRequestTransitModeRail = 1 << 5 -}; \ No newline at end of file +}; diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitRoutingPreference.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitRoutingPreference.h index 3190ce1..fd48b42 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitRoutingPreference.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTransitRoutingPreference.h @@ -22,4 +22,4 @@ typedef NS_ENUM(NSUInteger, OCDirectionsRequestTransitRoutingPreference) { * indicates that the calculated route should prefer a limited number of transfers. */ OCDirectionsRequestTransitRoutingPreferenceFewerTransfers -}; \ No newline at end of file +}; diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTravelMode.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTravelMode.h index 0cb491c..dd66005 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTravelMode.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestTravelMode.h @@ -26,4 +26,4 @@ typedef NS_ENUM(NSUInteger, OCDirectionsRequestTravelMode) { requests directions via public transit routes (where available). */ OCDirectionsRequestTravelModeTransit -}; \ No newline at end of file +}; diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestUnit.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestUnit.h index 3904e26..aa9ac75 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestUnit.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestUnit.h @@ -21,4 +21,4 @@ typedef NS_ENUM(NSUInteger, OCDirectionsRequestUnit) { specifies usage of the Imperial (English) system. Textual distances are returned using miles and feet. */ OCDirectionsRequestUnitImperial -}; \ No newline at end of file +}; diff --git a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h index 7900e92..ed09c45 100644 --- a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h +++ b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h @@ -158,4 +158,4 @@ + (NSDate *)departureTimeNow; -@end \ No newline at end of file +@end diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.h b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.h index 1a697e6..d3ed1b0 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.h +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.h @@ -27,4 +27,4 @@ extern NSString *const kCGGoogleDirectionsResponseAttributeFare; + (instancetype)fareFromDictionary:(NSDictionary *)dictionary; -@end \ No newline at end of file +@end diff --git a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.m b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.m index 4d10e6a..1d8159f 100644 --- a/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.m +++ b/Source/OCGoogleDirectionsAPI/Response/Attributes/OCDirectionsFare.m @@ -54,4 +54,4 @@ - (void)loadValue { _value = value; } -@end \ No newline at end of file +@end diff --git a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m index 2be9f77..982be4a 100644 --- a/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m +++ b/Source/OCGoogleDirectionsAPI/Response/OCDirectionsResponse.m @@ -85,4 +85,4 @@ - (void)loadErrorMessage { _errorMessage = errorMessage; } -@end \ No newline at end of file +@end diff --git a/Source/OCGoogleDirectionsAPI/Shared Classes/Assertions/OCAssertParameter.h b/Source/OCGoogleDirectionsAPI/Shared Classes/Assertions/OCAssertParameter.h index d27942c..5ca777e 100644 --- a/Source/OCGoogleDirectionsAPI/Shared Classes/Assertions/OCAssertParameter.h +++ b/Source/OCGoogleDirectionsAPI/Shared Classes/Assertions/OCAssertParameter.h @@ -9,4 +9,4 @@ #import #define OCAssertParameter(condition, args...) if (!condition) [NSException raise:NSInvalidArgumentException format:args]; -#define OCAssertParameterNotNil(parameter, args...) OCAssertParameter(parameter, args); \ No newline at end of file +#define OCAssertParameterNotNil(parameter, args...) OCAssertParameter(parameter, args); From 5ae5c3d0d6796a0daada299bce1cd5f39c442a47 Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sun, 20 Mar 2016 20:26:05 +0000 Subject: [PATCH 12/15] Fix typo. --- .../Common/OCDirectionsRequestRestriction.h | 2 +- Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestRestriction.h b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestRestriction.h index 5df695c..2d94119 100644 --- a/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestRestriction.h +++ b/Source/OCGoogleDirectionsAPI/Common/OCDirectionsRequestRestriction.h @@ -20,5 +20,5 @@ typedef NS_ENUM(NSUInteger, OCDirectionsRequestRestriction) { /** avoid ferries */ - OCDirectionsRequestRestrictionAviodFerries + OCDirectionsRequestRestrictionAvoidFerries }; diff --git a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h index ed09c45..3125721 100644 --- a/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h +++ b/Source/OCGoogleDirectionsAPI/Request/OCDirectionsRequest.h @@ -55,7 +55,7 @@ /** * Directions may be calculated that adhere to certain restrictions. * Use an array of DirectionsRequestRestriction types ie. - * @[DirectionsRequestAvoidTollsRestriction, DirectionsRequestAviodFerriesRestriction] + * @[DirectionsRequestAvoidTollsRestriction, DirectionsRequestAvoidFerriesRestriction] */ @property (nonatomic) NSArray *restrictions; From 245b0eb3c2b0f18742d4b5a329316104fcdf355a Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sun, 20 Mar 2016 20:26:28 +0000 Subject: [PATCH 13/15] Update CHANGELOG. --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21c3c6c..50a614d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,10 @@ ## 0.1.5 -- - +- Added scripts to build and run tests (Bin/run-build.sh, Bin/run-tests.sh) +- Added fare and duration_in_traffic to response +- Added transit_mode, transit_routing_preference, traffic_model, arrival_time, +departure_time to request ## 0.1.2 From 589ee605abae2965906c4eed1fa23aa9a34c18fa Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sun, 20 Mar 2016 20:34:13 +0000 Subject: [PATCH 14/15] Update README and podspec. --- OCGoogleDirectionsAPI.podspec | 4 +-- README.md | 51 +++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/OCGoogleDirectionsAPI.podspec b/OCGoogleDirectionsAPI.podspec index 5f70a8f..0170091 100644 --- a/OCGoogleDirectionsAPI.podspec +++ b/OCGoogleDirectionsAPI.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = "OCGoogleDirectionsAPI" - s.version = "0.1.4" + s.version = "0.1.5" s.summary = "A lightweight wrapper for The Google Directions API." s.homepage = "https://github.com/marciniwanicki/OCGoogleDirectionsAPI" s.license = 'MIT' s.author = { "Marcin Iwanicki" => "marcin.iwanicki@appliwings.com" } - s.source = { :git => "https://github.com/marciniwanicki/OCGoogleDirectionsAPI.git", :tag => "0.1.4" } + s.source = { :git => "https://github.com/marciniwanicki/OCGoogleDirectionsAPI.git", :tag => "0.1.5" } s.ios.deployment_target = '7.0' s.requires_arc = true diff --git a/README.md b/README.md index 71dc8eb..8784690 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ As Google wrote: "The Google Directions API is a service that calculates directions between locations using an HTTP request. You can search for directions for several modes of transportation, include transit, driving, walking or cycling. Directions may specify origins, destinations and waypoints either as text strings (e.g. "Chicago, IL" or "Darwin, NT, Australia") or as latitude/longitude coordinates. The Directions API can return multi-part directions using a series of waypoints." -# 0.1.4 +# 0.1.5 The OCGoogleDirectionsAPI library allows your iOS apps to deal with this powerful service easily. IMPORTANT: It uses `NSURLSession` only available in iOS 7.0+. It is not compatible with iOS 6.x and lower. @@ -87,19 +87,11 @@ To create an isntance of `OCDirectionsRequest` you can use one of the following ```objc + (instancetype)requestWithOriginLocation:(CLLocation *)origin andDestinationLocation:(CLLocation *)destination; -+ (instancetype)requestWithOriginLocation:(CLLocation *)origin andDestinationLocation:(CLLocation *)destination sensor:(BOOL)sensor; - + (instancetype)requestWithOriginString:(NSString *)origin andDestinationLocation:(CLLocation *)destination; -+ (instancetype)requestWithOriginString:(NSString *)origin andDestinationLocation:(CLLocation *)destination sensor:(BOOL)sensor; - + (instancetype)requestWithOriginLocation:(CLLocation *)origin andDestinationString:(NSString *)destination; -+ (instancetype)requestWithOriginLocation:(CLLocation *)origin andDestinationString:(NSString *)destination sensor:(BOOL)sensor; - + (instancetype)requestWithOriginString:(NSString *)origin andDestinationString:(NSString *)destination; - -+ (instancetype)requestWithOriginString:(NSString *)origin andDestinationString:(NSString *)destination sensor:(BOOL)sensor; ``` ### Request attributes @@ -127,7 +119,7 @@ Here you can find the list of supported languages: [https://developers.google.co There are 3 different restrictions: * `OCDirectionsRequestRestrictionAvoidTolls` * `OCDirectionsRequestRestrictionAvoidHighways` -* `OCDirectionsRequestRestrictionAviodFerries` +* `OCDirectionsRequestRestrictionAvoidFerries` You can ask to avoid one or even all of them by calling the `setRestrictions:` method. @@ -174,6 +166,25 @@ CLLocation *secondLocation = [[CLLocation alloc] initWithLatitude:51.1314 longit [request setWaypointsOptimise:YES]; ``` +### Traffic model + +```objc +[request setTrafficModel:OCDirectionsRequestTrafficModelOptimistic]; +``` + +### Transit mode + +```objc +[request setTransitMode:OCDirectionsRequestTransitModeBus | OCDirectionsRequestTransitModeTrain]; +``` + +### Transit routing preference + +```objc +[request setTransitRoutingPreference:OCDirectionsRequestTransitRoutingPreferenceFewerTransfers]; +``` + + ## Response @@ -188,6 +199,7 @@ Classes: * [OCDirectionsDuration](#ocdirectionsduration) * [OCDirectionsStep](#ocdirectionsstep) * [OCDirectionsWaypoint](#ocdirectionswaypoint) +* [OCDirectionsFare](#ocdirectionsfare) ### OCDirectionsResponse @@ -199,6 +211,7 @@ Properties: * errorMessage `NSString*` * route `NSDirectionsRoute*` +Be aware that `geocoded_waypoints` property is not supported in the current version (#8). ### OCDirectionsResponseStatus @@ -233,6 +246,7 @@ Properties: * dictionary `NSDictionary*` * distance `OCDirectionsDistance*` * duration `OCDirectionsDuration*` +* durationInTraffic `OCDirectionsDuration*` * endAddress `NSString*` * endLocation `OCLocationCoordinate2D` * startAddress `NSString*` @@ -262,9 +276,9 @@ Properties: * dictionary `NSDictionary*` * text `NSString*` * value `NSNumber*` + - -### OCDirectionsDuration +### OCDirectionsDuration Properties: * dictionary `NSDictionary*` @@ -295,11 +309,20 @@ Properties: * stepInterpolation `NSNumber*` +### OCDirectionsFare + +Properties: +* dictionary `NSDictionary*` +* currency `NSString*` +* text `NSString*` +* value `NSNumber*` + + ## Contact -Did you find a bug? Do you have great ideas how to make the library better? or you just want to say hello:) ... please do not hesitate to contact me via mail marcin.iwanicki[at]live.com or twitter @marciniwanicki. +Did you find a bug? Do you have great ideas how to make the library better? or you just want to say hello:) ... drop me a line on twitter @marciniwanicki. -## To Do +## TODO * Add samples. * Write unit tests. From 571f6692d959461b868d02c1e39baa03a7d7b6ff Mon Sep 17 00:00:00 2001 From: Marcin Iwanicki Date: Sun, 20 Mar 2016 20:38:09 +0000 Subject: [PATCH 15/15] Update README. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8784690..81f1f9e 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ The OCGoogleDirectionsAPI library allows your iOS apps to deal with this powerfu #### Podfile ```ruby platform :ios, '7.0' -pod "OCGoogleDirectionsAPI", "~> 0.1.4" +pod "OCGoogleDirectionsAPI", "~> 0.1.5" ``` ## How to get started