BTHTTP.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #import <Foundation/Foundation.h>
  2. @class BTClientToken;
  3. @class BTHTTPErrors;
  4. @class BTHTTPResponse;
  5. @class BTJSON;
  6. @class BTCacheDateValidator;
  7. NS_ASSUME_NONNULL_BEGIN
  8. /**
  9. Performs HTTP methods on the Braintree Client API
  10. */
  11. @interface BTHTTP : NSObject<NSCopying>
  12. /**
  13. An optional array of pinned certificates, each an NSData instance consisting of DER encoded x509 certificates
  14. */
  15. @property (nonatomic, nullable, strong) NSArray<NSData *> *pinnedCertificates;
  16. /// internal date cache validator for testing
  17. @property (nonatomic) BTCacheDateValidator *cacheDateValidator;
  18. /**
  19. Initialize `BTHTTP` with the URL for the Braintree API
  20. @param URL The base URL for the Braintree Client API
  21. */
  22. - (instancetype)initWithBaseURL:(NSURL *)URL NS_DESIGNATED_INITIALIZER;
  23. /**
  24. Initialize `BTHTTP` with the authorization fingerprint from a client token
  25. @param URL The base URL for the Braintree Client API
  26. @param authorizationFingerprint The authorization fingerprint HMAC from a client token
  27. */
  28. - (instancetype)initWithBaseURL:(NSURL *)URL
  29. authorizationFingerprint:(NSString *)authorizationFingerprint;
  30. /**
  31. Initialize `BTHTTP` with a tokenization key
  32. @param URL The base URL for the Braintree Client API
  33. @param tokenizationKey A tokenization key
  34. */
  35. - (instancetype)initWithBaseURL:(NSURL *)URL tokenizationKey:(NSString *)tokenizationKey;
  36. /**
  37. A convenience initializer to initialize `BTHTTP` with a client token
  38. @param clientToken A client token
  39. */
  40. - (instancetype)initWithClientToken:(BTClientToken *)clientToken;
  41. - (NSString *)userAgentString;
  42. - (NSString *)acceptString;
  43. - (NSString *)acceptLanguageString;
  44. - (instancetype)init __attribute__((unavailable("Please use initWithBaseURL:authorizationFingerprint: instead.")));
  45. // For testing
  46. @property (nonatomic, strong) NSURLSession *session;
  47. @property (nonatomic, readonly, strong) NSURL *baseURL;
  48. /**
  49. Queue that callbacks are dispatched onto, main queue if not otherwise specified
  50. */
  51. @property (nonatomic, strong) dispatch_queue_t dispatchQueue;
  52. - (void)GET:(NSString *)endpoint
  53. completion:(nullable void(^)(BTJSON * _Nullable body, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error))completionBlock;
  54. - (void)GET:(NSString *)endpoint
  55. parameters:(nullable NSDictionary <NSString *, NSString *> *)parameters
  56. shouldCache:(BOOL)shouldCache
  57. completion:(nullable void(^)(BTJSON * _Nullable body, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error))completionBlock;
  58. - (void)GET:(NSString *)endpoint
  59. parameters:(nullable NSDictionary <NSString *, NSString *> *)parameters
  60. completion:(nullable void(^)(BTJSON * _Nullable body, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error))completionBlock;
  61. - (void)POST:(NSString *)endpoint
  62. completion:(nullable void(^)(BTJSON * _Nullable body, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error))completionBlock;
  63. - (void)POST:(NSString *)endpoint
  64. parameters:(nullable NSDictionary *)parameters
  65. completion:(nullable void(^)(BTJSON * _Nullable body, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error))completionBlock;
  66. - (void)PUT:(NSString *)endpoint
  67. completion:(nullable void(^)(BTJSON * _Nullable body, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error))completionBlock;
  68. - (void)PUT:(NSString *)endpoint
  69. parameters:(nullable NSDictionary *)parameters
  70. completion:(nullable void(^)(BTJSON * _Nullable body, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error))completionBlock;
  71. - (void)DELETE:(NSString *)endpoint
  72. completion:(nullable void(^)(BTJSON * _Nullable body, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error))completionBlock;
  73. - (void)DELETE:(NSString *)endpoint
  74. parameters:(nullable NSDictionary *)parameters
  75. completion:(nullable void(^)(BTJSON * _Nullable body, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error))completionBlock;
  76. - (void)handleRequestCompletion:(nullable NSData *)data
  77. request:(nullable NSURLRequest *)request
  78. shouldCache:(BOOL)shouldCache
  79. response:(nullable NSURLResponse *)response
  80. error:(nullable NSError *)error
  81. completionBlock:(void(^)(BTJSON *body, NSHTTPURLResponse *response, NSError *error))completionBlock;
  82. - (void)callCompletionBlock:(void(^)(BTJSON *body, NSHTTPURLResponse *response, NSError *error))completionBlock
  83. body:(nullable BTJSON *)jsonBody
  84. response:(nullable NSHTTPURLResponse *)response
  85. error:(nullable NSError *)error;
  86. @end
  87. NS_ASSUME_NONNULL_END