Skip to content

Commit

Permalink
inject wrapper agents into push channel subscriptions / device regist…
Browse files Browse the repository at this point in the history
…rations
  • Loading branch information
lawrence-forooghian committed Feb 13, 2025
1 parent 21e8f90 commit efc0819
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 61 deletions.
35 changes: 18 additions & 17 deletions Source/ARTPushChannelSubscriptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,23 @@ - (instancetype)initWithInternal:(ARTPushChannelSubscriptionsInternal *)internal
}

- (void)save:(ARTPushChannelSubscription *)channelSubscription callback:(ARTCallback)callback {
[_internal save:channelSubscription callback:callback];
[_internal save:channelSubscription wrapperSDKAgents:nil callback:callback];
}

- (void)listChannels:(ARTPaginatedTextCallback)callback {
[_internal listChannels:callback];
[_internal listChannelsWithWrapperSDKAgents:nil completion:callback];
}

- (void)list:(NSStringDictionary *)params callback:(ARTPaginatedPushChannelCallback)callback {
[_internal list:params callback:callback];
[_internal list:params wrapperSDKAgents:nil callback:callback];
}

- (void)remove:(ARTPushChannelSubscription *)subscription callback:(ARTCallback)callback {
[_internal remove:subscription callback:callback];
[_internal remove:subscription wrapperSDKAgents:nil callback:callback];
}

- (void)removeWhere:(NSStringDictionary *)params callback:(ARTCallback)callback {
[_internal removeWhere:params callback:callback];
[_internal removeWhere:params wrapperSDKAgents:nil callback:callback];
}

@end
Expand All @@ -62,7 +62,7 @@ - (instancetype)initWithRest:(ARTRestInternal *)rest logger:(ARTInternalLog *)lo
return self;
}

- (void)save:(ARTPushChannelSubscription *)channelSubscription callback:(ARTCallback)callback {
- (void)save:(ARTPushChannelSubscription *)channelSubscription wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *error) {
Expand Down 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 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 (response.statusCode == 200 /*Ok*/ || response.statusCode == 201 /*Created*/) {
ARTLogDebug(self->_logger, @"channel subscription saved successfully");
callback(nil);
Expand All @@ -108,7 +108,8 @@ - (void)save:(ARTPushChannelSubscription *)channelSubscription callback:(ARTCall
});
}

- (void)listChannels:(ARTPaginatedTextCallback)callback {
- (void)listChannelsWithWrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents
completion:(ARTPaginatedTextCallback)callback {
if (callback) {
void (^userCallback)(ARTPaginatedResult *, ARTErrorInfo *error) = callback;
callback = ^(ARTPaginatedResult *result, ARTErrorInfo *error) {
Expand All @@ -126,11 +127,11 @@ - (void)listChannels:(ARTPaginatedTextCallback)callback {
ARTPaginatedResultResponseProcessor responseProcessor = ^(NSHTTPURLResponse *response, NSData *data, NSError **error) {
return [self->_rest.encoders[response.MIMEType] decode:data error:error];
};
[ARTPaginatedResult executePaginated:self->_rest withRequest:request andResponseProcessor:responseProcessor wrapperSDKAgents:nil logger:self->_logger callback:callback];
[ARTPaginatedResult executePaginated:self->_rest withRequest:request andResponseProcessor:responseProcessor wrapperSDKAgents:wrapperSDKAgents logger:self->_logger callback:callback];
});
}

- (void)list:(NSStringDictionary *)params callback:(ARTPaginatedPushChannelCallback)callback {
- (void)list:(NSStringDictionary *)params wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(ARTPaginatedPushChannelCallback)callback {
if (callback) {
void (^userCallback)(ARTPaginatedResult *, ARTErrorInfo *error) = callback;
callback = ^(ARTPaginatedResult *result, ARTErrorInfo *error) {
Expand All @@ -149,11 +150,11 @@ - (void)list:(NSStringDictionary *)params callback:(ARTPaginatedPushChannelCallb
ARTPaginatedResultResponseProcessor responseProcessor = ^(NSHTTPURLResponse *response, NSData *data, NSError **error) {
return [self->_rest.encoders[response.MIMEType] decodePushChannelSubscriptions:data error:error];
};
[ARTPaginatedResult executePaginated:self->_rest withRequest:request andResponseProcessor:responseProcessor wrapperSDKAgents:nil logger:self->_logger callback:callback];
[ARTPaginatedResult executePaginated:self->_rest withRequest:request andResponseProcessor:responseProcessor wrapperSDKAgents:wrapperSDKAgents logger:self->_logger callback:callback];
});
}

- (void)remove:(ARTPushChannelSubscription *)subscription callback:(ARTCallback)callback {
- (void)remove:(ARTPushChannelSubscription *)subscription wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *error) {
Expand All @@ -175,11 +176,11 @@ - (void)remove:(ARTPushChannelSubscription *)subscription callback:(ARTCallback)
} else {
where[@"clientId"] = subscription.clientId;
}
[self _removeWhere:where callback:callback];
[self _removeWhere:where wrapperSDKAgents:wrapperSDKAgents callback:callback];
});
}

- (void)removeWhere:(NSStringDictionary *)params callback:(ARTCallback)callback {
- (void)removeWhere:(NSStringDictionary *)params wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *error) {
Expand All @@ -190,11 +191,11 @@ - (void)removeWhere:(NSStringDictionary *)params callback:(ARTCallback)callback
}

dispatch_async(_queue, ^{
[self _removeWhere:params callback:callback];
[self _removeWhere:params wrapperSDKAgents:wrapperSDKAgents callback:callback];
});
}

