Elaborate request factory.

pull/1/head
Matthew Chen 7 years ago
parent df9cc1d9a6
commit 0ca497846b

@ -1,5 +1,5 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
import Foundation
@ -118,7 +118,7 @@ class MessageFetcherJob: NSObject {
return nil
}
guard let type = OWSSignalServiceProtosEnvelopeType(rawValue:typeInt) else {
guard let type = OWSSignalServiceProtosEnvelopeType(rawValue: typeInt) else {
Logger.error("\(self.logTag) message body type was invalid")
return nil
}
@ -189,7 +189,7 @@ class MessageFetcherJob: NSObject {
}
private func acknowledgeDelivery(envelope: OWSSignalServiceProtosEnvelope) {
let request = OWSAcknowledgeMessageDeliveryRequest(source: envelope.source, timestamp: envelope.timestamp)
let request = OWSRequestFactory.acknowledgeMessageDeliveryRequest(withSource: envelope.source, timestamp: envelope.timestamp)
self.networkManager.makeRequest(request,
success: { (_: URLSessionDataTask?, _: Any?) -> Void in
Logger.debug("\(self.logTag) acknowledged delivery for message at timestamp: \(envelope.timestamp)")

@ -73,7 +73,6 @@
#import <SignalServiceKit/NSNotificationCenter+OWS.h>
#import <SignalServiceKit/NSString+SSK.h>
#import <SignalServiceKit/NSTimer+OWS.h>
#import <SignalServiceKit/OWSAcknowledgeMessageDeliveryRequest.h>
#import <SignalServiceKit/OWSAnalytics.h>
#import <SignalServiceKit/OWSAnalyticsEvents.h>
#import <SignalServiceKit/OWSAsserts.h>
@ -99,6 +98,7 @@
#import <SignalServiceKit/OWSOutgoingCallMessage.h>
#import <SignalServiceKit/OWSProfileKeyMessage.h>
#import <SignalServiceKit/OWSRecipientIdentity.h>
#import <SignalServiceKit/OWSRequestFactory.h>
#import <SignalServiceKit/OWSSignalService.h>
#import <SignalServiceKit/OWSSyncContactsMessage.h>
#import <SignalServiceKit/OWSTurnServerInfoRequest.h>

@ -1,9 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSDeviceProvisioningCodeService.h"
#import "OWSDeviceProvisioningCodeRequest.h"
#import "OWSRequestFactory.h"
#import "TSNetworkManager.h"
NS_ASSUME_NONNULL_BEGIN
@ -39,7 +39,8 @@ NSString *const OWSDeviceProvisioningCodeServiceProvisioningCodeKey = @"verifica
- (void)requestProvisioningCodeWithSuccess:(void (^)(NSString *))successCallback
failure:(void (^)(NSError *))failureCallback
{
[self.networkManager makeRequest:[OWSDeviceProvisioningCodeRequest new]
TSRequest *request = [OWSRequestFactory deviceProvisioningCodeRequest];
[self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
DDLogVerbose(@"ProvisioningCode request succeeded");
if ([(NSObject *)responseObject isKindOfClass:[NSDictionary class]]) {

@ -1,9 +1,9 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSDeviceProvisioningService.h"
#import "OWSDeviceProvisioningRequest.h"
#import "OWSRequestFactory.h"
#import "TSNetworkManager.h"
NS_ASSUME_NONNULL_BEGIN
@ -38,9 +38,8 @@ NS_ASSUME_NONNULL_BEGIN
success:(void (^)(void))successCallback
failure:(void (^)(NSError *))failureCallback
{
OWSDeviceProvisioningRequest *request =
[[OWSDeviceProvisioningRequest alloc] initWithMessageBody:messageBody ephemeralDeviceId:deviceId];
TSRequest *request =
[OWSRequestFactory deviceProvisioningRequestWithMessageBody:messageBody ephemeralDeviceId:deviceId];
[self.networkManager makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {
DDLogVerbose(@"Provisioning request succeeded");

@ -1,12 +1,12 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSDevicesService.h"
#import "OWSDeleteDeviceRequest.h"
#import "OWSDevice.h"
#import "OWSError.h"
#import "OWSGetDevicesRequest.h"
#import "OWSRequestFactory.h"
#import "TSNetworkManager.h"
#import <Mantle/MTLJSONAdapter.h>
@ -44,7 +44,7 @@ NS_ASSUME_NONNULL_BEGIN
success:(void (^)(void))successCallback
failure:(void (^)(NSError *))failureCallback
{
OWSDeleteDeviceRequest *request = [[OWSDeleteDeviceRequest alloc] initWithDevice:device];
TSRequest *request = [OWSRequestFactory deleteDeviceRequestWithDevice:device];
[[TSNetworkManager sharedManager] makeRequest:request
success:^(NSURLSessionDataTask *task, id responseObject) {

@ -1,14 +0,0 @@
// Created by Michael Kirk on 12/19/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@interface OWSAcknowledgeMessageDeliveryRequest : TSRequest
- (instancetype)initWithSource:(NSString *)source timestamp:(UInt64)timestamp;
@end
NS_ASSUME_NONNULL_END

@ -1,23 +0,0 @@
// Created by Michael Kirk on 12/19/16.
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "OWSAcknowledgeMessageDeliveryRequest.h"
NS_ASSUME_NONNULL_BEGIN
@implementation OWSAcknowledgeMessageDeliveryRequest
- (instancetype)initWithSource:(NSString *)source timestamp:(UInt64)timestamp
{
NSString *path = [NSString stringWithFormat:@"v1/messages/%@/%llu", source, timestamp];
NSURL *url = [NSURL URLWithString:path];
self = [super initWithURL:url];
self.HTTPMethod = @"DELETE";
return self;
}
@end
NS_ASSUME_NONNULL_END

@ -1,17 +0,0 @@
//
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
//
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@class OWSDevice;
@interface OWSDeleteDeviceRequest : TSRequest
- (instancetype)initWithDevice:(OWSDevice *)device;
@end
NS_ASSUME_NONNULL_END

@ -1,27 +0,0 @@
// Copyright © 2016 Open Whisper Systems. All rights reserved.
#import "OWSDeleteDeviceRequest.h"
#import "OWSDevice.h"
#import "TSConstants.h"
NS_ASSUME_NONNULL_BEGIN
@implementation OWSDeleteDeviceRequest
- (instancetype)initWithDevice:(OWSDevice *)device
{
NSString *deleteDevicePath = [NSString
stringWithFormat:textSecureDevicesAPIFormat, [NSString stringWithFormat:@"%ld", (long)device.deviceId]];
self = [super initWithURL:[NSURL URLWithString:deleteDevicePath]];
if (!self) {
return self;
}
[self setHTTPMethod:@"DELETE"];
return self;
}
@end
NS_ASSUME_NONNULL_END

@ -1,11 +0,0 @@
// Copyright (c) 2016 Open Whisper Systems. All rights reserved.
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@interface OWSDeviceProvisioningCodeRequest : TSRequest
@end
NS_ASSUME_NONNULL_END

@ -1,24 +0,0 @@
// Copyright (c) 2016 Open Whisper Systems. All rights reserved.
#import "OWSDeviceProvisioningCodeRequest.h"
#import "TSConstants.h"
NS_ASSUME_NONNULL_BEGIN
@implementation OWSDeviceProvisioningCodeRequest
- (instancetype)init
{
self = [super initWithURL:[NSURL URLWithString:textSecureDeviceProvisioningCodeAPI]];
if (!self) {
return self;
}
[self setHTTPMethod:@"GET"];
return self;
}
@end
NS_ASSUME_NONNULL_END

@ -1,13 +0,0 @@
// Copyright (c) 2016 Open Whisper Systems. All rights reserved.
#import "TSRequest.h"
NS_ASSUME_NONNULL_BEGIN
@interface OWSDeviceProvisioningRequest : TSRequest
- (instancetype)initWithMessageBody:(NSData *)messageBody ephemeralDeviceId:(NSString *)deviceId;
@end
NS_ASSUME_NONNULL_END

@ -1,32 +0,0 @@
//
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
//
#import "OWSDeviceProvisioningRequest.h"
#import "TSConstants.h"
#import <SignalServiceKit/NSData+Base64.h>
NS_ASSUME_NONNULL_BEGIN
@implementation OWSDeviceProvisioningRequest
- (instancetype)initWithMessageBody:(NSData *)messageBody ephemeralDeviceId:(NSString *)deviceId
{
NSString *path = [NSString stringWithFormat:textSecureDeviceProvisioningAPIFormat, deviceId];
self = [super initWithURL:[NSURL URLWithString:path]];
if (!self) {
return self;
}
self.HTTPMethod = @"PUT";
self.parameters = @{
@"body" : [messageBody base64EncodedString],
};
return self;
}
@end
NS_ASSUME_NONNULL_END

@ -4,6 +4,7 @@
NS_ASSUME_NONNULL_BEGIN
@class OWSDevice;
@class TSRequest;
@interface OWSRequestFactory : NSObject
@ -14,6 +15,14 @@ NS_ASSUME_NONNULL_BEGIN
+ (TSRequest *)disable2FARequest;
+ (TSRequest *)acknowledgeMessageDeliveryRequestWithSource:(NSString *)source timestamp:(UInt64)timestamp;
+ (TSRequest *)deleteDeviceRequestWithDevice:(OWSDevice *)device;
+ (TSRequest *)deviceProvisioningCodeRequest;
+ (TSRequest *)deviceProvisioningRequestWithMessageBody:(NSData *)messageBody ephemeralDeviceId:(NSString *)deviceId;
@end
NS_ASSUME_NONNULL_END

@ -3,8 +3,10 @@
//
#import "OWSRequestFactory.h"
#import "OWSDevice.h"
#import "TSConstants.h"
#import "TSRequest.h"
#import <SignalServiceKit/NSData+Base64.h>
NS_ASSUME_NONNULL_BEGIN
@ -26,6 +28,45 @@ NS_ASSUME_NONNULL_BEGIN
return [TSRequest requestWithUrl:[NSURL URLWithString:textSecure2FAAPI] method:@"DELETE" parameters:@{}];
}
+ (TSRequest *)acknowledgeMessageDeliveryRequestWithSource:(NSString *)source timestamp:(UInt64)timestamp
{
OWSAssert(source.length > 0);
OWSAssert(timestamp > 0);
NSString *path = [NSString stringWithFormat:@"v1/messages/%@/%llu", source, timestamp];
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"DELETE" parameters:@{}];
}
+ (TSRequest *)deleteDeviceRequestWithDevice:(OWSDevice *)device
{
OWSAssert(device);
NSString *path = [NSString stringWithFormat:textSecureDevicesAPIFormat, @(device.deviceId)];
return [TSRequest requestWithUrl:[NSURL URLWithString:path] method:@"DELETE" parameters:@{}];
}
+ (TSRequest *)deviceProvisioningCodeRequest
{
return [TSRequest requestWithUrl:[NSURL URLWithString:textSecureDeviceProvisioningCodeAPI]
method:@"GET"
parameters:@{}];
}
+ (TSRequest *)deviceProvisioningRequestWithMessageBody:(NSData *)messageBody ephemeralDeviceId:(NSString *)deviceId
{
OWSAssert(messageBody.length > 0);
OWSAssert(deviceId.length > 0);
NSString *path = [NSString stringWithFormat:textSecureDeviceProvisioningAPIFormat, deviceId];
return [TSRequest requestWithUrl:[NSURL URLWithString:path]
method:@"PUT"
parameters:@{
@"body" : [messageBody base64EncodedString],
}];
}
@end
NS_ASSUME_NONNULL_END

Loading…
Cancel
Save