Skip to content

Commit

Permalink
insert wrapper SDK agents in -request
Browse files Browse the repository at this point in the history
note that this justifies our earlier making of the internal not conform
to the public protocol

note this provides groundwork for allowing other REST-triggering things
to also supply wrapper SDK agents, but that we're currently passing nil
for wrapperSDKAgents param; will address that piecemeal later

TODO test
  • Loading branch information
lawrence-forooghian committed Jan 15, 2025
1 parent 9147528 commit 927ac69
Show file tree
Hide file tree
Showing 18 changed files with 89 additions and 55 deletions.
4 changes: 2 additions & 2 deletions Source/ARTAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ - (void)requestToken:(ARTTokenParams *)tokenParams

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

task = [_rest executeRequest:request withAuthOption:ARTAuthenticationOff completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
task = [_rest executeRequest:request withAuthOption:ARTAuthenticationOff wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
checkerCallback(nil, error);
} else {
Expand Down Expand Up @@ -508,7 +508,7 @@ - (void)handleAuthUrlResponse:(NSHTTPURLResponse *)response
[request setValue:[encoder mimeType] forHTTPHeaderField:@"Accept"];
[request setValue:[encoder mimeType] forHTTPHeaderField:@"Content-Type"];

return [_rest executeRequest:request withAuthOption:ARTAuthenticationOff completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
return [_rest executeRequest:request withAuthOption:ARTAuthenticationOff wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
callback(nil, error);
} else {
Expand Down
7 changes: 4 additions & 3 deletions Source/ARTHTTPPaginatedResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ - (void)first:(ARTHTTPPaginatedCallback)callback {
};
}

[self.class executePaginated:self.rest withRequest:self.relFirst logger:self.logger callback:callback];
[self.class executePaginated:self.rest withRequest:self.relFirst wrapperSDKAgents:nil logger:self.logger callback:callback];
}

- (void)next:(ARTHTTPPaginatedCallback)callback {
Expand All @@ -81,16 +81,17 @@ - (void)next:(ARTHTTPPaginatedCallback)callback {
return;
}

[self.class executePaginated:self.rest withRequest:self.relNext logger:self.logger callback:callback];
[self.class executePaginated:self.rest withRequest:self.relNext wrapperSDKAgents:nil logger:self.logger callback:callback];
}

+ (void)executePaginated:(ARTRestInternal *)rest
withRequest:(NSMutableURLRequest *)request
wrapperSDKAgents:(nullable NSDictionary<NSString *, NSString *> *)wrapperSDKAgents
logger:(ARTInternalLog *)logger
callback:(ARTHTTPPaginatedCallback)callback {
ARTLogDebug(logger, @"HTTP Paginated request: %@", request);

[rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error && ![error.domain isEqualToString:ARTAblyErrorDomain]) {
callback(nil, [ARTErrorInfo createFromNSError:error]);
return;
Expand Down
2 changes: 1 addition & 1 deletion Source/ARTPaginatedResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ - (void)next:(void (^)(ARTPaginatedResult<id> *_Nullable result, ARTErrorInfo *_
+ (void)executePaginated:(ARTRestInternal *)rest withRequest:(NSMutableURLRequest *)request andResponseProcessor:(ARTPaginatedResultResponseProcessor)responseProcessor logger:(ARTInternalLog *)logger callback:(void (^)(ARTPaginatedResult<id> *_Nullable result, ARTErrorInfo *_Nullable error))callback {
ARTLogDebug(logger, @"Paginated request: %@", request);

[rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
callback(nil, [ARTErrorInfo createFromNSError:error]);
} else {
Expand Down
8 changes: 4 additions & 4 deletions Source/ARTPushActivationStateMachine.m
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ - (void)deviceRegistration:(ARTErrorInfo *)error {
[request setValue:[[self->_rest defaultEncoder] mimeType] forHTTPHeaderField:@"Content-Type"];

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

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

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

ARTLogDebug(_logger, @"%@: device deregistration with request %@", NSStringFromClass(self.class), request);
[_rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
// RSH3d2c1: ignore unauthorized or invalid credentials errors
if (response.statusCode == 401 || error.code == 40005) {
Expand Down
2 changes: 1 addition & 1 deletion Source/ARTPushAdmin.m
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ - (void)publish:(ARTPushRecipient *)recipient data:(ARTJsonObject *)data callbac
[request setValue:[[self->_rest defaultEncoder] mimeType] forHTTPHeaderField:@"Content-Type"];

ARTLogDebug(self->_logger, @"push notification to a single device %@", request);
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
ARTLogError(self->_logger, @"%@: push notification to a single device failed (%@)", NSStringFromClass(self.class), error.localizedDescription);
if (callback) callback([ARTErrorInfo createFromNSError:error]);
Expand Down
8 changes: 4 additions & 4 deletions Source/ARTPushChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ - (void)subscribeDevice:(ARTCallback)callback {
[request setDeviceAuthentication:deviceId localDevice:device];

ARTLogDebug(self->_logger, @"subscribe notifications for device %@ in channel %@", deviceId, self->_channel.name);
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
ARTLogError(self->_logger, @"%@: subscribe notifications for device %@ in channel %@ failed (%@)", NSStringFromClass(self.class), deviceId, self->_channel.name, error.localizedDescription);
}
Expand Down Expand Up @@ -163,7 +163,7 @@ - (void)subscribeClient:(ARTCallback)callback {
[request setValue:[[self->_rest defaultEncoder] mimeType] forHTTPHeaderField:@"Content-Type"];

ARTLogDebug(self->_logger, @"subscribe notifications for clientId %@ in channel %@", clientId, self->_channel.name);
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
ARTLogError(self->_logger, @"%@: subscribe notifications for clientId %@ in channel %@ failed (%@)", NSStringFromClass(self.class), clientId, self->_channel.name, error.localizedDescription);
}
Expand Down Expand Up @@ -200,7 +200,7 @@ - (void)unsubscribeDevice:(ARTCallback)callback {
[request setDeviceAuthentication:deviceId localDevice:device];

ARTLogDebug(self->_logger, @"unsubscribe notifications for device %@ in channel %@", deviceId, self->_channel.name);
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
ARTLogError(self->_logger, @"%@: unsubscribe notifications for device %@ in channel %@ failed (%@)", NSStringFromClass(self.class), deviceId, self->_channel.name, error.localizedDescription);
}
Expand Down Expand Up @@ -235,7 +235,7 @@ - (void)unsubscribeClient:(ARTCallback)callback {
request.HTTPMethod = @"DELETE";

ARTLogDebug(self->_logger, @"unsubscribe notifications for clientId %@ in channel %@", clientId, self->_channel.name);
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
ARTLogError(self->_logger, @"%@: unsubscribe notifications for clientId %@ in channel %@ failed (%@)", NSStringFromClass(self.class), clientId, self->_channel.name, error.localizedDescription);
}
Expand Down
4 changes: 2 additions & 2 deletions Source/ARTPushChannelSubscriptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ - (void)save:(ARTPushChannelSubscription *)channelSubscription callback:(ARTCall
[request setDeviceAuthentication:channelSubscription.deviceId localDevice:local];

ARTLogDebug(self->_logger, @"save channel subscription with request %@", request);
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (response.statusCode == 200 /*Ok*/ || response.statusCode == 201 /*Created*/) {
ARTLogDebug(self->_logger, @"channel subscription saved successfully");
callback(nil);
Expand Down Expand Up @@ -207,7 +207,7 @@ - (void)_removeWhere:(NSStringDictionary *)params callback:(ARTCallback)callback
#endif

ARTLogDebug(_logger, @"remove channel subscription with request %@", request);
[_rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (response.statusCode == 200 /*Ok*/ || response.statusCode == 204 /*not returning any content*/) {
ARTLogDebug(self->_logger, @"%@: channel subscription removed successfully", NSStringFromClass(self.class));
callback(nil);
Expand Down
8 changes: 4 additions & 4 deletions Source/ARTPushDeviceRegistrations.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ - (void)save:(ARTDeviceDetails *)deviceDetails callback:(ARTCallback)callback {
[request setDeviceAuthentication:deviceDetails.id localDevice:local logger:self->_logger];

ARTLogDebug(self->_logger, @"save device with request %@", request);
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (response.statusCode == 200 /*OK*/) {
NSError *decodeError = nil;
ARTDeviceDetails *deviceDetails = [[self->_rest defaultEncoder] decodeDeviceDetails:data error:&decodeError];
Expand Down Expand Up @@ -139,7 +139,7 @@ - (void)get:(ARTDeviceId *)deviceId callback:(void (^)(ARTDeviceDetails *, ARTEr
[request setDeviceAuthentication:deviceId localDevice:local logger:self->_logger];

ARTLogDebug(self->_logger, @"get device with request %@", request);
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (response.statusCode == 200 /*OK*/) {
NSError *decodeError = nil;
ARTDeviceDetails *device = [self->_rest.encoders[response.MIMEType] decodeDeviceDetails:data error:&decodeError];
Expand Down Expand Up @@ -212,7 +212,7 @@ - (void)remove:(NSString *)deviceId callback:(ARTCallback)callback {
[request setValue:[[self->_rest defaultEncoder] mimeType] forHTTPHeaderField:@"Content-Type"];

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

ARTLogDebug(self->_logger, @"remove devices with request %@", request);
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (response.statusCode == 200 /*Ok*/ || response.statusCode == 204 /*not returning any content*/) {
ARTLogDebug(self->_logger, @"%@: remove devices successfully", NSStringFromClass(self.class));
callback(nil);
Expand Down
5 changes: 3 additions & 2 deletions Source/ARTRealtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ - (BOOL)request:(NSString *)method
headers:(nullable NSStringDictionary *)headers
callback:(ARTHTTPPaginatedCallback)callback
error:(NSError *_Nullable *_Nullable)errorPtr {
return [_internal request:method path:path params:params body:body headers:headers callback:callback error:errorPtr];
return [_internal request:method path:path params:params body:body headers:headers wrapperSDKAgents:nil callback:callback error:errorPtr];
}

- (void)ping:(ARTCallback)cb {
Expand Down Expand Up @@ -509,9 +509,10 @@ - (BOOL)request:(NSString *)method
params:(nullable NSStringDictionary *)params
body:(nullable id)body
headers:(nullable NSStringDictionary *)headers
wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
callback:(ARTHTTPPaginatedCallback)callback
error:(NSError *_Nullable *_Nullable)errorPtr {
return [self.rest request:method path:path params:params body:body headers:headers callback:callback error:errorPtr];
return [self.rest request:method path:path params:params body:body headers:headers wrapperSDKAgents:wrapperSDKAgents callback:callback error:errorPtr];
}

- (void)ping:(ARTCallback) cb {
Expand Down
17 changes: 10 additions & 7 deletions Source/ARTRealtimeWrapperSDKProxy.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#import "ARTRealtimeWrapperSDKProxy.h"
#import "ARTRealtimeWrapperSDKProxy+Private.h"
#import "ARTWrapperProxyOptions.h"
#import "ARTRealtime+Private.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -96,13 +98,14 @@ - (BOOL)request:(nonnull NSString *)method
headers:(nullable NSStringDictionary *)headers
callback:(nonnull ARTHTTPPaginatedCallback)callback
error:(NSError * _Nullable __autoreleasing * _Nullable)errorPtr {
return [self.realtime request:method
path:path
params:params
body:body
headers:headers
callback:callback
error:errorPtr];
return [self.realtime.internal request:method
path:path
params:params
body:body
headers:headers
wrapperSDKAgents:self.options.agents
callback:callback
error:errorPtr];
}

- (BOOL)stats:(nonnull ARTPaginatedStatsCallback)callback {
Expand Down
Loading

0 comments on commit 927ac69

Please sign in to comment.