- (void)_removeWhere:(NSStringDictionary *)params callback:(ARTCallback)callback {
- (void)_removeWhere:(NSStringDictionary *)params wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(ARTCallback)callback {
NSURLComponents *components = [[NSURLComponents alloc] initWithURL:[NSURL URLWithString:@"/push/channelSubscriptions"] resolvingAgainstBaseURL:NO];
components.queryItems = [params art_asURLQueryItems];
if (_rest.options.pushFullWait) {
Expand All @@ -207,7 +208,7 @@ - (void)_removeWhere:(NSStringDictionary *)params callback:(ARTCallback)callback
#endif

ARTLogDebug(_logger, @"remove channel subscription with 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 (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
30 changes: 15 additions & 15 deletions Source/ARTPushDeviceRegistrations.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@ - (instancetype)initWithInternal:(ARTPushDeviceRegistrationsInternal *)internal
}

- (void)save:(ARTDeviceDetails *)deviceDetails callback:(ARTCallback)callback {
[_internal save:deviceDetails callback:callback];
[_internal save:deviceDetails wrapperSDKAgents:nil callback:callback];
}

- (void)get:(ARTDeviceId *)deviceId callback:(void (^)(ARTDeviceDetails *_Nullable, ARTErrorInfo *_Nullable))callback {
[_internal get:deviceId callback:callback];
[_internal get:deviceId wrapperSDKAgents:nil callback:callback];
}

- (void)list:(NSStringDictionary *)params callback:(ARTPaginatedDeviceDetailsCallback)callback {
[_internal list:params callback:callback];
[_internal list:params wrapperSDKAgents:nil callback:callback];
}

- (void)remove:(NSString *)deviceId callback:(ARTCallback)callback {
[_internal remove:deviceId callback:callback];
[_internal remove:deviceId wrapperSDKAgents:nil callback:callback];
}

- (void)removeWhere:(NSStringDictionary *)params callback:(ARTCallback)callback {
[_internal removeWhere:params callback:callback];
[_internal removeWhere:params wrapperSDKAgents:nil callback:callback];
}

@end
Expand All @@ -63,7 +63,7 @@ - (instancetype)initWithRest:(ARTRestInternal *)rest logger:(ARTInternalLog *)lo
return self;
}

- (void)save:(ARTDeviceDetails *)deviceDetails callback:(ARTCallback)callback {
- (void)save:(ARTDeviceDetails *)deviceDetails wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *error) {
Expand Down 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 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 (response.statusCode == 200 /*OK*/) {
NSError *decodeError = nil;
ARTDeviceDetails *deviceDetails = [[self->_rest defaultEncoder] decodeDeviceDetails:data error:&decodeError];
Expand All @@ -117,7 +117,7 @@ - (void)save:(ARTDeviceDetails *)deviceDetails callback:(ARTCallback)callback {
});
}

- (void)get:(ARTDeviceId *)deviceId callback:(void (^)(ARTDeviceDetails *, ARTErrorInfo *))callback {
- (void)get:(ARTDeviceId *)deviceId wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(void (^)(ARTDeviceDetails *, ARTErrorInfo *))callback {
if (callback) {
void (^userCallback)(ARTDeviceDetails *, ARTErrorInfo *error) = callback;
callback = ^(ARTDeviceDetails *device, ARTErrorInfo *error) {
Expand All @@ -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 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 (response.statusCode == 200 /*OK*/) {
NSError *decodeError = nil;
ARTDeviceDetails *device = [self->_rest.encoders[response.MIMEType] decodeDeviceDetails:data error:&decodeError];
Expand Down Expand Up @@ -169,7 +169,7 @@ - (void)get:(ARTDeviceId *)deviceId callback:(void (^)(ARTDeviceDetails *, ARTEr
});
}

- (void)list:(NSStringDictionary *)params callback:(ARTPaginatedDeviceDetailsCallback)callback {
- (void)list:(NSStringDictionary *)params wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(ARTPaginatedDeviceDetailsCallback)callback {
if (callback) {
void (^userCallback)(ARTPaginatedResult *, ARTErrorInfo *error) = callback;
callback = ^(ARTPaginatedResult *result, ARTErrorInfo *error) {
Expand All @@ -188,11 +188,11 @@ - (void)list:(NSStringDictionary *)params callback:(ARTPaginatedDeviceDetailsCal
ARTPaginatedResultResponseProcessor responseProcessor = ^(NSHTTPURLResponse *response, NSData *data, NSError **error) {
return [self->_rest.encoders[response.MIMEType] decodeDevicesDetails:data error:error];
};
[ARTPaginatedResult executePaginated:self->_rest withRequest:request andResponseProcessor:responseProcessor wrapperSDKAgents:nil logger:self->_logger callback:callback];
[ARTPaginatedResult executePaginated:self->_rest withRequest:request andResponseProcessor:responseProcessor wrapperSDKAgents:wrapperSDKAgents logger:self->_logger callback:callback];
});
}

- (void)remove:(NSString *)deviceId callback:(ARTCallback)callback {
- (void)remove:(NSString *)deviceId wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *error) {
Expand All @@ -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 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 (response.statusCode == 200 /*Ok*/ || response.statusCode == 204 /*not returning any content*/) {
ARTLogDebug(self->_logger, @"%@: save device successfully", NSStringFromClass(self.class));
callback(nil);
Expand All @@ -230,7 +230,7 @@ - (void)remove:(NSString *)deviceId callback:(ARTCallback)callback {
});
}

- (void)removeWhere:(NSStringDictionary *)params callback:(ARTCallback)callback {
- (void)removeWhere:(NSStringDictionary *)params wrapperSDKAgents:(nullable NSStringDictionary *)wrapperSDKAgents callback:(ARTCallback)callback {
if (callback) {
ARTCallback userCallback = callback;
callback = ^(ARTErrorInfo *error) {
Expand All @@ -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 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 (response.statusCode == 200 /*Ok*/ || response.statusCode == 204 /*not returning any content*/) {
ARTLogDebug(self->_logger, @"%@: remove devices successfully", NSStringFromClass(self.class));
callback(nil);
Expand Down
25 changes: 16 additions & 9 deletions Source/ARTWrapperSDKProxyPushChannelSubscriptions.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#import "ARTWrapperSDKProxyPushChannelSubscriptions+Private.h"
#import "ARTWrapperSDKProxyOptions.h"
#import "ARTPushChannelSubscriptions+Private.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -23,27 +25,32 @@ - (instancetype)initWithPushChannelSubscriptions:(ARTPushChannelSubscriptions *)
}

- (void)list:(nonnull NSStringDictionary *)params callback:(nonnull ARTPaginatedPushChannelCallback)callback {
[self.underlyingPushChannelSubscriptions list:params
callback:callback];
[self.underlyingPushChannelSubscriptions.internal list:params
wrapperSDKAgents:self.proxyOptions.agents
callback:callback];
}

- (void)listChannels:(nonnull ARTPaginatedTextCallback)callback {
[self.underlyingPushChannelSubscriptions listChannels:callback];
[self.underlyingPushChannelSubscriptions.internal listChannelsWithWrapperSDKAgents:self.proxyOptions.agents
completion:callback];
}

- (void)remove:(nonnull ARTPushChannelSubscription *)subscription callback:(nonnull ARTCallback)callback {
[self.underlyingPushChannelSubscriptions remove:subscription
callback:callback];
[self.underlyingPushChannelSubscriptions.internal remove:subscription
wrapperSDKAgents:self.proxyOptions.agents
callback:callback];
}

- (void)removeWhere:(nonnull NSStringDictionary *)params callback:(nonnull ARTCallback)callback {
[self.underlyingPushChannelSubscriptions removeWhere:params
callback:callback];
[self.underlyingPushChannelSubscriptions.internal removeWhere:params
wrapperSDKAgents:self.proxyOptions.agents
callback:callback];
}

- (void)save:(nonnull ARTPushChannelSubscription *)channelSubscription callback:(nonnull ARTCallback)callback {
[self.underlyingPushChannelSubscriptions save:channelSubscription
callback:callback];
[self.underlyingPushChannelSubscriptions.internal save:channelSubscription
wrapperSDKAgents:self.proxyOptions.agents
callback:callback];
}

@end
27 changes: 17 additions & 10 deletions Source/ARTWrapperSDKProxyPushDeviceRegistrations.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#import "ARTWrapperSDKProxyPushDeviceRegistrations+Private.h"
#import "ARTWrapperSDKProxyOptions.h"
#import "ARTPushDeviceRegistrations+Private.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -23,28 +25,33 @@ - (instancetype)initWithPushDeviceRegistrations:(ARTPushDeviceRegistrations *)pu
}

- (void)get:(nonnull ARTDeviceId *)deviceId callback:(nonnull void (^)(ARTDeviceDetails * _Nullable, ARTErrorInfo * _Nullable))callback {
[self.underlyingPushDeviceRegistrations get:deviceId
callback:callback];
[self.underlyingPushDeviceRegistrations.internal get:deviceId
wrapperSDKAgents:self.proxyOptions.agents
callback:callback];
}

- (void)list:(nonnull NSStringDictionary *)params callback:(nonnull ARTPaginatedDeviceDetailsCallback)callback {
[self.underlyingPushDeviceRegistrations list:params
callback:callback];
[self.underlyingPushDeviceRegistrations.internal list:params
wrapperSDKAgents:self.proxyOptions.agents
callback:callback];
}

- (void)remove:(nonnull NSString *)deviceId callback:(nonnull ARTCallback)callback {
[self.underlyingPushDeviceRegistrations remove:deviceId
callback:callback];
[self.underlyingPushDeviceRegistrations.internal remove:deviceId
wrapperSDKAgents:self.proxyOptions.agents
callback:callback];
}

- (void)removeWhere:(nonnull NSStringDictionary *)params callback:(nonnull ARTCallback)callback {
[self.underlyingPushDeviceRegistrations removeWhere:params
callback:callback];
[self.underlyingPushDeviceRegistrations.internal removeWhere:params
wrapperSDKAgents:self.proxyOptions.agents
callback:callback];
}

- (void)save:(nonnull ARTDeviceDetails *)deviceDetails callback:(nonnull ARTCallback)callback {
[self.underlyingPushDeviceRegistrations save:deviceDetails
callback:callback];
[self.underlyingPushDeviceRegistrations.internal save:deviceDetails
wrapperSDKAgents:self.proxyOptions.agents
callback:callback];
}

@end
Loading

0 comments on commit efc0819

Please sign in to comment.