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) 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
method:(NSString *)method
parameters:(NSDictionary<NSString *, id> *)parameters;
parameters:(nullable NSDictionary<NSString *, id> *)parameters;
@end

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

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

Loading…
Cancel
Save