Skip to content

Commit b0f9b49

Browse files
committed
Merge pull request #827 from ParsePlatform/nlutsenko.nullable.clientkey
Allow clientKey to be nil, as it's not explicitly required for Open Parse Server.
2 parents 5af822b + 5d47fc6 commit b0f9b49

File tree

11 files changed

+41
-45
lines changed

11 files changed

+41
-45
lines changed

Parse/Internal/Commands/CommandRunner/PFCommandRunning.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ NS_ASSUME_NONNULL_BEGIN
4343

4444
- (instancetype)initWithDataSource:(id<PFInstallationIdentifierStoreProvider>)dataSource
4545
applicationId:(NSString *)applicationId
46-
clientKey:(NSString *)clientKey
46+
clientKey:(nullable NSString *)clientKey
4747
serverURL:(NSURL *)serverURL;
4848
+ (instancetype)commandRunnerWithDataSource:(id<PFInstallationIdentifierStoreProvider>)dataSource
4949
applicationId:(NSString *)applicationId
50-
clientKey:(NSString *)clientKey
50+
clientKey:(nullable NSString *)clientKey
5151
serverURL:(NSURL *)serverURL;
5252

5353
///--------------------------------------

Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
@class BFTask<__covariant BFGenericType>;
1717
@class PFRESTCommand;
1818

19+
NS_ASSUME_NONNULL_BEGIN
20+
1921
@interface PFCommandURLRequestConstructor : NSObject
2022

2123
@property (nonatomic, weak, readonly) id<PFInstallationIdentifierStoreProvider> dataSource;
@@ -49,7 +51,9 @@
4951
///--------------------------------------
5052

5153
+ (NSDictionary *)defaultURLRequestHeadersForApplicationId:(NSString *)applicationId
52-
clientKey:(NSString *)clientKey
54+
clientKey:(nullable NSString *)clientKey
5355
bundle:(NSBundle *)bundle;
5456

5557
@end
58+
59+
NS_ASSUME_NONNULL_END

