Skip to content

Commit

Permalink
Add method for creating wrapper SDK proxy client
Browse files Browse the repository at this point in the history
TODO same for REST?
  • Loading branch information
lawrence-forooghian committed Jan 15, 2025
1 parent 72d7c98 commit 146c2dc
Show file tree
Hide file tree
Showing 14 changed files with 270 additions and 0 deletions.
56 changes: 56 additions & 0 deletions Ably.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions Source/ARTRealtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#import "ARTInternalLog.h"
#import "ARTRealtimeTransportFactory.h"
#import "ARTConnectRetryState.h"
#import "ARTRealtimeWrapperSDKProxy+Private.h"

@interface ARTConnectionStateChange ()

Expand Down Expand Up @@ -180,6 +181,12 @@ - (void)close {
[_internal close];
}

- (id<ARTRealtimeProtocol>)createWrapperSDKProxyWithOptions:(ARTWrapperProxyOptions *)options {
return [[ARTRealtimeWrapperSDKProxy alloc] initWithRealtime:self
options:options];

}

@end

NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -222,6 +229,11 @@ @implementation ARTRealtimeInternal {
dispatch_queue_t _queue;
}

- (id<ARTRealtimeProtocol>)createWrapperSDKProxyWithOptions:(ARTWrapperProxyOptions *)options {
[NSException raise:@"TODO why does this need to conform to ARTRealtimeProtocol?" format:@""];
exit(1);
}

- (instancetype)initWithOptions:(ARTClientOptions *)options {
self = [super init];
if (self) {
Expand Down
101 changes: 101 additions & 0 deletions Source/ARTRealtimeWrapperSDKProxy.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#import "ARTRealtimeWrapperSDKProxy.h"
#import "ARTRealtimeWrapperSDKProxy+Private.h"

NS_ASSUME_NONNULL_BEGIN

@interface ARTRealtimeWrapperSDKProxy ()

@property (nonatomic, readonly) ARTRealtime *realtime;
@property (nonatomic, readonly) ARTWrapperProxyOptions *options;

@end

NS_ASSUME_NONNULL_END

@implementation ARTRealtimeWrapperSDKProxy

- (instancetype)initWithRealtime:(ARTRealtime *)realtime
options:(ARTWrapperProxyOptions *)options {
if (self = [super init]) {
_realtime = realtime;
_options = options;
}

return self;
}

- (ARTConnection *)connection {
return self.realtime.connection;
}

- (ARTRealtimeChannels *)channels {
return self.realtime.channels;
}

- (ARTPush *)push {
return self.realtime.push;
}

- (ARTAuth *)auth {
return self.realtime.auth;
}

- (NSString *)clientId {
return self.realtime.clientId;
}

#if TARGET_OS_IOS
- (ARTLocalDevice *)device {
return self.realtime.device;
}
#endif

- (void)close {
[self.realtime close];
}

- (void)connect {
[self.realtime connect];
}

- (nonnull id<ARTRealtimeProtocol>)createWrapperSDKProxyWithOptions:(nonnull ARTWrapperProxyOptions *)options {
@throw [NSException exceptionWithName:NSInvalidArgumentException
reason:@"You can not call -createWrapperProxyWithOptions: on a proxy object."
userInfo: nil];
}

- (void)ping:(nonnull ARTCallback)cb {
[self.realtime ping:cb];
}

- (BOOL)request:(nonnull NSString *)method
path:(nonnull NSString *)path
params:(nullable NSStringDictionary *)params
body:(nullable id)body
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];
}

- (BOOL)stats:(nonnull ARTPaginatedStatsCallback)callback {
return [self.realtime stats:callback];
}

- (BOOL)stats:(nullable ARTStatsQuery *)query callback:(nonnull ARTPaginatedStatsCallback)callback error:(NSError * _Nullable __autoreleasing * _Nullable)errorPtr {
return [self.realtime stats:query
callback:callback
error:errorPtr];
}

- (void)time:(nonnull ARTDateTimeCallback)callback {
[self.realtime time:callback];
}

@end
13 changes: 13 additions & 0 deletions Source/ARTWrapperProxyOptions.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import "ARTWrapperProxyOptions.h"

@implementation ARTWrapperProxyOptions

- (instancetype)initWithAgent:(NSString *)agent {
if (self = [super init]) {
_agent = [agent copy];;
}

return self;
}

