BTAPIHTTP.m 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #import "BTAPIHTTP.h"
  2. #import "BTAPIPinnedCertificates.h"
  3. #define BT_API_VERSION @"2016-10-07"
  4. @interface BTAPIHTTP ()
  5. @property (nonatomic, strong) NSString *accessToken;
  6. @end
  7. @implementation BTAPIHTTP
  8. - (instancetype)initWithBaseURL:(NSURL *)URL accessToken:(NSString *)accessToken {
  9. if (self = [super initWithBaseURL:URL]) {
  10. self.accessToken = accessToken;
  11. NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
  12. configuration.HTTPAdditionalHeaders = self.defaultHeaders;
  13. NSOperationQueue *delegateQueue = [[NSOperationQueue alloc] init];
  14. delegateQueue.name = @"com.braintreepayments.BTHTTP";
  15. delegateQueue.maxConcurrentOperationCount = NSOperationQueueDefaultMaxConcurrentOperationCount;
  16. self.session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:delegateQueue];
  17. self.pinnedCertificates = [BTAPIPinnedCertificates trustedCertificates];
  18. }
  19. return self;
  20. }
  21. - (NSDictionary *)defaultHeaders {
  22. return @{ @"User-Agent": [self userAgentString],
  23. @"Accept": [self acceptString],
  24. @"Accept-Language": [self acceptLanguageString],
  25. @"Braintree-Version": BT_API_VERSION,
  26. @"Authorization": [NSString stringWithFormat:@"Bearer %@", self.accessToken]};
  27. }
  28. @end