Skip to content

Commit

Permalink
Merge pull request #2031 from ably/2029-attribute-all-requests-to-proxy
Browse files Browse the repository at this point in the history
[ECO-5216] Attribute most REST requests to wrapper SDK
  • Loading branch information
lawrence-forooghian authored Feb 18, 2025
2 parents 022fee0 + d7c0bc1 commit 035a574
Show file tree
Hide file tree
Showing 63 changed files with 1,278 additions and 201 deletions.
160 changes: 156 additions & 4 deletions Ably.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion Source/ARTAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ - (void)createTokenRequest:(ARTTokenParams *)tokenParams options:(ARTAuthOptions
}
else {
if (replacedOptions.queryTime) {
return [_rest _time:^(NSDate *time, NSError *error) {
return [_rest _timeWithWrapperSDKAgents:nil
completion:^(NSDate *time, NSError *error) {
if (error) {
callback(nil, error);
} else {
Expand Down
4 changes: 1 addition & 3 deletions Source/ARTChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ @implementation ARTChannel {
ARTChannelOptions *_options;
}

@synthesize name = _name;

- (instancetype)initWithName:(NSString *)name andOptions:(ARTChannelOptions *)options rest:(ARTRestInternal *)rest logger:(ARTInternalLog *)logger {
if (self = [super init]) {
_name = name;
Expand Down Expand Up @@ -178,7 +176,7 @@ - (ARTMessage *)encodeMessageIfNeeded:(ARTMessage *)message error:(NSError **)er
return message;
}

- (void)history:(ARTPaginatedMessagesCallback)callback {
- (void)historyWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents completion:(ARTPaginatedMessagesCallback)callback {
NSAssert(false, @"-[%@ %@] should always be overriden.", self.class, NSStringFromSelector(_cmd));
}

Expand Down
Empty file added Source/ARTChannelProtocol.m
Empty file.
3 changes: 1 addition & 2 deletions Source/ARTHTTPPaginatedResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ - (instancetype)initWithResponse:(NSHTTPURLResponse *)response
responseProcessor:(ARTPaginatedResultResponseProcessor)responseProcessor
wrapperSDKAgents:(nullable NSDictionary<NSString *,NSString *> *)wrapperSDKAgents
logger:(ARTInternalLog *)logger {
self = [super initWithItems:items rest:rest relFirst:relFirst relCurrent:relCurrent relNext:relNext responseProcessor:responseProcessor logger:logger];
self = [super initWithItems:items rest:rest relFirst:relFirst relCurrent:relCurrent relNext:relNext responseProcessor:responseProcessor wrapperSDKAgents:wrapperSDKAgents logger:logger];
if (self) {
_response = response;
_wrapperSDKAgents = [wrapperSDKAgents copy];
}
return self;
}
Expand Down
11 changes: 7 additions & 4 deletions Source/ARTPaginatedResult.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ - (instancetype)initWithItems:(NSArray *)items
relCurrent:(NSMutableURLRequest *)relCurrent
relNext:(NSMutableURLRequest *)relNext
responseProcessor:(ARTPaginatedResultResponseProcessor)responseProcessor
wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
logger:(ARTInternalLog *)logger {
if (self = [super init]) {
_initializedViaInit = NO;
Expand All @@ -64,6 +65,7 @@ - (instancetype)initWithItems:(NSArray *)items
_userQueue = rest.userQueue;
_queue = rest.queue;
_responseProcessor = responseProcessor;
_wrapperSDKAgents = wrapperSDKAgents;
_logger = logger;

// ARTPaginatedResult doesn't need a internal counterpart, as other
Expand Down Expand Up @@ -116,7 +118,7 @@ - (void)first:(void (^)(ARTPaginatedResult<id> *_Nullable result, ARTErrorInfo *
};
}

[self.class executePaginated:_rest withRequest:_relFirst andResponseProcessor:_responseProcessor logger:_logger callback:callback];
[self.class executePaginated:_rest withRequest:_relFirst andResponseProcessor:_responseProcessor wrapperSDKAgents:_wrapperSDKAgents logger:_logger callback:callback];
}

- (void)next:(void (^)(ARTPaginatedResult<id> *_Nullable result, ARTErrorInfo *_Nullable error))callback {
Expand All @@ -138,13 +140,13 @@ - (void)next:(void (^)(ARTPaginatedResult<id> *_Nullable result, ARTErrorInfo *_
callback(nil, nil);
return;
}
[self.class executePaginated:_rest withRequest:_relNext andResponseProcessor:_responseProcessor logger:_logger callback:callback];
[self.class executePaginated:_rest withRequest:_relNext andResponseProcessor:_responseProcessor wrapperSDKAgents:_wrapperSDKAgents logger:_logger callback:callback];
}

+ (void)executePaginated:(ARTRestInternal *)rest withRequest:(NSMutableURLRequest *)request andResponseProcessor:(ARTPaginatedResultResponseProcessor)responseProcessor logger:(ARTInternalLog *)logger callback:(void (^)(ARTPaginatedResult<id> *_Nullable result, ARTErrorInfo *_Nullable error))callback {
+ (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 {
ARTLogDebug(logger, @"Paginated request: %@", request);

[rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (error) {
callback(nil, [ARTErrorInfo createFromNSError:error]);
} else {
Expand All @@ -171,6 +173,7 @@ + (void)executePaginated:(ARTRestInternal *)rest withRequest:(NSMutableURLReques
relCurrent:currentRel
relNext:nextRel
responseProcessor:responseProcessor
wrapperSDKAgents:wrapperSDKAgents
logger:logger];

callback(result, nil);
Expand Down
6 changes: 3 additions & 3 deletions Source/ARTPushAdmin.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ - (instancetype)initWithInternal:(ARTPushAdminInternal *)internal queuedDealloc:
}

- (void)publish:(ARTPushRecipient *)recipient data:(ARTJsonObject *)data callback:(nullable ARTCallback)callback {
[_internal publish:recipient data:data callback:callback];
[_internal publish:recipient data:data wrapperSDKAgents:nil callback:callback];
}

- (ARTPushDeviceRegistrations *)deviceRegistrations {
Expand Down Expand Up @@ -53,7 +53,7 @@ - (instancetype)initWithRest:(ARTRestInternal *)rest logger:(ARTInternalLog *)lo
return self;
}

- (void)publish:(ARTPushRecipient *)recipient data:(ARTJsonObject *)data callback:(nullable ARTCallback)callback {
- (void)publish:(ARTPushRecipient *)recipient data:(ARTJsonObject *)data wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(nullable ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *error) {
Expand Down 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 wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents 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
53 changes: 27 additions & 26 deletions Source/ARTPushChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,41 +24,41 @@ - (instancetype)initWithInternal:(ARTPushChannelInternal *)internal queuedDeallo
}

- (void)subscribeDevice {
[_internal subscribeDevice];
[_internal subscribeDeviceWithWrapperSDKAgents:nil];
}

- (void)subscribeDevice:(ARTCallback)callback {
[_internal subscribeDevice:callback];
[_internal subscribeDeviceWithWrapperSDKAgents:nil completion:callback];
}

- (void)subscribeClient {
[_internal subscribeClient];
[_internal subscribeClientWithWrapperSDKAgents:nil];
}

- (void)subscribeClient:(ARTCallback)callback {
[_internal subscribeClient:callback];
[_internal subscribeClientWithWrapperSDKAgents:nil completion:callback];
}

- (void)unsubscribeDevice {
[_internal unsubscribeDevice];
[_internal unsubscribeDeviceWithWrapperSDKAgents:nil];
}

- (void)unsubscribeDevice:(ARTCallback)callback {
[_internal unsubscribeDevice:callback];
[_internal unsubscribeDeviceWithWrapperSDKAgents:nil completion:callback];
}

- (void)unsubscribeClient {
[_internal unsubscribeClient];
[_internal unsubscribeClientWithWrapperSDKAgents:nil];
}

- (void)unsubscribeClient:(ARTCallback)callback {
[_internal unsubscribeClient:callback];
[_internal unsubscribeClientWithWrapperSDKAgents:nil completion:callback];
}

- (BOOL)listSubscriptions:(NSStringDictionary *)params
callback:(ARTPaginatedPushChannelCallback)callback
error:(NSError *_Nullable *_Nullable)errorPtr {
return [_internal listSubscriptions:params callback:callback error:errorPtr];
return [_internal listSubscriptions:params wrapperSDKAgents:nil callback:callback error:errorPtr];
}

@end
Expand Down Expand Up @@ -86,23 +86,23 @@ - (instancetype)init:(ARTRestInternal *)rest withChannel:(ARTChannel *)channel l
return self;
}

- (void)subscribeDevice {
[self subscribeDevice:nil];
- (void)subscribeDeviceWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents {
[self subscribeDeviceWithWrapperSDKAgents:wrapperSDKAgents completion:nil];
}

- (void)unsubscribeDevice {
[self unsubscribeDevice:nil];
- (void)unsubscribeDeviceWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents {
[self unsubscribeDeviceWithWrapperSDKAgents:wrapperSDKAgents completion:nil];
}

- (void)subscribeClient {
[self subscribeClient:nil];
- (void)subscribeClientWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents {
[self subscribeClientWithWrapperSDKAgents:wrapperSDKAgents completion:nil];
}

- (void)unsubscribeClient {
[self unsubscribeClient:nil];
- (void)unsubscribeClientWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents {
[self unsubscribeClientWithWrapperSDKAgents:wrapperSDKAgents completion:nil];
}

- (void)subscribeDevice:(ARTCallback)callback {
- (void)subscribeDeviceWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents completion:(ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *_Nullable error) {
Expand All @@ -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 wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents 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 All @@ -138,7 +138,7 @@ - (void)subscribeDevice:(ARTCallback)callback {
});
}

- (void)subscribeClient:(ARTCallback)callback {
- (void)subscribeClientWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents completion:(ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *_Nullable error) {
Expand All @@ -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 wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents 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 All @@ -172,7 +172,7 @@ - (void)subscribeClient:(ARTCallback)callback {
});
}

- (void)unsubscribeDevice:(ARTCallback)callback {
- (void)unsubscribeDeviceWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents completion:(ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *_Nullable error) {
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 wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents 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 All @@ -209,7 +209,7 @@ - (void)unsubscribeDevice:(ARTCallback)callback {
});
}

- (void)unsubscribeClient:(ARTCallback)callback {
- (void)unsubscribeClientWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents completion:(ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *_Nullable error) {
Expand All @@ -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 wrapperSDKAgents:nil completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
[self->_rest executeRequest:request withAuthOption:ARTAuthenticationOn wrapperSDKAgents:wrapperSDKAgents 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 All @@ -245,6 +245,7 @@ - (void)unsubscribeClient:(ARTCallback)callback {
}

- (BOOL)listSubscriptions:(NSStringDictionary *)params
wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
callback:(ARTPaginatedPushChannelCallback)callback
error:(NSError * __autoreleasing *)errorPtr {
if (callback) {
Expand Down Expand Up @@ -290,7 +291,7 @@ - (BOOL)listSubscriptions:(NSStringDictionary *)params
return [self->_rest.encoders[response.MIMEType] decodePushChannelSubscriptions:data error:error];
};

[ARTPaginatedResult executePaginated:self->_rest withRequest:request andResponseProcessor:responseProcessor logger:self->_logger callback:callback];
[ARTPaginatedResult executePaginated:self->_rest withRequest:request andResponseProcessor:responseProcessor wrapperSDKAgents:wrapperSDKAgents logger:self->_logger callback:callback];
ret = YES;
});
return ret;
Expand Down
Loading

0 comments on commit 035a574

Please sign in to comment.