@end
1 change: 1 addition & 0 deletions Source/Ably.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@ framework module Ably {
header "ARTWebSocketFactory.h"
header "ARTAttachRetryState.h"
header "ARTConnectRetryState.h"
header "ARTRealtimeWrapperSDKProxy+Private.h"
}
}
13 changes: 13 additions & 0 deletions Source/PrivateHeaders/Ably/ARTRealtimeWrapperSDKProxy+Private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#import <Ably/ARTRealtimeWrapperSDKProxy.h>

NS_ASSUME_NONNULL_BEGIN

@interface ARTRealtimeWrapperSDKProxy ()

- (instancetype)initWithRealtime:(ARTRealtime *)realtime
options:(ARTWrapperProxyOptions *)options NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
Empty file added Source/Untitled.h
Empty file.
1 change: 1 addition & 0 deletions Source/include/Ably.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,6 @@ framework module Ably {
header "Ably/ARTWebSocketFactory.h"
header "Ably/ARTAttachRetryState.h"
header "Ably/ARTConnectRetryState.h"
header "Ably/ARTRealtimeWrapperSDKProxy+Private.h"
}
}
5 changes: 5 additions & 0 deletions Source/include/Ably/ARTRealtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
@class ARTPush;
@class ARTProtocolMessage;
@class ARTRealtimeChannels;
@class ARTWrapperProxyOptions;
@class ARTRealtimeWrapperSDKProxy;

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -154,6 +156,9 @@ NS_SWIFT_SENDABLE
/// :nodoc:
+ (instancetype)createWithToken:(NSString *)tokenId NS_SWIFT_UNAVAILABLE("Use instance initializer instead");

// TODO docs
- (ARTRealtimeWrapperSDKProxy *)createWrapperSDKProxyWithOptions:(ARTWrapperProxyOptions *)options;

@end

NS_ASSUME_NONNULL_END
24 changes: 24 additions & 0 deletions Source/include/Ably/ARTRealtimeWrapperSDKProxy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#import <Foundation/Foundation.h>
#import <Ably/ARTRealtime.h>

@class ARTWrapperProxyOptions;
@class ARTConnection;
@class ARTRealtimeChannels;
@class ARTPush;
@class ARTAuth;

// TODO exclude from docs

NS_ASSUME_NONNULL_BEGIN

NS_SWIFT_SENDABLE
@interface ARTRealtimeWrapperSDKProxy : NSObject <ARTRealtimeProtocol>

@property (readonly) ARTConnection *connection;
@property (readonly) ARTRealtimeChannels *channels;
@property (readonly) ARTPush *push;
@property (readonly) ARTAuth *auth;

@end

NS_ASSUME_NONNULL_END
15 changes: 15 additions & 0 deletions Source/include/Ably/ARTWrapperProxyOptions.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

NS_SWIFT_SENDABLE
@interface ARTWrapperProxyOptions: NSObject

@property (nonatomic, readonly) NSString *agent;

- (instancetype)initWithAgent:(NSString *)agent NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;

@end

NS_ASSUME_NONNULL_END
2 changes: 2 additions & 0 deletions Source/include/Ably/Ably.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ FOUNDATION_EXPORT const unsigned char ablyVersionString[];
#import <Ably/ARTPendingMessage.h>
#import <Ably/ARTStringifiable.h>
#import <Ably/ARTClientInformation.h>
#import <Ably/ARTWrapperProxyOptions.h>
#import <Ably/ARTRealtimeWrapperSDKProxy.h>
7 changes: 7 additions & 0 deletions Test/Test Utilities/WrapperSDKProxyTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import XCTest

class WrapperSDKProxyTests {
func testRealtimeAPI() {

}
}
20 changes: 20 additions & 0 deletions Test/Tests/WrapperSDKProxyTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import XCTest

class WrapperSDKProxyTests {
func testRealtimeAPI() throws {
let test = Test()
let options = try AblyTests.commonAppSetup(for: test)
let client = AblyTests.newRealtime(options).client
defer { client.dispose(); client.close() }

let proxyClient = client.createWrapperSDKProxy(with: .init(agent: test.id.uuidString))

// TODO get these compiling, then start adding other APIs here

let _ = proxyClient.connection
//
let channel = proxyClient.channels.get(test.uniqueChannelName())

channel.attach()
}
}

0 comments on commit 146c2dc

Please sign in to comment.