From 937f0dfb62e02f00766d61d2c36e1e99aff5de8b Mon Sep 17 00:00:00 2001 From: Marat Al Date: Sat, 24 Aug 2024 15:20:20 +0200 Subject: [PATCH] Added a wrapper `ARTRealtime.request...` method for making rest requests via internal `ARTRest` instance. --- Source/ARTRealtime.m | 20 ++++++++++++++++++++ Source/include/Ably/ARTRealtime.h | 21 +++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/Source/ARTRealtime.m b/Source/ARTRealtime.m index aa10cf716..bb5f67742 100644 --- a/Source/ARTRealtime.m +++ b/Source/ARTRealtime.m @@ -150,6 +150,16 @@ - (void)time:(ARTDateTimeCallback)cb { [_internal time:cb]; } +- (BOOL)request:(NSString *)method + path:(NSString *)path + params:(nullable NSStringDictionary *)params + body:(nullable id)body + 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]; +} + - (void)ping:(ARTCallback)cb { [_internal ping:cb]; } @@ -482,6 +492,16 @@ - (void)time:(ARTDateTimeCallback)cb { [self.rest time:cb]; } +- (BOOL)request:(NSString *)method + path:(NSString *)path + params:(nullable NSStringDictionary *)params + body:(nullable id)body + headers:(nullable NSStringDictionary *)headers + 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]; +} + - (void)ping:(ARTCallback) cb { if (cb) { ARTCallback userCallback = cb; diff --git a/Source/include/Ably/ARTRealtime.h b/Source/include/Ably/ARTRealtime.h index fbf87b8b8..9fa314d96 100644 --- a/Source/include/Ably/ARTRealtime.h +++ b/Source/include/Ably/ARTRealtime.h @@ -72,6 +72,27 @@ NS_ASSUME_NONNULL_BEGIN */ - (void)time:(ARTDateTimeCallback)callback; +/** + * Makes a REST request to a provided path. This is provided as a convenience for developers who wish to use REST API functionality that is either not documented or is not yet included in the public API, without having to directly handle features such as authentication, paging, fallback hosts, MsgPack and JSON support. + * + * @param method The request method to use, such as GET, POST. + * @param path The request path. + * @param params The parameters to include in the URL query of the request. The parameters depend on the endpoint being queried. See the [REST API reference](https://ably.com/docs/api/rest-api) for the available parameters of each endpoint. + * @param body The JSON body of the request. + * @param headers Additional HTTP headers to include in the request. + * @param callback A callback for retriving `ARTHttpPaginatedResponse` object returned by the HTTP request, containing an empty or JSON-encodable object. + * @param errorPtr A reference to the `NSError` object where an error information will be saved in case of failure. + + * @return In case of failure returns `false` and the error information can be retrived via the `error` parameter. + */ +- (BOOL)request:(NSString *)method + path:(NSString *)path + params:(nullable NSStringDictionary *)params + body:(nullable id)body + headers:(nullable NSStringDictionary *)headers + callback:(ARTHTTPPaginatedCallback)callback + error:(NSError *_Nullable *_Nullable)errorPtr; + /// :nodoc: TODO: docstring - (void)ping:(ARTCallback)cb;