Skip to content

Commit 9546629

Browse files
committed
Introduce method for external requests (such as user provided options' authUrl).
Rename executeRequest to executeAblyRequest for better readability. Refactor private executeRequest to decrease its size.
1 parent 211c51d commit 9546629

16 files changed

Lines changed: 236 additions & 175 deletions

Source/ARTAuth.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ - (NSMutableURLRequest *)buildRequest:(ARTAuthOptions *)options withParams:(ARTT
260260
NSURL *url = [self buildURL:options withParams:params];
261261
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
262262
request.HTTPMethod = options.authMethod;
263+
[request setTimeoutInterval:_options.httpRequestTimeout];
263264

264265
// HTTP Header Fields
265266
if ([options isMethodPOST]) {
@@ -370,7 +371,7 @@ - (void)requestToken:(ARTTokenParams *)tokenParams
370371

371372
ARTLogDebug(self.logger, @"RS:%p using authUrl (%@ %@)", _rest, request.HTTPMethod, request.URL);
372373

373-
task = [_rest executeRequest:request withAuthOption:ARTAuthenticationOff wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
374+
task = [_rest executeExternalRequest:request completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
374375
if (error) {
375376
checkerCallback(nil, error);
376377
} else {
@@ -508,7 +509,7 @@ - (void)handleAuthUrlResponse:(NSHTTPURLResponse *)response
508509
[request setValue:[encoder mimeType] forHTTPHeaderField:@"Accept"];
509510
[request setValue:[encoder mimeType] forHTTPHeaderField:@"Content-Type"];
510511

511-
return [_rest executeRequest:request withAuthOption:ARTAuthenticationOff wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
512+
return [_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOff wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
512513
if (error) {
513514
callback(nil, error);
514515
} else {

Source/ARTHTTPPaginatedResponse.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ + (void)executePaginated:(ARTRestInternal *)rest
9393
callback:(ARTHTTPPaginatedCallback)callback {
9494
ARTLogDebug(logger, @"HTTP Paginated request: %@", request);
9595

96-
[rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
96+
[rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
9797
if (error && ![error.domain isEqualToString:ARTAblyErrorDomain]) {
9898
callback(nil, [ARTErrorInfo createFromNSError:error]);
9999
return;

Source/ARTPaginatedResult.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ - (void)next:(void (^)(ARTPaginatedResult<id> *_Nullable result, ARTErrorInfo *_
147147
+ (void)executePaginated:(ARTRestInternal *)rest withRequest:(NSMutableURLRequest *)request andResponseProcessor:(ARTPaginatedResultResponseProcessor)responseProcessor wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents logger:(ARTInternalLog *)logger callback:(void (^)(ARTPaginatedResult<id> *_Nullable result, ARTErrorInfo *_Nullable error))callback {
148148
ARTLogDebug(logger, @"Paginated request: %@", request);
149149

150-
[rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
150+
[rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
151151
if (error) {
152152
callback(nil, [ARTErrorInfo createFromNSError:error]);
153153
} else {

Source/ARTPushActivationStateMachine.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ - (void)deviceRegistration:(ARTErrorInfo *)error {
197197
[request setValue:[[self->_rest defaultEncoder] mimeType] forHTTPHeaderField:@"Content-Type"];
198198

199199
ARTLogDebug(self->_logger, @"%@: device registration with request %@", NSStringFromClass(self.class), request);
200-
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
200+
[self->_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
201201
if (error) {
202202
ARTLogError(self->_logger, @"%@: device registration failed (%@)", NSStringFromClass(self.class), error.localizedDescription);
203203
[self sendEvent:[ARTPushActivationEventGettingDeviceRegistrationFailed newWithError:[ARTErrorInfo createFromNSError:error]]];
@@ -263,7 +263,7 @@ - (void)deviceUpdateRegistration:(ARTErrorInfo *)error {
263263
[request setDeviceAuthentication:local];
264264

265265
ARTLogDebug(_logger, @"%@: update device with request %@", NSStringFromClass(self.class), request);
266-
[_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
266+
[_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
267267
if (error) {
268268
ARTLogError(self->_logger, @"%@: update device failed (%@)", NSStringFromClass(self.class), error.localizedDescription);
269269
[self sendEvent:[ARTPushActivationEventSyncRegistrationFailed newWithError:[ARTErrorInfo createFromNSError:error]]];
@@ -311,7 +311,7 @@ - (void)syncDevice {
311311
[request setDeviceAuthentication:local];
312312

313313
ARTLogDebug(self->_logger, @"%@: sync device with request %@", NSStringFromClass(self.class), request);
314-
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
314+
[self->_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
315315
if (error) {
316316
ARTLogError(self->_logger, @"%@: device registration failed (%@)", NSStringFromClass(self.class), error.localizedDescription);
317317
[self sendEvent:[ARTPushActivationEventSyncRegistrationFailed newWithError:[ARTErrorInfo createFromNSError:error]]];
@@ -366,7 +366,7 @@ - (void)deviceUnregistration:(ARTErrorInfo *)error {
366366
[request setDeviceAuthentication:local];
367367

368368
ARTLogDebug(_logger, @"%@: device deregistration with request %@", NSStringFromClass(self.class), request);
369-
[_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
369+
[_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
370370
if (error) {
371371
// RSH3d2c1: ignore unauthorized or invalid credentials errors
372372
if (response.statusCode == 401 || error.code == 40005) {

Source/ARTPushAdmin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ - (void)publish:(ARTPushRecipient *)recipient data:(ARTJsonObject *)data wrapper
8484
[request setValue:[[self->_rest defaultEncoder] mimeType] forHTTPHeaderField:@"Content-Type"];
8585

8686
ARTLogDebug(self->_logger, @"push notification to a single device %@", request);
87-
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
87+
[self->_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
8888
if (error) {
8989
ARTLogError(self->_logger, @"%@: push notification to a single device failed (%@)", NSStringFromClass(self.class), error.localizedDescription);
9090
if (callback) callback([ARTErrorInfo createFromNSError:error]);

Source/ARTPushChannel.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ - (void)subscribeDeviceWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapp
130130
[request setDeviceAuthentication:deviceId localDevice:device];
131131

132132
ARTLogDebug(self->_logger, @"subscribe notifications for device %@ in channel %@", deviceId, self->_channel.name);
133-
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
133+
[self->_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
134134
if (error) {
135135
ARTLogError(self->_logger, @"%@: subscribe notifications for device %@ in channel %@ failed (%@)", NSStringFromClass(self.class), deviceId, self->_channel.name, error.localizedDescription);
136136
}
@@ -164,7 +164,7 @@ - (void)subscribeClientWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapp
164164
[request setValue:[[self->_rest defaultEncoder] mimeType] forHTTPHeaderField:@"Content-Type"];
165165

166166
ARTLogDebug(self->_logger, @"subscribe notifications for clientId %@ in channel %@", clientId, self->_channel.name);
167-
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
167+
[self->_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
168168
if (error) {
169169
ARTLogError(self->_logger, @"%@: subscribe notifications for clientId %@ in channel %@ failed (%@)", NSStringFromClass(self.class), clientId, self->_channel.name, error.localizedDescription);
170170
}
@@ -201,7 +201,7 @@ - (void)unsubscribeDeviceWithWrapperSDKAgents:(nullable NSStringDictionary *)wra
201201
[request setDeviceAuthentication:deviceId localDevice:device];
202202

203203
ARTLogDebug(self->_logger, @"unsubscribe notifications for device %@ in channel %@", deviceId, self->_channel.name);
204-
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
204+
[self->_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
205205
if (error) {
206206
ARTLogError(self->_logger, @"%@: unsubscribe notifications for device %@ in channel %@ failed (%@)", NSStringFromClass(self.class), deviceId, self->_channel.name, error.localizedDescription);
207207
}
@@ -236,7 +236,7 @@ - (void)unsubscribeClientWithWrapperSDKAgents:(nullable NSStringDictionary *)wra
236236
request.HTTPMethod = @"DELETE";
237237

238238
ARTLogDebug(self->_logger, @"unsubscribe notifications for clientId %@ in channel %@", clientId, self->_channel.name);
239-
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
239+
[self->_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
240240
if (error) {
241241
ARTLogError(self->_logger, @"%@: unsubscribe notifications for clientId %@ in channel %@ failed (%@)", NSStringFromClass(self.class), clientId, self->_channel.name, error.localizedDescription);
242242
}

Source/ARTPushChannelSubscriptions.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ - (void)save:(ARTPushChannelSubscription *)channelSubscription wrapperSDKAgents:
9191
[request setDeviceAuthentication:channelSubscription.deviceId localDevice:local];
9292

9393
ARTLogDebug(self->_logger, @"save channel subscription with request %@", request);
94-
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
94+
[self->_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
9595
if (response.statusCode == 200 /*Ok*/ || response.statusCode == 201 /*Created*/) {
9696
ARTLogDebug(self->_logger, @"channel subscription saved successfully");
9797
callback(nil);
@@ -209,7 +209,7 @@ - (void)_removeWhere:(NSStringDictionary *)params wrapperSDKAgents:(nullable NSS
209209
#endif
210210

211211
ARTLogDebug(_logger, @"remove channel subscription with request %@", request);
212-
[_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
212+
[_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
213213
if (response.statusCode == 200 /*Ok*/ || response.statusCode == 204 /*not returning any content*/) {
214214
ARTLogDebug(self->_logger, @"%@: channel subscription removed successfully", NSStringFromClass(self.class));
215215
callback(nil);

Source/ARTPushDeviceRegistrations.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ - (void)save:(ARTDeviceDetails *)deviceDetails wrapperSDKAgents:(nullable NSStri
9292
[request setDeviceAuthentication:deviceDetails.id localDevice:local logger:self->_logger];
9393

9494
ARTLogDebug(self->_logger, @"save device with request %@", request);
95-
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
95+
[self->_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
9696
if (response.statusCode == 200 /*OK*/) {
9797
NSError *decodeError = nil;
9898
ARTDeviceDetails *deviceDetails = [[self->_rest defaultEncoder] decodeDeviceDetails:data error:&decodeError];
@@ -140,7 +140,7 @@ - (void)get:(ARTDeviceId *)deviceId wrapperSDKAgents:(nullable NSStringDictionar
140140
[request setDeviceAuthentication:deviceId localDevice:local logger:self->_logger];
141141

142142
ARTLogDebug(self->_logger, @"get device with request %@", request);
143-
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
143+
[self->_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
144144
if (response.statusCode == 200 /*OK*/) {
145145
NSError *decodeError = nil;
146146
ARTDeviceDetails *device = [self->_rest.encoders[response.MIMEType] decodeDeviceDetails:data error:&decodeError];
@@ -213,7 +213,7 @@ - (void)remove:(NSString *)deviceId wrapperSDKAgents:(nullable NSStringDictionar
213213
[request setValue:[[self->_rest defaultEncoder] mimeType] forHTTPHeaderField:@"Content-Type"];
214214

215215
ARTLogDebug(self->_logger, @"remove device with request %@", request);
216-
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
216+
[self->_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
217217
if (response.statusCode == 200 /*Ok*/ || response.statusCode == 204 /*not returning any content*/) {
218218
ARTLogDebug(self->_logger, @"%@: save device successfully", NSStringFromClass(self.class));
219219
callback(nil);
@@ -258,7 +258,7 @@ - (void)removeWhere:(NSStringDictionary *)params wrapperSDKAgents:(nullable NSSt
258258
[request setDeviceAuthentication:[params objectForKey:@"deviceId"] localDevice:local];
259259

260260
ARTLogDebug(self->_logger, @"remove devices with request %@", request);
261-
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
261+
[self->_rest executeAblyRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
262262
if (response.statusCode == 200 /*Ok*/ || response.statusCode == 204 /*not returning any content*/) {
263263
ARTLogDebug(self->_logger, @"%@: remove devices successfully", NSStringFromClass(self.class));
264264
callback(nil);

0 commit comments

Comments
 (0)