Clean up ahead of PR.

pull/1/head
Matthew Chen 7 years ago
parent 2395dbf66b
commit 3e6db43b24

@ -6,10 +6,22 @@
@property (nonatomic) BOOL shouldHaveAuthorizationHeaders; @property (nonatomic) BOOL shouldHaveAuthorizationHeaders;
@property (nonatomic) NSDictionary *parameters; @property (nonatomic, readonly) NSDictionary *parameters;
- (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithURL:(NSURL *)URL;
- (instancetype)initWithURL:(NSURL *)URL
cachePolicy:(NSURLRequestCachePolicy)cachePolicy
timeoutInterval:(NSTimeInterval)timeoutInterval NS_UNAVAILABLE;
- (instancetype)initWithURL:(NSURL *)URL
method:(NSString *)method
parameters:(nullable NSDictionary<NSString *, id> *)parameters;
+ (instancetype)requestWithUrl:(NSURL *)url + (instancetype)requestWithUrl:(NSURL *)url
method:(NSString *)method method:(NSString *)method
parameters:(NSDictionary<NSString *, id> *)parameters; parameters:(nullable NSDictionary<NSString *, id> *)parameters;
@end @end

@ -17,13 +17,14 @@
return nil; return nil;
} }
self.parameters = @{}; _parameters = @{};
self.shouldHaveAuthorizationHeaders = YES; self.shouldHaveAuthorizationHeaders = YES;
return self; return self;
} }
- (id)init { - (instancetype)init
{
OWSRaiseException(NSInternalInconsistencyException, @"You must use the initWithURL: method"); OWSRaiseException(NSInternalInconsistencyException, @"You must use the initWithURL: method");
return nil; return nil;
} }
@ -31,21 +32,41 @@
#pragma clang diagnostic push #pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wobjc-designated-initializers" #pragma clang diagnostic ignored "-Wobjc-designated-initializers"
- (id)initWithURL:(NSURL *)URL - (instancetype)initWithURL:(NSURL *)URL
cachePolicy:(NSURLRequestCachePolicy)cachePolicy cachePolicy:(NSURLRequestCachePolicy)cachePolicy
timeoutInterval:(NSTimeInterval)timeoutInterval { timeoutInterval:(NSTimeInterval)timeoutInterval
{
OWSRaiseException(NSInternalInconsistencyException, @"You must use the initWithURL method"); OWSRaiseException(NSInternalInconsistencyException, @"You must use the initWithURL method");
return nil; return nil;
} }
- (instancetype)initWithURL:(NSURL *)URL
method:(NSString *)method
parameters:(nullable NSDictionary<NSString *, id> *)parameters
{
OWSAssert(URL);
OWSAssert(method.length > 0);
OWSAssert(parameters);
self = [super initWithURL:URL
cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
timeoutInterval:textSecureHTTPTimeOut];
if (!self) {
return nil;
}
_parameters = parameters ?: @{};
[self setHTTPMethod:method];
self.shouldHaveAuthorizationHeaders = YES;
return self;
}
+ (instancetype)requestWithUrl:(NSURL *)url + (instancetype)requestWithUrl:(NSURL *)url
method:(NSString *)method method:(NSString *)method
parameters:(NSDictionary<NSString *, id> *)parameters parameters:(nullable NSDictionary<NSString *, id> *)parameters
{ {
TSRequest *request = [[TSRequest alloc] initWithURL:url]; return [[TSRequest alloc] initWithURL:url method:method parameters:parameters];
[request setHTTPMethod:method];
request.parameters = parameters;
return request;
} }
@end @end

@ -22,12 +22,8 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(signalingKey.length > 0); OWSAssert(signalingKey.length > 0);
OWSAssert(authKey.length > 0); OWSAssert(authKey.length > 0);
self = [super NSURL *url =
initWithURL:[NSURL URLWithString:[NSString [NSURL URLWithString:[NSString stringWithFormat:@"%@/code/%@", textSecureAccountsAPI, verificationCode]];
stringWithFormat:@"%@/code/%@", textSecureAccountsAPI, verificationCode]]];
_numberToValidate = phoneNumber;
NSMutableDictionary *parameters = NSMutableDictionary *parameters =
[[TSAttributes attributesWithSignalingKey:signalingKey serverAuthToken:authKey manualMessageFetching:NO] [[TSAttributes attributesWithSignalingKey:signalingKey serverAuthToken:authKey manualMessageFetching:NO]
mutableCopy]; mutableCopy];
@ -35,9 +31,9 @@ NS_ASSUME_NONNULL_BEGIN
OWSAssert(pin.length > 0); OWSAssert(pin.length > 0);
parameters[@"pin"] = pin; parameters[@"pin"] = pin;
} }
self.parameters = parameters; self = [super initWithURL:url method:@"PUT" parameters:parameters];
[self setHTTPMethod:@"PUT"]; _numberToValidate = phoneNumber;
return self; return self;
} }

Loading…
Cancel
Save