mirror of https://github.com/oxen-io/session-ios
Moving away from custom HTTP stack
parent
510831d701
commit
d05791e699
@ -1 +1 @@
|
||||
Subproject commit e77476e6f8ddec69fb20785f9ff61db0ea95035a
|
||||
Subproject commit 585c9e6ca1b55e99fb5c09aa31a6d590c2be5c58
|
File diff suppressed because it is too large
Load Diff
@ -1,13 +0,0 @@
|
||||
//
|
||||
// AFFutureRequest.h
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 05/10/14.
|
||||
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface AFFutureRequest : NSObject
|
||||
|
||||
@end
|
@ -1,13 +0,0 @@
|
||||
//
|
||||
// AFFutureRequest.m
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 05/10/14.
|
||||
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AFFutureRequest.h"
|
||||
|
||||
@implementation AFFutureRequest
|
||||
|
||||
@end
|
@ -0,0 +1,23 @@
|
||||
//
|
||||
// AFHTTPSessionManager+SignalMethods.h
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 05/10/14.
|
||||
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AFHTTPSessionManager.h"
|
||||
|
||||
@interface AFHTTPSessionManager (SignalMethods)
|
||||
|
||||
- (NSURLSessionDataTask *)BUSY:(NSString *)URLString
|
||||
parameters:(id)parameters
|
||||
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
|
||||
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
|
||||
|
||||
- (NSURLSessionDataTask *)RING:(NSString *)URLString
|
||||
parameters:(id)parameters
|
||||
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
|
||||
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
|
||||
|
||||
@end
|
@ -0,0 +1,49 @@
|
||||
//
|
||||
// AFHTTPSessionManager+SignalMethods.m
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 05/10/14.
|
||||
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "AFHTTPSessionManager+SignalMethods.h"
|
||||
|
||||
@interface AFHTTPSessionManager ()
|
||||
|
||||
- (NSURLSessionDataTask *)dataTaskWithHTTPMethod:(NSString *)method
|
||||
URLString:(NSString *)URLString
|
||||
parameters:(id)parameters
|
||||
success:(void (^)(NSURLSessionDataTask *, id))success
|
||||
failure:(void (^)(NSURLSessionDataTask *, NSError *))failure;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AFHTTPSessionManager (SignalMethods)
|
||||
|
||||
- (NSURLSessionDataTask *)BUSY:(NSString *)URLString
|
||||
parameters:(id)parameters
|
||||
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
|
||||
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
|
||||
|
||||
NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"BUSY" URLString:URLString parameters:parameters success:success failure:failure];
|
||||
[dataTask resume];
|
||||
|
||||
return dataTask;
|
||||
|
||||
}
|
||||
|
||||
- (NSURLSessionDataTask *)RING:(NSString *)URLString
|
||||
parameters:(id)parameters
|
||||
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
|
||||
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
|
||||
|
||||
NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"RING" URLString:URLString parameters:parameters success:success failure:failure];
|
||||
[dataTask resume];
|
||||
|
||||
return dataTask;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
@ -1,18 +0,0 @@
|
||||
//
|
||||
// CallServerRequests.h
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 31/07/14.
|
||||
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AFNetworking/AFNetworking.h>
|
||||
|
||||
@interface CallServerRequestsManager : NSObject
|
||||
|
||||
MacrosSingletonInterface
|
||||
|
||||
- (void)registerPushToken:(NSData*)deviceToken success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
|
||||
|
||||
@end
|
@ -1,62 +0,0 @@
|
||||
//
|
||||
// CallServerRequests.m
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 31/07/14.
|
||||
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
#import "HttpRequest.h"
|
||||
#import "CallServerRequestsManager.h"
|
||||
#import "DataUtil.h"
|
||||
#import "Environment.h"
|
||||
#import "HostNameEndPoint.h"
|
||||
#import "SGNKeychainUtil.h"
|
||||
|
||||
#define defaultRequestTimeout
|
||||
|
||||
@interface CallServerRequestsManager ()
|
||||
|
||||
@property (nonatomic, retain)AFHTTPSessionManager *operationManager;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation CallServerRequestsManager
|
||||
|
||||
MacrosSingletonImplemention
|
||||
|
||||
- (id)init{
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
HostNameEndPoint *endpoint = Environment.getCurrent.masterServerSecureEndPoint.hostNameEndPoint;
|
||||
NSURL *endPointURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://%@:%hu", endpoint.hostname, endpoint.port]];
|
||||
NSURLSessionConfiguration *sessionConf = NSURLSessionConfiguration.ephemeralSessionConfiguration;
|
||||
self.operationManager = [[AFHTTPSessionManager alloc] initWithBaseURL:endPointURL sessionConfiguration:sessionConf];
|
||||
self.operationManager.responseSerializer = [AFJSONResponseSerializer serializer];
|
||||
self.operationManager.securityPolicy.allowInvalidCertificates = YES;
|
||||
NSString *certPath = [NSBundle.mainBundle pathForResource:@"whisperReal" ofType:@"cer"];
|
||||
NSData *certData = [NSData dataWithContentsOfFile:certPath];
|
||||
SecCertificateRef cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)(certData));
|
||||
self.operationManager.securityPolicy.pinnedCertificates = @[(__bridge_transfer NSData *)SecCertificateCopyData(cert)];
|
||||
self.operationManager.securityPolicy.SSLPinningMode = AFSSLPinningModeCertificate;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)registerPushToken:(NSData*)deviceToken success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
|
||||
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
|
||||
self.operationManager.requestSerializer = [self basicAuthenticationSerializer];
|
||||
|
||||
[self.operationManager PUT:[NSString stringWithFormat:@"/apn/%@",deviceToken.encodedAsHexString] parameters:@{} success:success failure:failure];
|
||||
}
|
||||
|
||||
- (AFHTTPRequestSerializer*)basicAuthenticationSerializer{
|
||||
AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer];
|
||||
[serializer setValue:[HttpRequest computeBasicAuthorizationTokenForLocalNumber:SGNKeychainUtil.localNumber
|
||||
andPassword:SGNKeychainUtil.serverAuthPassword]
|
||||
forHTTPHeaderField:@"Authorization"];
|
||||
return serializer;
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,47 @@
|
||||
//
|
||||
// RedPhoneAPICall.h
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 05/10/14.
|
||||
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AFNetworking/AFNetworking.h>
|
||||
@class PhoneNumber;
|
||||
|
||||
@interface RPAPICall : NSObject
|
||||
|
||||
typedef NS_ENUM(NSInteger, HTTPMethod) {
|
||||
HTTP_GET,
|
||||
HTTP_POST,
|
||||
HTTP_PUT,
|
||||
HTTP_DELETE,
|
||||
SIGNAL_RING,
|
||||
SIGNAL_BUSY
|
||||
};
|
||||
|
||||
#pragma mark API Call Properties
|
||||
|
||||
@property (nonatomic, readonly) NSString *endPoint;
|
||||
@property (nonatomic, readonly) HTTPMethod method;
|
||||
@property (nonatomic, readonly) NSDictionary *parameters;
|
||||
@property (nonatomic, readonly) AFHTTPRequestSerializer <AFURLRequestSerialization> *requestSerializer;
|
||||
@property (nonatomic, readonly) AFHTTPResponseSerializer <AFURLResponseSerialization> *responseSerializer;
|
||||
|
||||
#pragma mark API Call Contstructors
|
||||
|
||||
+ (RPAPICall*)requestVerificationCode;
|
||||
+ (RPAPICall*)requestVerificationCodeWithVoice;
|
||||
+ (RPAPICall*)verifyVerificationCode:(NSString*)verificationCode;
|
||||
+ (RPAPICall*)registerPushNotificationWithPushToken:(NSData*)pushToken;
|
||||
+ (RPAPICall*)unregister;
|
||||
|
||||
+ (RPAPICall*)fetchBloomFilter;
|
||||
|
||||
//+ (RPAPICall*)requestToOpenPortWithSessionId:(int64_t)sessionId;
|
||||
//+ (RPAPICall*)requestToRingWithSessionId:(int64_t)sessionId;
|
||||
//+ (RPAPICall*)requestToSignalBusyWithSessionId:(int64_t)sessionId;
|
||||
//+ (RPAPICall*)requestToInitiateToRemoteNumber:(PhoneNumber*)remoteNumber;
|
||||
|
||||
@end
|
@ -0,0 +1,168 @@
|
||||
//
|
||||
// RedPhoneAPICall.m
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 05/10/14.
|
||||
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "Constraints.h"
|
||||
#import "CryptoTools.h"
|
||||
#import "PhoneNumber.h"
|
||||
#import "RPAPICall.h"
|
||||
#import "SignalUtil.h"
|
||||
#import "SGNKeychainUtil.h"
|
||||
#import "Util.h"
|
||||
|
||||
#define CLAIMED_INTEROP_VERSION_IN_INITIATE_SIGNAL 1
|
||||
|
||||
@interface RPAPICall ()
|
||||
@property (nonatomic, readwrite) NSString *endPoint;
|
||||
@property (nonatomic, readwrite) HTTPMethod method;
|
||||
@property (nonatomic, readwrite) NSDictionary *parameters;
|
||||
@property (nonatomic, readwrite) AFHTTPRequestSerializer <AFURLRequestSerialization> *requestSerializer;
|
||||
@property (nonatomic, readwrite) AFHTTPResponseSerializer <AFURLResponseSerialization> *responseSerializer;
|
||||
@end
|
||||
|
||||
@implementation RPAPICall
|
||||
|
||||
+ (RPAPICall*)defaultAPICall {
|
||||
RPAPICall *apiCall = [[RPAPICall alloc] init];
|
||||
apiCall.parameters = @{};
|
||||
apiCall.requestSerializer = [self basicAuthenticationSerializer];
|
||||
apiCall.responseSerializer = [AFHTTPResponseSerializer serializer];
|
||||
return apiCall;
|
||||
}
|
||||
|
||||
|
||||
+ (RPAPICall*)requestVerificationCode {
|
||||
[SGNKeychainUtil generateServerAuthPassword];
|
||||
RPAPICall *apiCall = [self defaultAPICall];
|
||||
apiCall.method = HTTP_GET;
|
||||
apiCall.endPoint = @"/users/verification";
|
||||
return apiCall;
|
||||
}
|
||||
|
||||
+ (RPAPICall*)requestVerificationCodeWithVoice {
|
||||
RPAPICall *apiCall = [self requestVerificationCode];
|
||||
apiCall.endPoint = [apiCall.endPoint stringByAppendingString:@"/voice"];
|
||||
return apiCall;
|
||||
}
|
||||
|
||||
+ (RPAPICall*)verifyVerificationCode:(NSString*)verificationCode {
|
||||
RPAPICall *apiCall = [self defaultAPICall];
|
||||
[SGNKeychainUtil generateSignaling];
|
||||
apiCall.method = HTTP_PUT;
|
||||
apiCall.endPoint = [NSString stringWithFormat:@"/users/verification/%@", SGNKeychainUtil.localNumber];
|
||||
|
||||
NSData* signalingCipherKey = SGNKeychainUtil.signalingCipherKey;
|
||||
NSData* signalingMacKey = SGNKeychainUtil.signalingMacKey;
|
||||
NSData* signalingExtraKeyData = SGNKeychainUtil.signalingCipherKey;
|
||||
NSString* encodedSignalingKey = @[signalingCipherKey, signalingMacKey, signalingExtraKeyData].concatDatas.encodedAsBase64;
|
||||
apiCall.parameters = @{@"key" : encodedSignalingKey, @"challenge" : verificationCode};
|
||||
return apiCall;
|
||||
}
|
||||
|
||||
+ (RPAPICall*)registerPushNotificationWithPushToken:(NSData*)pushToken {
|
||||
RPAPICall *apiCall = [self defaultAPICall];
|
||||
apiCall.method = HTTP_PUT;
|
||||
apiCall.endPoint = [NSString stringWithFormat:@"/apn/%@", pushToken.encodedAsHexString];
|
||||
return apiCall;
|
||||
}
|
||||
|
||||
+ (RPAPICall*)fetchBloomFilter {
|
||||
RPAPICall *apiCall = [self defaultAPICall];
|
||||
apiCall.method = HTTP_GET;
|
||||
apiCall.endPoint = @"/users/directory";
|
||||
apiCall.requestSerializer = [self otpAuthenticationSerializer];
|
||||
return apiCall;
|
||||
}
|
||||
|
||||
+ (RPAPICall*)unregister {
|
||||
RPAPICall *apiCall = [self defaultAPICall];
|
||||
apiCall.method = HTTP_GET;
|
||||
apiCall.endPoint = @"/users/directory";
|
||||
apiCall.requestSerializer = [self otpAuthenticationSerializer];
|
||||
return apiCall;
|
||||
}
|
||||
|
||||
+ (RPAPICall*)requestToOpenPortWithSessionId:(int64_t)sessionId {
|
||||
RPAPICall *apiCall = [self defaultAPICall];
|
||||
apiCall.method = HTTP_GET;
|
||||
apiCall.endPoint = [NSString stringWithFormat:@"/open/%lld", sessionId];
|
||||
apiCall.requestSerializer = [self unauthenticatedSerializer];
|
||||
apiCall.responseSerializer = [AFHTTPResponseSerializer serializer];
|
||||
return apiCall;
|
||||
}
|
||||
|
||||
+ (RPAPICall*)requestToRingWithSessionId:(int64_t)sessionId {
|
||||
RPAPICall *apiCall = [self defaultAPICall];
|
||||
apiCall.method = SIGNAL_RING;
|
||||
apiCall.endPoint = [NSString stringWithFormat:@"/session/%lld", sessionId];
|
||||
apiCall.requestSerializer = [self otpAuthenticationSerializer];
|
||||
return apiCall;
|
||||
}
|
||||
|
||||
+ (RPAPICall*)requestToSignalBusyWithSessionId:(int64_t)sessionId {
|
||||
RPAPICall *apiCall = [self defaultAPICall];
|
||||
apiCall.method = SIGNAL_BUSY;
|
||||
apiCall.endPoint = [NSString stringWithFormat:@"/session/%lld", sessionId];
|
||||
apiCall.requestSerializer = [self otpAuthenticationSerializer];
|
||||
return apiCall;
|
||||
}
|
||||
|
||||
+ (RPAPICall*)requestToInitiateToRemoteNumber:(PhoneNumber*)remoteNumber {
|
||||
RPAPICall *apiCall = [self defaultAPICall];
|
||||
|
||||
require(remoteNumber != nil);
|
||||
|
||||
NSString* formattedRemoteNumber = remoteNumber.toE164;
|
||||
NSString* interopVersionInsert = (CLAIMED_INTEROP_VERSION_IN_INITIATE_SIGNAL == 0)? @"" : [NSString stringWithFormat:@"/%d", CLAIMED_INTEROP_VERSION_IN_INITIATE_SIGNAL];
|
||||
|
||||
apiCall.method = HTTP_GET;
|
||||
apiCall.endPoint = [NSString stringWithFormat:@"/session%@/%@",
|
||||
interopVersionInsert,
|
||||
formattedRemoteNumber];
|
||||
apiCall.requestSerializer = [self otpAuthenticationSerializer];
|
||||
return apiCall;
|
||||
}
|
||||
|
||||
#pragma mark Authorization Headers
|
||||
|
||||
+ (AFHTTPRequestSerializer*)basicAuthenticationSerializer {
|
||||
AFHTTPRequestSerializer *serializer = [AFJSONRequestSerializer serializer];
|
||||
[serializer setAuthorizationHeaderFieldWithUsername:SGNKeychainUtil.localNumber.toE164 password:SGNKeychainUtil.serverAuthPassword];
|
||||
return serializer;
|
||||
}
|
||||
|
||||
+ (AFHTTPRequestSerializer*)otpAuthenticationSerializer {
|
||||
AFHTTPRequestSerializer *serializer = [AFJSONRequestSerializer serializer];
|
||||
[serializer setAuthorizationHeaderFieldWithUsername:SGNKeychainUtil.localNumber.toE164 password:SGNKeychainUtil.serverAuthPassword];
|
||||
return serializer;
|
||||
}
|
||||
|
||||
+ (AFHTTPRequestSerializer*)unauthenticatedSerializer {
|
||||
return [AFHTTPRequestSerializer serializer];
|
||||
}
|
||||
|
||||
+ (NSString*) computeOtpAuthorizationTokenForLocalNumber:(PhoneNumber*)localNumber
|
||||
andCounterValue:(int64_t)counterValue
|
||||
andPassword:(NSString*)password {
|
||||
require(localNumber != nil);
|
||||
require(password != nil);
|
||||
|
||||
NSString* rawToken = [NSString stringWithFormat:@"%@:%@:%lld",
|
||||
localNumber.toE164,
|
||||
[CryptoTools computeOtpWithPassword:password andCounter:counterValue],
|
||||
counterValue];
|
||||
return [@"OTP " stringByAppendingString:rawToken.encodedAsUtf8.encodedAsBase64];
|
||||
}
|
||||
|
||||
+ (NSString*) computeBasicAuthorizationTokenForLocalNumber:(PhoneNumber*)localNumber andPassword:(NSString*)password {
|
||||
NSString* rawToken = [NSString stringWithFormat:@"%@:%@",
|
||||
localNumber.toE164,
|
||||
password];
|
||||
return [@"Basic " stringByAppendingString:rawToken.encodedAsUtf8.encodedAsBase64];
|
||||
}
|
||||
|
||||
@end
|
@ -0,0 +1,22 @@
|
||||
//
|
||||
// CallServerRequests.h
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 31/07/14.
|
||||
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "RPAPICall.h"
|
||||
|
||||
#import <CollapsingFutures.h>
|
||||
|
||||
@interface RPServerRequestsManager : NSObject
|
||||
|
||||
MacrosSingletonInterface
|
||||
|
||||
- (void)performRequest:(RPAPICall*)apiCall success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure;
|
||||
|
||||
- (TOCFuture*)futureForRequest:(RPAPICall*)apiCall;
|
||||
|
||||
@end
|
@ -0,0 +1,96 @@
|
||||
//
|
||||
// CallServerRequests.m
|
||||
// Signal
|
||||
//
|
||||
// Created by Frederic Jacobs on 31/07/14.
|
||||
// Copyright (c) 2014 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
#import "HttpRequest.h"
|
||||
#import "RPServerRequestsManager.h"
|
||||
#import "Constraints.h"
|
||||
#import "CryptoTools.h"
|
||||
#import "DataUtil.h"
|
||||
#import "Environment.h"
|
||||
#import "HostNameEndPoint.h"
|
||||
#import "SGNKeychainUtil.h"
|
||||
#import "Util.h"
|
||||
|
||||
#import "AFHTTPSessionManager+SignalMethods.h"
|
||||
|
||||
@interface RPServerRequestsManager ()
|
||||
|
||||
@property (nonatomic, retain)AFHTTPSessionManager *operationManager;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation RPServerRequestsManager
|
||||
|
||||
MacrosSingletonImplemention
|
||||
|
||||
- (id)init{
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
HostNameEndPoint *endpoint = Environment.getCurrent.masterServerSecureEndPoint.hostNameEndPoint;
|
||||
NSURL *endPointURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://%@:%hu", endpoint.hostname, endpoint.port]];
|
||||
NSURLSessionConfiguration *sessionConf = NSURLSessionConfiguration.ephemeralSessionConfiguration;
|
||||
self.operationManager = [[AFHTTPSessionManager alloc] initWithBaseURL:endPointURL sessionConfiguration:sessionConf];
|
||||
self.operationManager.responseSerializer = [AFJSONResponseSerializer serializer];
|
||||
self.operationManager.securityPolicy.allowInvalidCertificates = YES;
|
||||
NSString *certPath = [NSBundle.mainBundle pathForResource:@"whisperReal" ofType:@"cer"];
|
||||
NSData *certData = [NSData dataWithContentsOfFile:certPath];
|
||||
SecCertificateRef cert = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)(certData));
|
||||
self.operationManager.securityPolicy.pinnedCertificates = @[(__bridge_transfer NSData *)SecCertificateCopyData(cert)];
|
||||
self.operationManager.securityPolicy.SSLPinningMode = AFSSLPinningModeCertificate;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)performRequest:(RPAPICall*)apiCall success:(void (^)(NSURLSessionDataTask *task, id responseObject))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure{
|
||||
|
||||
self.operationManager.requestSerializer = apiCall.requestSerializer;
|
||||
self.operationManager.responseSerializer = apiCall.responseSerializer;
|
||||
|
||||
switch (apiCall.method) {
|
||||
case HTTP_GET:
|
||||
[self.operationManager GET:apiCall.endPoint parameters:apiCall.parameters success:success failure:failure];
|
||||
break;
|
||||
|
||||
case HTTP_PUT:
|
||||
[self.operationManager PUT:apiCall.endPoint parameters:apiCall.parameters success:success failure:failure];
|
||||
break;
|
||||
|
||||
case HTTP_POST:
|
||||
[self.operationManager POST:apiCall.endPoint parameters:apiCall.parameters success:success failure:failure];
|
||||
break;
|
||||
|
||||
case HTTP_DELETE:
|
||||
[self.operationManager DELETE:apiCall.endPoint parameters:apiCall.parameters success:success failure:failure];
|
||||
break;
|
||||
|
||||
case SIGNAL_BUSY:
|
||||
[self.operationManager BUSY:apiCall.endPoint parameters:apiCall.parameters success:success failure:failure];
|
||||
break;
|
||||
|
||||
case SIGNAL_RING:
|
||||
[self.operationManager RING:apiCall.endPoint parameters:apiCall.parameters success:success failure:failure];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
- (TOCFuture*)futureForRequest:(RPAPICall*)apiCall{
|
||||
TOCFutureSource *requestFutureSource = [TOCFutureSource new];
|
||||
|
||||
[self performRequest:apiCall success:^(NSURLSessionDataTask *task, id responseObject) {
|
||||
NSLog(@"ResponseObject: %@", responseObject);
|
||||
[requestFutureSource trySetResult:task.response];
|
||||
} failure:^(NSURLSessionDataTask *task, NSError *error) {
|
||||
[requestFutureSource trySetFailure:error];
|
||||
}];
|
||||
|
||||
return [requestFutureSource future];
|
||||
|
||||
}
|
||||
|
||||
@end
|
Loading…
Reference in New Issue