BTAPIClient_Internal.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #import "BTAnalyticsService.h"
  2. #import "BTAPIClient.h"
  3. #import "BTClientMetadata.h"
  4. #import "BTClientToken.h"
  5. #import "BTHTTP.h"
  6. #import "BTAPIHTTP.h"
  7. #import "BTGraphQLHTTP.h"
  8. #import "BTJSON.h"
  9. #import "BTPayPalIDToken.h"
  10. NS_ASSUME_NONNULL_BEGIN
  11. @class BTPaymentMethodNonce;
  12. typedef NS_ENUM(NSInteger, BTAPIClientHTTPType) {
  13. /// Use the Gateway
  14. BTAPIClientHTTPTypeGateway = 0,
  15. /// Use the Braintree API
  16. BTAPIClientHTTPTypeBraintreeAPI,
  17. /// Use the GraphQL API
  18. BTAPIClientHTTPTypeGraphQLAPI,
  19. };
  20. typedef NS_ENUM(NSInteger, BTAPIClientAuthorizationType) {
  21. BTAPIClientAuthorizationTypeTokenizationKey = 0,
  22. BTAPIClientAuthorizationTypeClientToken,
  23. BTAPIClientAuthorizationTypePayPalIDToken,
  24. };
  25. @interface BTAPIClient ()
  26. @property (nonatomic, copy, nullable) NSString *tokenizationKey;
  27. @property (nonatomic, strong, nullable) BTClientToken *clientToken;
  28. @property (nonatomic, strong, nullable) BTPayPalIDToken *payPalIDToken;
  29. @property (nonatomic, strong) BTHTTP *http;
  30. @property (nonatomic, strong) BTHTTP *configurationHTTP;
  31. @property (nonatomic, strong) BTAPIHTTP *braintreeAPI;
  32. @property (nonatomic, strong) BTGraphQLHTTP *graphQL;
  33. /**
  34. Client metadata that is used for tracking the client session
  35. */
  36. @property (nonatomic, readonly, strong) BTClientMetadata *metadata;
  37. /**
  38. Exposed for testing analytics
  39. */
  40. @property (nonatomic, strong) BTAnalyticsService *analyticsService;
  41. /**
  42. Sends this event and all queued analytics events. Use `queueAnalyticsEvent` for low priority events.
  43. */
  44. - (void)sendAnalyticsEvent:(NSString *)eventName;
  45. /**
  46. Queues an analytics event to be sent.
  47. */
  48. - (void)queueAnalyticsEvent:(NSString *)eventName;
  49. /**
  50. An internal initializer to toggle whether to send an analytics event during initialization.
  51. This prevents copyWithSource:integration: from sending a duplicate event. It can also be used to suppress excessive network chatter during testing.
  52. */
  53. - (nullable instancetype)initWithAuthorization:(NSString *)authorization sendAnalyticsEvent:(BOOL)sendAnalyticsEvent;
  54. - (void)GET:(NSString *)path
  55. parameters:(nullable NSDictionary <NSString *, NSString *> *)parameters
  56. httpType:(BTAPIClientHTTPType)httpType
  57. completion:(nullable void(^)(BTJSON * _Nullable body, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error))completionBlock;
  58. - (void)POST:(NSString *)path
  59. parameters:(nullable NSDictionary *)parameters
  60. httpType:(BTAPIClientHTTPType)httpType
  61. completion:(nullable void(^)(BTJSON * _Nullable body, NSHTTPURLResponse * _Nullable response, NSError * _Nullable error))completionBlock;
  62. /**
  63. Gets base GraphQL URL
  64. */
  65. + (nullable NSURL *)graphQLURLForEnvironment:(NSString *)environment;
  66. /**
  67. Determines the BTAPIClientAuthorizationType of the given authorization string. Exposed for testing.
  68. */
  69. + (BTAPIClientAuthorizationType)authorizationTypeForAuthorization:(NSString *)authorization;
  70. @end
  71. NS_ASSUME_NONNULL_END