2018-11-13 12:29:15 -08:00
|
|
|
//
|
|
|
|
|
// MBIMBridgeOperation.m
|
|
|
|
|
// kordophoned
|
|
|
|
|
//
|
|
|
|
|
// Created by James Magahern on 11/13/18.
|
|
|
|
|
// Copyright © 2018 James Magahern. All rights reserved.
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#import "MBIMBridgeOperation.h"
|
2023-01-17 16:16:23 -08:00
|
|
|
#import "MBIMURLUtilities.h"
|
2018-11-13 12:29:15 -08:00
|
|
|
|
|
|
|
|
@interface MBIMBridgeOperation (/*INTERNAL*/)
|
2018-11-16 01:30:38 -08:00
|
|
|
@property (nonatomic, strong) NSURL *requestURL;
|
|
|
|
|
@property (nonatomic, copy) MBIMBridgeOperationCompletionBlock serverCompletionBlock;
|
2018-11-13 12:29:15 -08:00
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
@implementation MBIMBridgeOperation
|
|
|
|
|
|
|
|
|
|
+ (NSString *)endpointName
|
|
|
|
|
{
|
|
|
|
|
// To be inplemented by subclasses
|
|
|
|
|
return @"__unimplemented__";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (NSMutableDictionary *)_operationClassMapping
|
|
|
|
|
{
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
static NSMutableDictionary *operationClassMapping = nil;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
operationClassMapping = [[NSMutableDictionary alloc] init];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return operationClassMapping;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-21 15:51:51 -07:00
|
|
|
+ (dispatch_queue_t)sharedIMAccessQueue
|
|
|
|
|
{
|
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
|
static dispatch_queue_t accessQueue = nil;
|
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
|
accessQueue = dispatch_queue_create("IMAccessQueue", DISPATCH_QUEUE_SERIAL);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return accessQueue;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-13 12:29:15 -08:00
|
|
|
+ (void)load
|
|
|
|
|
{
|
|
|
|
|
if ([self class] != [MBIMBridgeOperation class]) {
|
|
|
|
|
[[self _operationClassMapping] setObject:[self class] forKey:[self endpointName]];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (nullable Class)operationClassForEndpointName:(NSString *)endpointName
|
|
|
|
|
{
|
|
|
|
|
return [[self _operationClassMapping] objectForKey:endpointName];
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-06 22:52:33 -07:00
|
|
|
+ (BOOL)requiresAuthentication
|
|
|
|
|
{
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-16 01:30:38 -08:00
|
|
|
- (instancetype)initWithRequestURL:(NSURL *)requestURL completion:(MBIMBridgeOperationCompletionBlock)completionBlock
|
2018-11-13 12:29:15 -08:00
|
|
|
{
|
|
|
|
|
self = [super init];
|
|
|
|
|
if (self) {
|
2018-11-16 01:30:38 -08:00
|
|
|
self.requestURL = requestURL;
|
2018-11-13 12:29:15 -08:00
|
|
|
self.serverCompletionBlock = completionBlock;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 19:57:35 -07:00
|
|
|
- (NSObject<HTTPResponse> *)cancelAndReturnTimeoutResponse
|
|
|
|
|
{
|
|
|
|
|
[self cancel];
|
|
|
|
|
return [[HTTPErrorResponse alloc] initWithErrorCode:500];
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-21 15:51:51 -07:00
|
|
|
- (NSString *)valueForQueryItemWithName:(NSString *)queryItemName
|
|
|
|
|
{
|
2023-01-17 16:16:23 -08:00
|
|
|
return [[self requestURL] valueForQueryItemWithName:queryItemName];
|
2018-11-21 15:51:51 -07:00
|
|
|
}
|
|
|
|
|
|
2018-11-13 12:29:15 -08:00
|
|
|
@end
|