BTHTTP.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #import <Foundation/Foundation.h>
  2. #import "BTHTTPErrors.h"
  3. #import "BTJSON.h"
  4. NS_ASSUME_NONNULL_BEGIN
  5. @class BTHTTPResponse, BTClientToken, BTPayPalIDToken;
  6. /**
  7. Performs HTTP methods on the Braintree Client API
  8. */
  9. @interface BTHTTP : NSObject<NSCopying>
  10. /**
  11. An optional array of pinned certificates, each an NSData instance consisting of DER encoded x509 certificates
  12. */
  13. @property (nonatomic, nullable, strong) NSArray<NSData *> *pinnedCertificates;
  14. /**
  15. Initialize `BTHTTP` with the URL for the Braintree API
  16. @param URL The base URL for the Braintree Client API
  17. */
  18. - (instancetype)initWithBaseURL:(NSURL *)URL NS_DESIGNATED_INITIALIZER;
  19. /**
  20. Initialize `BTHTTP` with the authorization fingerprint from a client token
  21. @param URL The base URL for the Braintree Client API
  22. @param authorizationFingerprint The authorization fingerprint HMAC from a client token
  23. */
  24. - (instancetype)initWithBaseURL:(NSURL *)URL
  25. authorizationFingerprint:(NSString *)authorizationFingerprint;
  26. /**
  27. Initialize `BTHTTP` with a tokenization key
  28. @param URL The base URL for the Braintree Client API
  29. @param tokenizationKey A tokenization key
  30. */
  31. - (instancetype)initWithBaseURL:(NSURL *)URL tokenizationKey:(NSString *)tokenizationKey;
  32. /**
  33. A convenience initializer to initialize `BTHTTP` with a client token
  34. @param clientToken A client token
  35. */
  36. - (instancetype)initWithClientToken:(BTClientToken *)clientToken;
  37. /**
  38. A convenience initializer to initialize `BTHTTP` with a PayPal ID Token
  39. @param payPalIDToken A PayPal ID Token
  40. */
  41. - (instancetype)initWithPayPalIDToken:(BTPayPalIDToken *)payPalIDToken;
  42. - (NSString *)userAgentString;
  43. - (NSString *)acceptString;
  44. - (NSString *)acceptLanguageString;
  45. #pragma clang diagnostic push
  46. #pragma clang diagnostic ignored "-Wnullability"
  47. - (nullable instancetype)init __attribute__((unavailable("Please use initWithBaseURL:authorizationFingerprint: instead.")));
  48. #pragma clang diagnostic pop
  49. // For testing
  50. @property (nonatomic, strong) NSURLSession *session;
  51. @property (nonatomic, readonly, strong) NSURL *baseURL;
  52. /**
  53. Queue that callbacks are dispatched onto, main queue if not otherwise specified
  54. */
  55. @property (nonatomic, strong) dispatch_queue_t dispatchQueue;
  56. - (void)GET:(NSString *)endpoint
  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. response:(nullable NSURLResponse *)response
  78. error:(nullable NSError *)error
  79. completionBlock:(void(^)(BTJSON *body, NSHTTPURLResponse *response, NSError *error))completionBlock;
  80. - (void)callCompletionBlock:(void(^)(BTJSON *body, NSHTTPURLResponse *response, NSError *error))completionBlock
  81. body:(nullable BTJSON *)jsonBody
  82. response:(nullable NSHTTPURLResponse *)response
  83. error:(nullable NSError *)error;
  84. @end
  85. NS_ASSUME_NONNULL_END