Parse/Internal/Commands/CommandRunner/URLRequestConstructor/PFCommandURLRequestConstructor.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ + (instancetype)constructorWithDataSource:(id<PFInstallationIdentifierStoreProvi
115115
///--------------------------------------
116116

117117
+ (NSDictionary *)defaultURLRequestHeadersForApplicationId:(NSString *)applicationId
118-
clientKey:(NSString *)clientKey
118+
clientKey:(nullable NSString *)clientKey
119119
bundle:(NSBundle *)bundle {
120120
#if TARGET_OS_IOS
121121
NSString *versionPrefix = @"i";
@@ -130,7 +130,9 @@ + (NSDictionary *)defaultURLRequestHeadersForApplicationId:(NSString *)applicati
130130
NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary];
131131

132132
mutableHeaders[PFCommandHeaderNameApplicationId] = applicationId;
133-
mutableHeaders[PFCommandHeaderNameClientKey] = clientKey;
133+
if (clientKey) {
134+
mutableHeaders[PFCommandHeaderNameClientKey] = clientKey;
135+
}
134136

135137
mutableHeaders[PFCommandHeaderNameClientVersion] = [versionPrefix stringByAppendingString:PARSE_VERSION];
136138
mutableHeaders[PFCommandHeaderNameOSVersion] = [PFDevice currentDevice].operatingSystemFullVersion;

Parse/Internal/Commands/CommandRunner/URLSession/PFURLSessionCommandRunner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
2121
+ (instancetype)commandRunnerWithDataSource:(id<PFInstallationIdentifierStoreProvider>)dataSource
2222
retryAttempts:(NSUInteger)retryAttempts
2323
applicationId:(NSString *)applicationId
24-
clientKey:(NSString *)clientKey
24+
clientKey:(nullable NSString *)clientKey
2525
serverURL:(NSURL *)serverURL;
2626

2727
@end

Parse/Internal/Commands/CommandRunner/URLSession/PFURLSessionCommandRunner.m

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ @implementation PFURLSessionCommandRunner
5050

5151
- (instancetype)initWithDataSource:(id<PFInstallationIdentifierStoreProvider>)dataSource
5252
applicationId:(NSString *)applicationId
53-
clientKey:(NSString *)clientKey
54-
serverURL:(nonnull NSURL *)serverURL {
53+
clientKey:(nullable NSString *)clientKey
54+
serverURL:(NSURL *)serverURL {
5555
return [self initWithDataSource:dataSource
5656
retryAttempts:PFCommandRunningDefaultMaxAttemptsCount
5757
applicationId:applicationId
@@ -62,10 +62,9 @@ - (instancetype)initWithDataSource:(id<PFInstallationIdentifierStoreProvider>)da
6262
- (instancetype)initWithDataSource:(id<PFInstallationIdentifierStoreProvider>)dataSource
6363
retryAttempts:(NSUInteger)retryAttempts
6464
applicationId:(NSString *)applicationId
65-
clientKey:(NSString *)clientKey
65+
clientKey:(nullable NSString *)clientKey
6666
serverURL:(NSURL *)serverURL {
67-
NSURLSessionConfiguration *configuration = [[self class] _urlSessionConfigurationForApplicationId:applicationId
68-
clientKey:clientKey];
67+
NSURLSessionConfiguration *configuration = [[self class] _urlSessionConfigurationForApplicationId:applicationId clientKey:clientKey];
6968

7069
PFURLSession *session = [PFURLSession sessionWithConfiguration:configuration delegate:self];
7170
PFCommandURLRequestConstructor *constructor = [PFCommandURLRequestConstructor constructorWithDataSource:dataSource serverURL:serverURL];
@@ -102,15 +101,15 @@ - (instancetype)initWithDataSource:(id<PFInstallationIdentifierStoreProvider>)da
102101

103102
+ (instancetype)commandRunnerWithDataSource:(id<PFInstallationIdentifierStoreProvider>)dataSource
104103
applicationId:(NSString *)applicationId
105-
clientKey:(NSString *)clientKey
104+
clientKey:(nullable NSString *)clientKey
106105
serverURL:(nonnull NSURL *)serverURL {
107106
return [[self alloc] initWithDataSource:dataSource applicationId:applicationId clientKey:clientKey serverURL:serverURL];
108107
}
109108

110109
+ (instancetype)commandRunnerWithDataSource:(id<PFInstallationIdentifierStoreProvider>)dataSource
111110
retryAttempts:(NSUInteger)retryAttempts
112111
applicationId:(NSString *)applicationId
113-
clientKey:(NSString *)clientKey
112+
clientKey:(nullable NSString *)clientKey
114113
serverURL:(nonnull NSURL *)serverURL {
115114
return [[self alloc] initWithDataSource:dataSource
116115
retryAttempts:retryAttempts
@@ -255,7 +254,7 @@ - (BFTask *)_performCommandRunningBlock:(nonnull id (^)())block
255254
///--------------------------------------
256255

257256
+ (NSURLSessionConfiguration *)_urlSessionConfigurationForApplicationId:(NSString *)applicationId
258-
clientKey:(NSString *)clientKey {
257+
clientKey:(nullable NSString *)clientKey {
259258
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
260259

261260
// No cookies, they are bad for you.

Parse/Internal/ParseModule.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99

1010
#import <Foundation/Foundation.h>
1111

12+
NS_ASSUME_NONNULL_BEGIN
13+
1214
@protocol ParseModule <NSObject>
1315

14-
- (void)parseDidInitializeWithApplicationId:(NSString *)applicationId clientKey:(NSString *)clientKey;
16+
- (void)parseDidInitializeWithApplicationId:(NSString *)applicationId clientKey:(nullable NSString *)clientKey;
1517

1618
@end
1719

@@ -25,3 +27,5 @@
2527
- (BOOL)containsModule:(id<ParseModule>)module;
2628

2729
@end
30+
31+
NS_ASSUME_NONNULL_END

Parse/Internal/ParseModule.m

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#import "ParseModule.h"
1111

12+
NS_ASSUME_NONNULL_BEGIN
13+
1214
///--------------------------------------
1315
#pragma mark - ParseModuleCollection
1416
///--------------------------------------
@@ -30,10 +32,11 @@ @implementation ParseModuleCollection
3032

3133
- (instancetype)init {
3234
self = [super init];
33-
if (self) {
34-
_collectionQueue = dispatch_queue_create("com.parse.ParseModuleCollection", DISPATCH_QUEUE_SERIAL);
35-
_modules = [NSPointerArray weakObjectsPointerArray];
36-
}
35+
if (!self) return self;
36+
37+
_collectionQueue = dispatch_queue_create("com.parse.ParseModuleCollection", DISPATCH_QUEUE_SERIAL);
38+
_modules = [NSPointerArray weakObjectsPointerArray];
39+
3740
return self;
3841
}
3942

@@ -42,20 +45,12 @@ - (instancetype)init {
4245
///--------------------------------------
4346

4447
- (void)addParseModule:(id<ParseModule>)module {
45-
if (module == nil) {
46-
return;
47-
}
48-
4948
[self performCollectionAccessBlock:^{
5049
[self.modules addPointer:(__bridge void *)module];
5150
}];
5251
}
5352

5453
- (void)removeParseModule:(id<ParseModule>)module {
55-
if (module == nil) {
56-
return;
57-
}
58-
5954
[self enumerateModulesWithBlock:^(id<ParseModule> enumeratedModule, BOOL *stop, BOOL *remove) {
6055
*remove = (module == enumeratedModule);
6156
}];
@@ -80,7 +75,7 @@ - (NSUInteger)modulesCount {
8075
#pragma mark - ParseModule
8176
///--------------------------------------
8277

83-
- (void)parseDidInitializeWithApplicationId:(NSString *)applicationId clientKey:(NSString *)clientKey {
78+
- (void)parseDidInitializeWithApplicationId:(NSString *)applicationId clientKey:(nullable NSString *)clientKey {
8479
dispatch_async(dispatch_get_main_queue(), ^{
8580
[self enumerateModulesWithBlock:^(id<ParseModule> module, BOOL *stop, BOOL *remove) {
8681
[module parseDidInitializeWithApplicationId:applicationId clientKey:clientKey];
@@ -132,3 +127,5 @@ - (void)enumerateModulesWithBlock:(ParseModuleEnumerationBlock)block {
132127
}
133128

134129
@end
130+
131+
NS_ASSUME_NONNULL_END

Parse/Parse.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ + (void)setApplicationId:(NSString *)applicationId clientKey:(NSString *)clientK
6868
+ (void)initializeWithConfiguration:(ParseClientConfiguration *)configuration {
6969
PFConsistencyAssert(configuration.applicationId.length != 0,
7070
@"You must set your configuration's `applicationId` before calling %s!", __PRETTY_FUNCTION__);
71-
PFConsistencyAssert(configuration.clientKey.length != 0,
72-
@"You must set your configuration's `clientKey` before calling %s!", __PRETTY_FUNCTION__);
7371
PFConsistencyAssert(![PFApplication currentApplication].extensionEnvironment ||
7472
configuration.applicationGroupIdentifier == nil ||
7573
configuration.containingApplicationBundleIdentifier != nil,

Parse/ParseClientConfiguration.m

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ - (instancetype)initWithBlock:(void (^)(id<ParseMutableClientConfiguration>))con
4646
configurationBlock(self);
4747

4848
PFConsistencyAssert(self.applicationId.length, @"`applicationId` should not be nil.");
49-
PFConsistencyAssert(self.clientKey.length, @"`clientKey` should not be nil.");
5049

5150
return self;
5251
}
@@ -65,7 +64,6 @@ - (void)setApplicationId:(NSString *)applicationId {
6564
}
6665

6766
- (void)setClientKey:(NSString *)clientKey {
68-
PFParameterAssert(clientKey.length, @"'clientKey' should not be nil.");
6967
_clientKey = [clientKey copy];
7068
}
7169

Tests/Unit/ParseModuleUnitTests.m

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ - (void)testModuleSelectors {
3636
ParseTestModule *module = [[ParseTestModule alloc] init];
3737
[collection addParseModule:module];
3838

39-
[collection parseDidInitializeWithApplicationId:nil clientKey:nil];
39+
[collection parseDidInitializeWithApplicationId:@"a" clientKey:nil];
4040

4141
// Spin the run loop, as the delegate messages are being called on the main thread
4242
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
@@ -52,7 +52,7 @@ - (void)testWeakModuleReference {
5252
[collection addParseModule:module];
5353
}
5454

55-
[collection parseDidInitializeWithApplicationId:nil clientKey:nil];
55+
[collection parseDidInitializeWithApplicationId:@"a" clientKey:nil];
5656

5757
// Run a single runloop tick to trigger the parse initializaiton.
5858
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate distantPast]];
@@ -76,13 +76,4 @@ - (void)testModuleRemove {
7676
XCTAssertEqual(collection.modulesCount, 1);
7777
}
7878

79-
- (void)testNilModule {
80-
ParseModuleCollection *collection = [[ParseModuleCollection alloc] init];
81-
82-
XCTAssertNoThrow([collection addParseModule:nil]);
83-
XCTAssertEqual(collection.modulesCount, 0);
84-
XCTAssertNoThrow([collection removeParseModule:nil]);
85-
XCTAssertEqual(collection.modulesCount, 0);
86-
}
87-
8879
@end

0 commit comments

Comments
 (0)