RLMNetworkClient.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import <Foundation/Foundation.h>
  19. #import "RLMSyncUtil_Private.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. @interface RLMNetworkRequestOptions : NSObject
  22. @property (nonatomic, copy, nullable) NSString *authorizationHeaderName;
  23. @property (nonatomic, copy, nullable) NSDictionary<NSString *, NSString *> *customHeaders;
  24. @property (nullable, nonatomic, copy) NSDictionary<NSString *, NSURL *> *pinnedCertificatePaths;
  25. @end
  26. /// An abstract class representing a server endpoint.
  27. @interface RLMSyncServerEndpoint : NSObject RLM_SYNC_UNINITIALIZABLE
  28. + (instancetype)endpoint;
  29. + (void)sendRequestToServer:(NSURL *)serverURL
  30. JSON:(NSDictionary *)jsonDictionary
  31. options:(nullable RLMNetworkRequestOptions *)options
  32. completion:(void (^)(NSError *))completionBlock;
  33. @end
  34. /// The authentication endpoint.
  35. @interface RLMSyncAuthEndpoint : RLMSyncServerEndpoint RLM_SYNC_UNINITIALIZABLE
  36. @end
  37. /// The password change endpoint.
  38. @interface RLMSyncChangePasswordEndpoint : RLMSyncServerEndpoint RLM_SYNC_UNINITIALIZABLE
  39. @end
  40. @interface RLMSyncUpdateAccountEndpoint : RLMSyncServerEndpoint RLM_SYNC_UNINITIALIZABLE
  41. @end
  42. /// The get user info endpoint.
  43. @interface RLMSyncGetUserInfoEndpoint : RLMSyncServerEndpoint RLM_SYNC_UNINITIALIZABLE
  44. @end
  45. /**
  46. A simple Realm Object Server network client that wraps `NSURLSession`.
  47. */
  48. @interface RLMNetworkClient : NSObject
  49. // Set the timeout in seconds for requests which do not take an explicit timeout.
  50. + (void)setDefaultTimeout:(NSTimeInterval)timeout;
  51. + (void)sendRequestToEndpoint:(RLMSyncServerEndpoint *)endpoint
  52. server:(NSURL *)serverURL
  53. JSON:(NSDictionary *)jsonDictionary
  54. timeout:(NSTimeInterval)timeout
  55. options:(nullable RLMNetworkRequestOptions *)options
  56. completion:(RLMSyncCompletionBlock)completionBlock;
  57. NS_ASSUME_NONNULL_END
  58. @end