Skip to content

Commit fe64f19

Browse files
author
Marcin Iwanicki
committed
Not provided key is represented as nil.
1 parent e92c3f2 commit fe64f19

File tree

4 files changed

+10
-25
lines changed

4 files changed

+10
-25
lines changed

Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#import "OCDirectionsRequestURLCreator.h"
1313
#import "OCDirectionsRequestURLCreatorJSON.h"
1414

15-
extern NSString *const kOCDirectionsAPIClientAPIKeyNotProvided;
16-
1715
typedef void (^OCDirectionsRequestCallback)(OCDirectionsResponse *response, NSError *error);
1816

1917
@interface OCDirectionsAPIClient : NSObject

Source/OCGoogleDirectionsAPI/Client/OCDirectionsAPIClient.m

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88

99
#import "OCDirectionsAPIClient.h"
1010

11-
NSString *const kOCDirectionsAPIClientAPIKeyNotProvided = @"";
12-
1311
@interface OCDirectionsAPIClient ()
1412

1513
@property (nonatomic, copy) NSString *key;
@@ -23,17 +21,17 @@ @implementation OCDirectionsAPIClient
2321

2422
- (instancetype)init
2523
{
26-
return [self initWithKey:_defaultKey?:kOCDirectionsAPIClientAPIKeyNotProvided];
24+
return [self initWithKey:_defaultKey];
2725
}
2826

2927
- (instancetype)initWithNoKey
3028
{
31-
return [self initWithKey:kOCDirectionsAPIClientAPIKeyNotProvided];
29+
return [self initWithKey:nil];
3230
}
3331

3432
- (instancetype)initWithNoKeyUseHttps:(BOOL)useHttps
3533
{
36-
return [self initWithKey:kOCDirectionsAPIClientAPIKeyNotProvided useHttps:useHttps];
34+
return [self initWithKey:nil useHttps:useHttps];
3735
}
3836

3937
- (instancetype)initWithKey:(NSString *)key

Source/OCGoogleDirectionsAPI/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSON.m

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ @implementation OCDirectionsRequestURLCreatorJSON
3333
- (NSString *)stringFromRequest:(OCDirectionsRequest *)request useHttps:(BOOL)useHttps andKey:(NSString *)key
3434
{
3535
OCAssertParameterNotNil(request, @"Request is nil.");
36-
OCAssertParameterNotNil(key, @"Key is nil.");
3736

3837
NSMutableString *string = [self baseStringWithHttps:useHttps];
3938

@@ -222,9 +221,9 @@ - (void)appendAlternatives:(OCDirectionsRequest *)request toString:(NSMutableStr
222221
- (void)appendKey:(NSString *)key toString:(NSMutableString *)string
223222
{
224223
/**
225-
API key is not requred. Empty string when key is not provided.
224+
API key is not requred.
226225
*/
227-
if (key.length) {
226+
if (key) {
228227
[string appendString:kOCGoogleDirectionsRequestAttributeKey];
229228
[string appendString:key];
230229
}

Source/OCGoogleDirectionsAPITests/Client/RequestURLCreator/OCDirectionsRequestURLCreatorJSONTests.m

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ - (void)testStringFromRequestWhenKeyIsNil
6262
OCDirectionsRequest *request = [self prepareRequest];
6363
NSString *key = nil;
6464

65+
// when
66+
NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key];
67+
6568
// then
66-
XCTAssertThrowsSpecificNamed([self.urlCreator stringFromRequest:request useHttps:YES andKey:key], NSException, NSInvalidArgumentException);
69+
XCTAssertNotNil(response);
70+
XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false", response);
6771
}
6872

6973
- (void)testStringFromRequestWhenRequestAndKeyAreNil
@@ -76,20 +80,6 @@ - (void)testStringFromRequestWhenRequestAndKeyAreNil
7680
XCTAssertThrowsSpecificNamed([self.urlCreator stringFromRequest:request useHttps:YES andKey:key], NSException, NSInvalidArgumentException);
7781
}
7882

79-
- (void)testStringFromRequestWhenKeyIsNotProvided
80-
{
81-
// given
82-
OCDirectionsRequest *request = [self prepareRequest];
83-
NSString *key = @"";
84-
85-
// when
86-
NSString *response = [self.urlCreator stringFromRequest:request useHttps:YES andKey:key];
87-
88-
// then
89-
XCTAssertNotNil(response);
90-
XCTAssertEqualObjects(@"https://maps.googleapis.com/maps/api/directions/json?origin=London&destination=Lodz&sensor=false", response);
91-
}
92-
9383
#pragma mark - Test stringFromRequest:useHttps:andKey: when arguments are valid
9484
- (void)testStringFromRequestWhenAllArgumentsAreValid
9585
{

0 commit comments

Comments
 (0)