mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-08-02 00:17:02 +00:00
factor out BITHockeyAppClient to provide network services
* factor out HockeyAppClient * configure Authenticator with HockeyAppClient * move appendPostValue to HockeyAppClient (& add the missing boundary parameter) * move tests over to new file
This commit is contained in:
parent
6a0cfdd4dc
commit
96304ac639
@ -9,6 +9,7 @@
|
|||||||
#import <UIKit/UIKit.h>
|
#import <UIKit/UIKit.h>
|
||||||
@protocol BITAuthenticationViewControllerDelegate;
|
@protocol BITAuthenticationViewControllerDelegate;
|
||||||
@class BITAuthenticator;
|
@class BITAuthenticator;
|
||||||
|
@class BITHockeyAppClient;
|
||||||
|
|
||||||
@interface BITAuthenticationViewController : UITableViewController
|
@interface BITAuthenticationViewController : UITableViewController
|
||||||
|
|
||||||
@ -16,6 +17,11 @@
|
|||||||
requirePassword:(BOOL) requiresPassword
|
requirePassword:(BOOL) requiresPassword
|
||||||
delegate:(id<BITAuthenticationViewControllerDelegate>) delegate;
|
delegate:(id<BITAuthenticationViewControllerDelegate>) delegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* must be set
|
||||||
|
*/
|
||||||
|
@property (nonatomic, strong) BITHockeyAppClient *hockeyAppClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The application's id to identifiy it in the backend
|
* The application's id to identifiy it in the backend
|
||||||
*/
|
*/
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#import "BITAuthenticator_Private.h"
|
#import "BITAuthenticator_Private.h"
|
||||||
#import "HockeySDKPrivate.h"
|
#import "HockeySDKPrivate.h"
|
||||||
#import "HockeySDK.h"
|
#import "HockeySDK.h"
|
||||||
|
#import "BITHockeyAppClient.h"
|
||||||
|
|
||||||
@interface BITAuthenticationViewController ()<UITextFieldDelegate> {
|
@interface BITAuthenticationViewController ()<UITextFieldDelegate> {
|
||||||
UIStatusBarStyle _statusBarStyle;
|
UIStatusBarStyle _statusBarStyle;
|
||||||
@ -244,7 +245,7 @@
|
|||||||
NSDictionary *params = [self parametersForAuthentication];
|
NSDictionary *params = [self parametersForAuthentication];
|
||||||
|
|
||||||
__weak typeof (self) weakSelf = self;
|
__weak typeof (self) weakSelf = self;
|
||||||
[self.authenticator postPath:authenticationPath
|
[self.hockeyAppClient postPath:authenticationPath
|
||||||
parameters:params
|
parameters:params
|
||||||
completion:^(BITHTTPOperation *operation, id response, NSError *error) {
|
completion:^(BITHTTPOperation *operation, id response, NSError *error) {
|
||||||
typeof (self) strongSelf = weakSelf;
|
typeof (self) strongSelf = weakSelf;
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
#import "HockeySDKPrivate.h"
|
#import "HockeySDKPrivate.h"
|
||||||
#import "BITAuthenticator_Private.h"
|
#import "BITAuthenticator_Private.h"
|
||||||
#import "BITHTTPOperation.h"
|
#import "BITHTTPOperation.h"
|
||||||
|
#import "BITHockeyAppClient.h"
|
||||||
|
|
||||||
static NSString* const kBITAuthenticatorAuthTokenKey = @"BITAuthenticatorAuthTokenKey";
|
static NSString* const kBITAuthenticatorAuthTokenKey = @"BITAuthenticatorAuthTokenKey";
|
||||||
static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthenticatorLastAuthenticatedVersionKey";
|
static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthenticatorLastAuthenticatedVersionKey";
|
||||||
@ -23,7 +24,6 @@ static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthe
|
|||||||
|
|
||||||
- (void)dealloc {
|
- (void)dealloc {
|
||||||
[self unregisterObservers];
|
[self unregisterObservers];
|
||||||
[self cancelOperationsWithPath:nil method:nil];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (instancetype) initWithAppIdentifier:(NSString *)appIdentifier isAppStoreEnvironemt:(BOOL)isAppStoreEnvironment {
|
- (instancetype) initWithAppIdentifier:(NSString *)appIdentifier isAppStoreEnvironemt:(BOOL)isAppStoreEnvironment {
|
||||||
@ -107,7 +107,7 @@ static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthe
|
|||||||
} else {
|
} else {
|
||||||
NSString *validationPath = [NSString stringWithFormat:@"api/3/apps/%@/identity/validate", self.encodedAppIdentifier];
|
NSString *validationPath = [NSString stringWithFormat:@"api/3/apps/%@/identity/validate", self.encodedAppIdentifier];
|
||||||
__weak typeof (self) weakSelf = self;
|
__weak typeof (self) weakSelf = self;
|
||||||
[self getPath:validationPath
|
[self.hockeyAppClient getPath:validationPath
|
||||||
parameters:[self validationParameters]
|
parameters:[self validationParameters]
|
||||||
completion:^(BITHTTPOperation *operation, id response, NSError *error) {
|
completion:^(BITHTTPOperation *operation, id response, NSError *error) {
|
||||||
typeof (self) strongSelf = weakSelf;
|
typeof (self) strongSelf = weakSelf;
|
||||||
@ -376,119 +376,4 @@ static NSString* const kBITAuthenticatorLastAuthenticatedVersionKey = @"BITAuthe
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#pragma mark - Networking
|
|
||||||
- (NSMutableURLRequest *) requestWithMethod:(NSString*) method
|
|
||||||
path:(NSString *) path
|
|
||||||
parameters:(NSDictionary *)params {
|
|
||||||
NSParameterAssert(self.serverURL);
|
|
||||||
NSParameterAssert(method);
|
|
||||||
NSParameterAssert(params == nil || [method isEqualToString:@"POST"] || [method isEqualToString:@"GET"]);
|
|
||||||
path = path ? : @"";
|
|
||||||
|
|
||||||
NSURL *endpoint = [[NSURL URLWithString:self.serverURL] URLByAppendingPathComponent:path];
|
|
||||||
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:endpoint];
|
|
||||||
request.HTTPMethod = method;
|
|
||||||
|
|
||||||
if (params) {
|
|
||||||
if ([method isEqualToString:@"GET"]) {
|
|
||||||
NSString *absoluteURLString = [endpoint absoluteString];
|
|
||||||
//either path already has parameters, or not
|
|
||||||
NSString *appenderFormat = [path rangeOfString:@"?"].location == NSNotFound ? @"?%@" : @"&%@";
|
|
||||||
|
|
||||||
endpoint = [NSURL URLWithString:[absoluteURLString stringByAppendingFormat:appenderFormat,
|
|
||||||
[self.class queryStringFromParameters:params withEncoding:NSUTF8StringEncoding]]];
|
|
||||||
[request setURL:endpoint];
|
|
||||||
} else {
|
|
||||||
//TODO: this is crap. Boundary must be the same as the one in appendData
|
|
||||||
//unify this!
|
|
||||||
NSString *boundary = @"----FOO";
|
|
||||||
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
|
|
||||||
[request setValue:contentType forHTTPHeaderField:@"Content-type"];
|
|
||||||
|
|
||||||
NSMutableData *postBody = [NSMutableData data];
|
|
||||||
[params enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
|
|
||||||
[postBody appendData:[self appendPostValue:value forKey:key]];
|
|
||||||
}];
|
|
||||||
|
|
||||||
[postBody appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
|
|
||||||
|
|
||||||
[request setHTTPBody:postBody];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return request;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSString *) queryStringFromParameters:(NSDictionary *) params withEncoding:(NSStringEncoding) encoding {
|
|
||||||
NSMutableString *queryString = [NSMutableString new];
|
|
||||||
[params enumerateKeysAndObjectsUsingBlock:^(NSString* key, NSString* value, BOOL *stop) {
|
|
||||||
NSAssert([key isKindOfClass:[NSString class]], @"Query parameters can only be string-string pairs");
|
|
||||||
NSAssert([value isKindOfClass:[NSString class]], @"Query parameters can only be string-string pairs");
|
|
||||||
|
|
||||||
[queryString appendFormat:queryString.length ? @"&%@=%@" : @"%@=%@", key, value];
|
|
||||||
}];
|
|
||||||
return queryString;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (BITHTTPOperation*) operationWithURLRequest:(NSURLRequest*) request
|
|
||||||
completion:(BITNetworkCompletionBlock) completion {
|
|
||||||
BITHTTPOperation *operation = [BITHTTPOperation operationWithRequest:request
|
|
||||||
];
|
|
||||||
[operation setCompletion:completion];
|
|
||||||
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)getPath:(NSString *)path parameters:(NSDictionary *)params completion:(BITNetworkCompletionBlock)completion {
|
|
||||||
NSURLRequest *request = [self requestWithMethod:@"GET" path:path parameters:params];
|
|
||||||
BITHTTPOperation *op = [self operationWithURLRequest:request
|
|
||||||
completion:completion];
|
|
||||||
[self enqeueHTTPOperation:op];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)postPath:(NSString *)path parameters:(NSDictionary *)params completion:(BITNetworkCompletionBlock)completion {
|
|
||||||
NSURLRequest *request = [self requestWithMethod:@"POST" path:path parameters:params];
|
|
||||||
BITHTTPOperation *op = [self operationWithURLRequest:request
|
|
||||||
completion:completion];
|
|
||||||
[self enqeueHTTPOperation:op];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) enqeueHTTPOperation:(BITHTTPOperation *) operation {
|
|
||||||
[self.operationQueue addOperation:operation];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSUInteger) cancelOperationsWithPath:(NSString*) path
|
|
||||||
method:(NSString*) method {
|
|
||||||
NSUInteger cancelledOperations = 0;
|
|
||||||
for(BITHTTPOperation *operation in self.operationQueue.operations) {
|
|
||||||
NSURLRequest *request = operation.URLRequest;
|
|
||||||
|
|
||||||
BOOL matchedMethod = YES;
|
|
||||||
if(method && ![request.HTTPMethod isEqualToString:method]) {
|
|
||||||
matchedMethod = NO;
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL matchedPath = YES;
|
|
||||||
if(path) {
|
|
||||||
//method is not interesting here, we' just creating it to get the URL
|
|
||||||
NSURL *url = [self requestWithMethod:@"GET" path:path parameters:nil].URL;
|
|
||||||
matchedPath = [request.URL isEqual:url];
|
|
||||||
}
|
|
||||||
|
|
||||||
if(matchedPath && matchedMethod) {
|
|
||||||
++cancelledOperations;
|
|
||||||
[operation cancel];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return cancelledOperations;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (NSOperationQueue *)operationQueue {
|
|
||||||
if(nil == _operationQueue) {
|
|
||||||
_operationQueue = [[NSOperationQueue alloc] init];
|
|
||||||
_operationQueue.maxConcurrentOperationCount = 1;
|
|
||||||
}
|
|
||||||
return _operationQueue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -9,10 +9,15 @@
|
|||||||
#import "BITAuthenticator.h"
|
#import "BITAuthenticator.h"
|
||||||
#import "BITHockeyBaseManagerPrivate.h"
|
#import "BITHockeyBaseManagerPrivate.h"
|
||||||
#import "BITAuthenticationViewController.h"
|
#import "BITAuthenticationViewController.h"
|
||||||
#import "BITHTTPOperation.h" //needed for typedef
|
@class BITHockeyAppClient;
|
||||||
|
|
||||||
@interface BITAuthenticator ()<BITAuthenticationViewControllerDelegate>
|
@interface BITAuthenticator ()<BITAuthenticationViewControllerDelegate>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* must be set
|
||||||
|
*/
|
||||||
|
@property (nonatomic, strong) BITHockeyAppClient *hockeyAppClient;
|
||||||
|
|
||||||
//can be set for testing
|
//can be set for testing
|
||||||
@property (nonatomic) UIDevice *currentDevice;
|
@property (nonatomic) UIDevice *currentDevice;
|
||||||
|
|
||||||
@ -46,72 +51,4 @@
|
|||||||
- (void) validationSucceededWithCompletion:(tValidationCompletion) completion;
|
- (void) validationSucceededWithCompletion:(tValidationCompletion) completion;
|
||||||
- (void) validationFailedWithError:(NSError *) validationError completion:(tValidationCompletion) completion;
|
- (void) validationFailedWithError:(NSError *) validationError completion:(tValidationCompletion) completion;
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - Networking helpers (TODO: move to base-class / networking component)
|
|
||||||
@property (nonatomic, strong) NSOperationQueue *operationQueue;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* creates an NRURLRequest for the given method and path by using
|
|
||||||
* the internally stored baseURL.
|
|
||||||
*
|
|
||||||
* @param method the HTTPMethod to check, must not be nil
|
|
||||||
* @param params parameters for the request (only supported for GET and POST for now)
|
|
||||||
* @param path path to append to baseURL. can be nil in which case "/" is appended
|
|
||||||
*
|
|
||||||
* @return an NSMutableURLRequest for further configuration
|
|
||||||
*/
|
|
||||||
- (NSMutableURLRequest *) requestWithMethod:(NSString*) method
|
|
||||||
path:(NSString *) path
|
|
||||||
parameters:(NSDictionary *) params;
|
|
||||||
/**
|
|
||||||
* Creates an operation for the given NSURLRequest
|
|
||||||
*
|
|
||||||
* @param request the request that should be handled
|
|
||||||
* @param completion completionBlock that is called once the operation finished
|
|
||||||
*
|
|
||||||
* @return operation, which can be queued via enqueueHTTPOperation:
|
|
||||||
*/
|
|
||||||
- (BITHTTPOperation*) operationWithURLRequest:(NSURLRequest*) request
|
|
||||||
completion:(BITNetworkCompletionBlock) completion;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an operation for the given path, and enqueues it
|
|
||||||
*
|
|
||||||
* @param path the request path to check
|
|
||||||
* @param params parameters for the request
|
|
||||||
* @param completion completionBlock that is called once the operation finished
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
- (void) getPath:(NSString*) path
|
|
||||||
parameters:(NSDictionary *) params
|
|
||||||
completion:(BITNetworkCompletionBlock) completion;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an operation for the given path, and enqueues it
|
|
||||||
*
|
|
||||||
* @param path the request path to check
|
|
||||||
* @param params parameters for the request
|
|
||||||
* @param completion completionBlock that is called once the operation finished
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
- (void) postPath:(NSString*) path
|
|
||||||
parameters:(NSDictionary *) params
|
|
||||||
completion:(BITNetworkCompletionBlock) completion;
|
|
||||||
/**
|
|
||||||
* adds the given operation to the internal queue
|
|
||||||
*
|
|
||||||
* @param operation operation to add
|
|
||||||
*/
|
|
||||||
- (void) enqeueHTTPOperation:(BITHTTPOperation *) operation;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* cancels the specified operations
|
|
||||||
*
|
|
||||||
* @param path the path which operation should be cancelled. Can be nil to match all
|
|
||||||
* @param method the method which operations to cancel. Can be nil to match all
|
|
||||||
* @return number of operations cancelled
|
|
||||||
*/
|
|
||||||
- (NSUInteger) cancelOperationsWithPath:(NSString*) path
|
|
||||||
method:(NSString*) method;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
#import "BITHockeyManagerPrivate.h"
|
#import "BITHockeyManagerPrivate.h"
|
||||||
|
|
||||||
#import "BITHockeyHelper.h"
|
#import "BITHockeyHelper.h"
|
||||||
|
#import "BITHockeyAppClient.h"
|
||||||
|
|
||||||
#define kBITFeedbackUserDataAsked @"HockeyFeedbackUserDataAsked"
|
#define kBITFeedbackUserDataAsked @"HockeyFeedbackUserDataAsked"
|
||||||
#define kBITFeedbackDateOfLastCheck @"HockeyFeedbackDateOfLastCheck"
|
#define kBITFeedbackDateOfLastCheck @"HockeyFeedbackDateOfLastCheck"
|
||||||
@ -749,27 +749,27 @@
|
|||||||
|
|
||||||
NSMutableData *postBody = [NSMutableData data];
|
NSMutableData *postBody = [NSMutableData data];
|
||||||
|
|
||||||
[postBody appendData:[self appendPostValue:@"Apple" forKey:@"oem"]];
|
[postBody appendData:[BITHockeyAppClient dataWithPostValue:@"Apple" forKey:@"oem" boundary:boundary]];
|
||||||
[postBody appendData:[self appendPostValue:[[UIDevice currentDevice] systemVersion] forKey:@"os_version"]];
|
[postBody appendData:[BITHockeyAppClient dataWithPostValue:[[UIDevice currentDevice] systemVersion] forKey:@"os_version" boundary:boundary]];
|
||||||
[postBody appendData:[self appendPostValue:[self getDevicePlatform] forKey:@"model"]];
|
[postBody appendData:[BITHockeyAppClient dataWithPostValue:[self getDevicePlatform] forKey:@"model" boundary:boundary]];
|
||||||
[postBody appendData:[self appendPostValue:[[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0] forKey:@"lang"]];
|
[postBody appendData:[BITHockeyAppClient dataWithPostValue:[[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0] forKey:@"lang" boundary:boundary]];
|
||||||
[postBody appendData:[self appendPostValue:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] forKey:@"bundle_version"]];
|
[postBody appendData:[BITHockeyAppClient dataWithPostValue:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"] forKey:@"bundle_version" boundary:boundary]];
|
||||||
[postBody appendData:[self appendPostValue:[message text] forKey:@"text"]];
|
[postBody appendData:[BITHockeyAppClient dataWithPostValue:[message text] forKey:@"text" boundary:boundary]];
|
||||||
[postBody appendData:[self appendPostValue:[message token] forKey:@"message_token"]];
|
[postBody appendData:[BITHockeyAppClient dataWithPostValue:[message token] forKey:@"message_token" boundary:boundary]];
|
||||||
|
|
||||||
NSString *installString = bit_appAnonID();
|
NSString *installString = bit_appAnonID();
|
||||||
if (installString) {
|
if (installString) {
|
||||||
[postBody appendData:[self appendPostValue:installString forKey:@"install_string"]];
|
[postBody appendData:[BITHockeyAppClient dataWithPostValue:installString forKey:@"install_string" boundary:boundary]];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self.userID) {
|
if (self.userID) {
|
||||||
[postBody appendData:[self appendPostValue:self.userID forKey:@"user_string"]];
|
[postBody appendData:[BITHockeyAppClient dataWithPostValue:self.userID forKey:@"user_string" boundary:boundary]];
|
||||||
}
|
}
|
||||||
if (self.userName) {
|
if (self.userName) {
|
||||||
[postBody appendData:[self appendPostValue:self.userName forKey:@"name"]];
|
[postBody appendData:[BITHockeyAppClient dataWithPostValue:self.userName forKey:@"name" boundary:boundary]];
|
||||||
}
|
}
|
||||||
if (self.userEmail) {
|
if (self.userEmail) {
|
||||||
[postBody appendData:[self appendPostValue:self.userEmail forKey:@"email"]];
|
[postBody appendData:[BITHockeyAppClient dataWithPostValue:self.userEmail forKey:@"email" boundary:boundary]];
|
||||||
}
|
}
|
||||||
|
|
||||||
[postBody appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
|
[postBody appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
|
||||||
|
108
Classes/BITHockeyAppClient.h
Normal file
108
Classes/BITHockeyAppClient.h
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
//
|
||||||
|
// BITHockeyAppClient.h
|
||||||
|
// HockeySDK
|
||||||
|
//
|
||||||
|
// Created by Stephan Diederich on 06.09.13.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
#import "BITHTTPOperation.h" //needed for typedef
|
||||||
|
|
||||||
|
@interface BITHockeyAppClient : NSObject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* designated initializer
|
||||||
|
*
|
||||||
|
* @param baseURL the baseURL of the HockeyApp instance
|
||||||
|
*/
|
||||||
|
- (instancetype) initWithBaseURL:(NSURL*) baseURL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* baseURL to which relative paths are appended
|
||||||
|
*/
|
||||||
|
@property (nonatomic, strong) NSURL *baseURL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* creates an NRURLRequest for the given method and path by using
|
||||||
|
* the internally stored baseURL.
|
||||||
|
*
|
||||||
|
* @param method the HTTPMethod to check, must not be nil
|
||||||
|
* @param params parameters for the request (only supported for GET and POST for now)
|
||||||
|
* @param path path to append to baseURL. can be nil in which case "/" is appended
|
||||||
|
*
|
||||||
|
* @return an NSMutableURLRequest for further configuration
|
||||||
|
*/
|
||||||
|
- (NSMutableURLRequest *) requestWithMethod:(NSString*) method
|
||||||
|
path:(NSString *) path
|
||||||
|
parameters:(NSDictionary *) params;
|
||||||
|
/**
|
||||||
|
* Creates an operation for the given NSURLRequest
|
||||||
|
*
|
||||||
|
* @param request the request that should be handled
|
||||||
|
* @param completion completionBlock that is called once the operation finished
|
||||||
|
*
|
||||||
|
* @return operation, which can be queued via enqueueHTTPOperation:
|
||||||
|
*/
|
||||||
|
- (BITHTTPOperation*) operationWithURLRequest:(NSURLRequest*) request
|
||||||
|
completion:(BITNetworkCompletionBlock) completion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an operation for the given path, and enqueues it
|
||||||
|
*
|
||||||
|
* @param path the request path to check
|
||||||
|
* @param params parameters for the request
|
||||||
|
* @param completion completionBlock that is called once the operation finished
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
- (void) getPath:(NSString*) path
|
||||||
|
parameters:(NSDictionary *) params
|
||||||
|
completion:(BITNetworkCompletionBlock) completion;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an operation for the given path, and enqueues it
|
||||||
|
*
|
||||||
|
* @param path the request path to check
|
||||||
|
* @param params parameters for the request
|
||||||
|
* @param completion completionBlock that is called once the operation finished
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
- (void) postPath:(NSString*) path
|
||||||
|
parameters:(NSDictionary *) params
|
||||||
|
completion:(BITNetworkCompletionBlock) completion;
|
||||||
|
/**
|
||||||
|
* adds the given operation to the internal queue
|
||||||
|
*
|
||||||
|
* @param operation operation to add
|
||||||
|
*/
|
||||||
|
- (void) enqeueHTTPOperation:(BITHTTPOperation *) operation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cancels the specified operations
|
||||||
|
*
|
||||||
|
* @param path the path which operation should be cancelled. Can be nil to match all
|
||||||
|
* @param method the method which operations to cancel. Can be nil to match all
|
||||||
|
* @return number of operations cancelled
|
||||||
|
*/
|
||||||
|
- (NSUInteger) cancelOperationsWithPath:(NSString*) path
|
||||||
|
method:(NSString*) method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Access to the internal operation queue
|
||||||
|
*/
|
||||||
|
@property (nonatomic, strong) NSOperationQueue *operationQueue;
|
||||||
|
|
||||||
|
#pragma mark - Helpers
|
||||||
|
/**
|
||||||
|
* create a post body from the given value, key and boundary
|
||||||
|
* c/p from HockeyBaseManager
|
||||||
|
*
|
||||||
|
* @param value -
|
||||||
|
* @param key -
|
||||||
|
* @param boundary -
|
||||||
|
*
|
||||||
|
* @return NSData instance configured to be attached on a (post) URLRequest
|
||||||
|
*/
|
||||||
|
+ (NSData *)dataWithPostValue:(NSString *)value forKey:(NSString *)key boundary:(NSString *) boundary;
|
||||||
|
@end
|
153
Classes/BITHockeyAppClient.m
Normal file
153
Classes/BITHockeyAppClient.m
Normal file
@ -0,0 +1,153 @@
|
|||||||
|
//
|
||||||
|
// BITHockeyAppClient.m
|
||||||
|
// HockeySDK
|
||||||
|
//
|
||||||
|
// Created by Stephan Diederich on 06.09.13.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
#import "BITHockeyAppClient.h"
|
||||||
|
|
||||||
|
@implementation BITHockeyAppClient
|
||||||
|
- (void)dealloc {
|
||||||
|
[self cancelOperationsWithPath:nil method:nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (instancetype)initWithBaseURL:(NSURL *)baseURL {
|
||||||
|
self = [super init];
|
||||||
|
if ( self ) {
|
||||||
|
NSParameterAssert(baseURL);
|
||||||
|
_baseURL = baseURL;
|
||||||
|
}
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Networking
|
||||||
|
- (NSMutableURLRequest *) requestWithMethod:(NSString*) method
|
||||||
|
path:(NSString *) path
|
||||||
|
parameters:(NSDictionary *)params {
|
||||||
|
NSParameterAssert(self.baseURL);
|
||||||
|
NSParameterAssert(method);
|
||||||
|
NSParameterAssert(params == nil || [method isEqualToString:@"POST"] || [method isEqualToString:@"GET"]);
|
||||||
|
path = path ? : @"";
|
||||||
|
|
||||||
|
NSURL *endpoint = [self.baseURL URLByAppendingPathComponent:path];
|
||||||
|
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:endpoint];
|
||||||
|
request.HTTPMethod = method;
|
||||||
|
|
||||||
|
if (params) {
|
||||||
|
if ([method isEqualToString:@"GET"]) {
|
||||||
|
NSString *absoluteURLString = [endpoint absoluteString];
|
||||||
|
//either path already has parameters, or not
|
||||||
|
NSString *appenderFormat = [path rangeOfString:@"?"].location == NSNotFound ? @"?%@" : @"&%@";
|
||||||
|
|
||||||
|
endpoint = [NSURL URLWithString:[absoluteURLString stringByAppendingFormat:appenderFormat,
|
||||||
|
[self.class queryStringFromParameters:params withEncoding:NSUTF8StringEncoding]]];
|
||||||
|
[request setURL:endpoint];
|
||||||
|
} else {
|
||||||
|
//TODO: this is crap. Boundary must be the same as the one in appendData
|
||||||
|
//unify this!
|
||||||
|
NSString *boundary = @"----FOO";
|
||||||
|
NSString *contentType = [NSString stringWithFormat:@"multipart/form-data; boundary=%@", boundary];
|
||||||
|
[request setValue:contentType forHTTPHeaderField:@"Content-type"];
|
||||||
|
|
||||||
|
NSMutableData *postBody = [NSMutableData data];
|
||||||
|
[params enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
|
||||||
|
[postBody appendData:[[self class] dataWithPostValue:value forKey:key boundary:boundary]];
|
||||||
|
}];
|
||||||
|
|
||||||
|
[postBody appendData:[[NSString stringWithFormat:@"--%@--\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
|
||||||
|
|
||||||
|
[request setHTTPBody:postBody];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return request;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (NSData *)dataWithPostValue:(NSString *)value forKey:(NSString *)key boundary:(NSString *) boundary {
|
||||||
|
NSMutableData *postBody = [NSMutableData data];
|
||||||
|
|
||||||
|
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
|
||||||
|
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\";\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]];
|
||||||
|
[postBody appendData:[[NSString stringWithFormat:@"Content-Type: text\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
|
||||||
|
[postBody appendData:[value dataUsingEncoding:NSUTF8StringEncoding]];
|
||||||
|
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
|
||||||
|
|
||||||
|
return postBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
+ (NSString *) queryStringFromParameters:(NSDictionary *) params withEncoding:(NSStringEncoding) encoding {
|
||||||
|
NSMutableString *queryString = [NSMutableString new];
|
||||||
|
[params enumerateKeysAndObjectsUsingBlock:^(NSString* key, NSString* value, BOOL *stop) {
|
||||||
|
NSAssert([key isKindOfClass:[NSString class]], @"Query parameters can only be string-string pairs");
|
||||||
|
NSAssert([value isKindOfClass:[NSString class]], @"Query parameters can only be string-string pairs");
|
||||||
|
|
||||||
|
[queryString appendFormat:queryString.length ? @"&%@=%@" : @"%@=%@", key, value];
|
||||||
|
}];
|
||||||
|
return queryString;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BITHTTPOperation*) operationWithURLRequest:(NSURLRequest*) request
|
||||||
|
completion:(BITNetworkCompletionBlock) completion {
|
||||||
|
BITHTTPOperation *operation = [BITHTTPOperation operationWithRequest:request
|
||||||
|
];
|
||||||
|
[operation setCompletion:completion];
|
||||||
|
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)getPath:(NSString *)path parameters:(NSDictionary *)params completion:(BITNetworkCompletionBlock)completion {
|
||||||
|
NSURLRequest *request = [self requestWithMethod:@"GET" path:path parameters:params];
|
||||||
|
BITHTTPOperation *op = [self operationWithURLRequest:request
|
||||||
|
completion:completion];
|
||||||
|
[self enqeueHTTPOperation:op];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)postPath:(NSString *)path parameters:(NSDictionary *)params completion:(BITNetworkCompletionBlock)completion {
|
||||||
|
NSURLRequest *request = [self requestWithMethod:@"POST" path:path parameters:params];
|
||||||
|
BITHTTPOperation *op = [self operationWithURLRequest:request
|
||||||
|
completion:completion];
|
||||||
|
[self enqeueHTTPOperation:op];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) enqeueHTTPOperation:(BITHTTPOperation *) operation {
|
||||||
|
[self.operationQueue addOperation:operation];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSUInteger) cancelOperationsWithPath:(NSString*) path
|
||||||
|
method:(NSString*) method {
|
||||||
|
NSUInteger cancelledOperations = 0;
|
||||||
|
for(BITHTTPOperation *operation in self.operationQueue.operations) {
|
||||||
|
NSURLRequest *request = operation.URLRequest;
|
||||||
|
|
||||||
|
BOOL matchedMethod = YES;
|
||||||
|
if(method && ![request.HTTPMethod isEqualToString:method]) {
|
||||||
|
matchedMethod = NO;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL matchedPath = YES;
|
||||||
|
if(path) {
|
||||||
|
//method is not interesting here, we' just creating it to get the URL
|
||||||
|
NSURL *url = [self requestWithMethod:@"GET" path:path parameters:nil].URL;
|
||||||
|
matchedPath = [request.URL isEqual:url];
|
||||||
|
}
|
||||||
|
|
||||||
|
if(matchedPath && matchedMethod) {
|
||||||
|
++cancelledOperations;
|
||||||
|
[operation cancel];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cancelledOperations;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSOperationQueue *)operationQueue {
|
||||||
|
if(nil == _operationQueue) {
|
||||||
|
_operationQueue = [[NSOperationQueue alloc] init];
|
||||||
|
_operationQueue.maxConcurrentOperationCount = 1;
|
||||||
|
}
|
||||||
|
return _operationQueue;
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
@ -291,24 +291,6 @@
|
|||||||
- (void)startManager {
|
- (void)startManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - Networking
|
|
||||||
|
|
||||||
- (NSData *)appendPostValue:(NSString *)value forKey:(NSString *)key {
|
|
||||||
NSString *boundary = @"----FOO";
|
|
||||||
|
|
||||||
NSMutableData *postBody = [NSMutableData data];
|
|
||||||
|
|
||||||
[postBody appendData:[[NSString stringWithFormat:@"--%@\r\n", boundary] dataUsingEncoding:NSUTF8StringEncoding]];
|
|
||||||
[postBody appendData:[[NSString stringWithFormat:@"Content-Disposition: form-data; name=\"%@\";\r\n", key] dataUsingEncoding:NSUTF8StringEncoding]];
|
|
||||||
[postBody appendData:[[NSString stringWithFormat:@"Content-Type: text\r\n\r\n"] dataUsingEncoding:NSUTF8StringEncoding]];
|
|
||||||
[postBody appendData:[value dataUsingEncoding:NSUTF8StringEncoding]];
|
|
||||||
[postBody appendData:[@"\r\n" dataUsingEncoding:NSUTF8StringEncoding]];
|
|
||||||
|
|
||||||
return postBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark - Helpers
|
#pragma mark - Helpers
|
||||||
|
|
||||||
- (NSDate *)parseRFC3339Date:(NSString *)dateString {
|
- (NSDate *)parseRFC3339Date:(NSString *)dateString {
|
||||||
|
@ -49,9 +49,6 @@
|
|||||||
- (UIWindow *)findVisibleWindow;
|
- (UIWindow *)findVisibleWindow;
|
||||||
- (void)showView:(UIViewController *)viewController;
|
- (void)showView:(UIViewController *)viewController;
|
||||||
|
|
||||||
/** Network helpers */
|
|
||||||
- (NSData *)appendPostValue:(NSString *)value forKey:(NSString *)key;
|
|
||||||
|
|
||||||
/** Date helpers */
|
/** Date helpers */
|
||||||
- (NSDate *)parseRFC3339Date:(NSString *)dateString;
|
- (NSDate *)parseRFC3339Date:(NSString *)dateString;
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@
|
|||||||
#import "BITStoreUpdateManagerPrivate.h"
|
#import "BITStoreUpdateManagerPrivate.h"
|
||||||
#import "BITFeedbackManagerPrivate.h"
|
#import "BITFeedbackManagerPrivate.h"
|
||||||
#import "BITAuthenticator_Private.h"
|
#import "BITAuthenticator_Private.h"
|
||||||
|
#import "BITHockeyAppClient.h"
|
||||||
|
|
||||||
@interface BITHockeyManager ()
|
@interface BITHockeyManager ()
|
||||||
|
|
||||||
@ -247,6 +248,7 @@
|
|||||||
|
|
||||||
if (_serverURL != aServerURL) {
|
if (_serverURL != aServerURL) {
|
||||||
_serverURL = [aServerURL copy];
|
_serverURL = [aServerURL copy];
|
||||||
|
_authenticator.hockeyAppClient.baseURL = [NSURL URLWithString:_serverURL ? _serverURL : BITHOCKEYSDK_URL];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,7 +304,9 @@
|
|||||||
_feedbackManager.delegate = _delegate;
|
_feedbackManager.delegate = _delegate;
|
||||||
|
|
||||||
BITHockeyLog(@"INFO: Setup Authenticator");
|
BITHockeyLog(@"INFO: Setup Authenticator");
|
||||||
|
BITHockeyAppClient *client = [[BITHockeyAppClient alloc] initWithBaseURL:[NSURL URLWithString:_serverURL ? _serverURL : BITHOCKEYSDK_URL]];
|
||||||
_authenticator = [[BITAuthenticator alloc] initWithAppIdentifier:_appIdentifier isAppStoreEnvironemt:_appStoreEnvironment];
|
_authenticator = [[BITAuthenticator alloc] initWithAppIdentifier:_appIdentifier isAppStoreEnvironemt:_appStoreEnvironment];
|
||||||
|
_authenticator.hockeyAppClient = client;
|
||||||
_authenticator.delegate = _delegate;
|
_authenticator.delegate = _delegate;
|
||||||
|
|
||||||
#if JIRA_MOBILE_CONNECT_SUPPORT_ENABLED
|
#if JIRA_MOBILE_CONNECT_SUPPORT_ENABLED
|
||||||
|
@ -127,6 +127,9 @@
|
|||||||
1EF95CA7162CB037000AE3AD /* BITFeedbackActivity.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EF95CA5162CB036000AE3AD /* BITFeedbackActivity.m */; };
|
1EF95CA7162CB037000AE3AD /* BITFeedbackActivity.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EF95CA5162CB036000AE3AD /* BITFeedbackActivity.m */; };
|
||||||
1EF95CAA162CB314000AE3AD /* BITFeedbackComposeViewControllerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1EF95CA9162CB313000AE3AD /* BITFeedbackComposeViewControllerDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
1EF95CAA162CB314000AE3AD /* BITFeedbackComposeViewControllerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1EF95CA9162CB313000AE3AD /* BITFeedbackComposeViewControllerDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
E405266217A2AD300096359C /* BITFeedbackManagerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = E405266117A2AD300096359C /* BITFeedbackManagerDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
E405266217A2AD300096359C /* BITFeedbackManagerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = E405266117A2AD300096359C /* BITFeedbackManagerDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
|
E40E0B0917DA19DC005E38C1 /* BITHockeyAppClientTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E40E0B0817DA19DC005E38C1 /* BITHockeyAppClientTests.m */; };
|
||||||
|
E40E0B0C17DA1AFF005E38C1 /* BITHockeyAppClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E40E0B0A17DA1AFF005E38C1 /* BITHockeyAppClient.h */; };
|
||||||
|
E40E0B0D17DA1AFF005E38C1 /* BITHockeyAppClient.m in Sources */ = {isa = PBXBuildFile; fileRef = E40E0B0B17DA1AFF005E38C1 /* BITHockeyAppClient.m */; };
|
||||||
E48A3DEC17B3ED1C00924C3D /* BITAuthenticator.h in Headers */ = {isa = PBXBuildFile; fileRef = E48A3DEA17B3ED1C00924C3D /* BITAuthenticator.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
E48A3DEC17B3ED1C00924C3D /* BITAuthenticator.h in Headers */ = {isa = PBXBuildFile; fileRef = E48A3DEA17B3ED1C00924C3D /* BITAuthenticator.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||||
E48A3DED17B3ED1C00924C3D /* BITAuthenticator.m in Sources */ = {isa = PBXBuildFile; fileRef = E48A3DEB17B3ED1C00924C3D /* BITAuthenticator.m */; };
|
E48A3DED17B3ED1C00924C3D /* BITAuthenticator.m in Sources */ = {isa = PBXBuildFile; fileRef = E48A3DEB17B3ED1C00924C3D /* BITAuthenticator.m */; };
|
||||||
E48A3DEF17B3EFF100924C3D /* BITAuthenticatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E48A3DEE17B3EFF100924C3D /* BITAuthenticatorTests.m */; };
|
E48A3DEF17B3EFF100924C3D /* BITAuthenticatorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E48A3DEE17B3EFF100924C3D /* BITAuthenticatorTests.m */; };
|
||||||
@ -276,6 +279,9 @@
|
|||||||
BEE0207C16C5107E004426EA /* hu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/HockeySDK.strings; sourceTree = "<group>"; };
|
BEE0207C16C5107E004426EA /* hu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/HockeySDK.strings; sourceTree = "<group>"; };
|
||||||
E400561D148D79B500EB22B9 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
E400561D148D79B500EB22B9 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
|
||||||
E405266117A2AD300096359C /* BITFeedbackManagerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BITFeedbackManagerDelegate.h; sourceTree = "<group>"; };
|
E405266117A2AD300096359C /* BITFeedbackManagerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BITFeedbackManagerDelegate.h; sourceTree = "<group>"; };
|
||||||
|
E40E0B0817DA19DC005E38C1 /* BITHockeyAppClientTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BITHockeyAppClientTests.m; sourceTree = "<group>"; };
|
||||||
|
E40E0B0A17DA1AFF005E38C1 /* BITHockeyAppClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BITHockeyAppClient.h; sourceTree = "<group>"; };
|
||||||
|
E40E0B0B17DA1AFF005E38C1 /* BITHockeyAppClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BITHockeyAppClient.m; sourceTree = "<group>"; };
|
||||||
E41EB465148D7BF50015DEDC /* BITHockeyManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BITHockeyManager.h; sourceTree = "<group>"; };
|
E41EB465148D7BF50015DEDC /* BITHockeyManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BITHockeyManager.h; sourceTree = "<group>"; };
|
||||||
E41EB466148D7BF50015DEDC /* BITHockeyManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BITHockeyManager.m; sourceTree = "<group>"; };
|
E41EB466148D7BF50015DEDC /* BITHockeyManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BITHockeyManager.m; sourceTree = "<group>"; };
|
||||||
E41EB48B148D7C4E0015DEDC /* CrashReporter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CrashReporter.framework; path = ../Vendor/CrashReporter.framework; sourceTree = "<group>"; };
|
E41EB48B148D7C4E0015DEDC /* CrashReporter.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CrashReporter.framework; path = ../Vendor/CrashReporter.framework; sourceTree = "<group>"; };
|
||||||
@ -356,6 +362,7 @@
|
|||||||
1E5A459716F0DFC200B55C04 /* Supporting Files */,
|
1E5A459716F0DFC200B55C04 /* Supporting Files */,
|
||||||
1E5A459D16F0DFC200B55C04 /* BITStoreUpdateManagerTests.m */,
|
1E5A459D16F0DFC200B55C04 /* BITStoreUpdateManagerTests.m */,
|
||||||
E48A3DEE17B3EFF100924C3D /* BITAuthenticatorTests.m */,
|
E48A3DEE17B3EFF100924C3D /* BITAuthenticatorTests.m */,
|
||||||
|
E40E0B0817DA19DC005E38C1 /* BITHockeyAppClientTests.m */,
|
||||||
);
|
);
|
||||||
path = HockeySDKTests;
|
path = HockeySDKTests;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -558,6 +565,8 @@
|
|||||||
E48A3DF017B408D800924C3D /* private */,
|
E48A3DF017B408D800924C3D /* private */,
|
||||||
E48A3DEA17B3ED1C00924C3D /* BITAuthenticator.h */,
|
E48A3DEA17B3ED1C00924C3D /* BITAuthenticator.h */,
|
||||||
E48A3DEB17B3ED1C00924C3D /* BITAuthenticator.m */,
|
E48A3DEB17B3ED1C00924C3D /* BITAuthenticator.m */,
|
||||||
|
E40E0B0A17DA1AFF005E38C1 /* BITHockeyAppClient.h */,
|
||||||
|
E40E0B0B17DA1AFF005E38C1 /* BITHockeyAppClient.m */,
|
||||||
);
|
);
|
||||||
name = Network;
|
name = Network;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
@ -593,6 +602,7 @@
|
|||||||
1E49A4481612223B00463151 /* BITFeedbackListViewController.h in Headers */,
|
1E49A4481612223B00463151 /* BITFeedbackListViewController.h in Headers */,
|
||||||
1E49A47F1612226D00463151 /* BITUpdateViewController.h in Headers */,
|
1E49A47F1612226D00463151 /* BITUpdateViewController.h in Headers */,
|
||||||
1E49A43C1612223B00463151 /* BITFeedbackComposeViewController.h in Headers */,
|
1E49A43C1612223B00463151 /* BITFeedbackComposeViewController.h in Headers */,
|
||||||
|
E40E0B0C17DA1AFF005E38C1 /* BITHockeyAppClient.h in Headers */,
|
||||||
1EF95CAA162CB314000AE3AD /* BITFeedbackComposeViewControllerDelegate.h in Headers */,
|
1EF95CAA162CB314000AE3AD /* BITFeedbackComposeViewControllerDelegate.h in Headers */,
|
||||||
1EF95CA6162CB037000AE3AD /* BITFeedbackActivity.h in Headers */,
|
1EF95CA6162CB037000AE3AD /* BITFeedbackActivity.h in Headers */,
|
||||||
1E49A4AF161222B900463151 /* BITHockeyBaseManager.h in Headers */,
|
1E49A4AF161222B900463151 /* BITHockeyBaseManager.h in Headers */,
|
||||||
@ -817,6 +827,7 @@
|
|||||||
files = (
|
files = (
|
||||||
1E5954D315B6F24A00A03429 /* BITHockeyManager.m in Sources */,
|
1E5954D315B6F24A00A03429 /* BITHockeyManager.m in Sources */,
|
||||||
1E49A43F1612223B00463151 /* BITFeedbackComposeViewController.m in Sources */,
|
1E49A43F1612223B00463151 /* BITFeedbackComposeViewController.m in Sources */,
|
||||||
|
E40E0B0D17DA1AFF005E38C1 /* BITHockeyAppClient.m in Sources */,
|
||||||
1E49A4451612223B00463151 /* BITFeedbackListViewCell.m in Sources */,
|
1E49A4451612223B00463151 /* BITFeedbackListViewCell.m in Sources */,
|
||||||
1E49A44B1612223B00463151 /* BITFeedbackListViewController.m in Sources */,
|
1E49A44B1612223B00463151 /* BITFeedbackListViewController.m in Sources */,
|
||||||
1E49A4511612223B00463151 /* BITFeedbackManager.m in Sources */,
|
1E49A4511612223B00463151 /* BITFeedbackManager.m in Sources */,
|
||||||
@ -856,6 +867,7 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
1E5A459E16F0DFC200B55C04 /* BITStoreUpdateManagerTests.m in Sources */,
|
1E5A459E16F0DFC200B55C04 /* BITStoreUpdateManagerTests.m in Sources */,
|
||||||
|
E40E0B0917DA19DC005E38C1 /* BITHockeyAppClientTests.m in Sources */,
|
||||||
E48A3DEF17B3EFF100924C3D /* BITAuthenticatorTests.m in Sources */,
|
E48A3DEF17B3EFF100924C3D /* BITAuthenticatorTests.m in Sources */,
|
||||||
1EA1170716F53B91001C015C /* BITTestHelper.m in Sources */,
|
1EA1170716F53B91001C015C /* BITTestHelper.m in Sources */,
|
||||||
);
|
);
|
||||||
|
1319
Support/HockeySDK.xcodeproj/project.pbxproj.orig
Normal file
1319
Support/HockeySDK.xcodeproj/project.pbxproj.orig
Normal file
File diff suppressed because it is too large
Load Diff
@ -41,7 +41,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)tearDown {
|
- (void)tearDown {
|
||||||
[_sut cancelOperationsWithPath:nil method:nil];
|
|
||||||
[_sut cleanupInternalStorage];
|
[_sut cleanupInternalStorage];
|
||||||
_sut = nil;
|
_sut = nil;
|
||||||
|
|
||||||
@ -279,177 +278,4 @@
|
|||||||
[verifyCount(delegateMock, times(1)) authenticatorDidValidateInstallation:_sut];
|
[verifyCount(delegateMock, times(1)) authenticatorDidValidateInstallation:_sut];
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma mark - Networking base tests
|
|
||||||
- (void) testThatURLRequestHasBaseURLSet {
|
|
||||||
_sut.serverURL = @"http://myserver.com";
|
|
||||||
NSMutableURLRequest *request = [_sut requestWithMethod:@"GET" path:nil parameters:nil];
|
|
||||||
assertThat(request.URL, equalTo([NSURL URLWithString:@"http://myserver.com/"]));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) testThatURLRequestHasPathAppended {
|
|
||||||
_sut.serverURL = @"http://myserver.com";
|
|
||||||
NSMutableURLRequest *request = [_sut requestWithMethod:@"GET" path:@"projects" parameters:nil];
|
|
||||||
assertThat(request.URL, equalTo([NSURL URLWithString:@"http://myserver.com/projects"]));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) testThatURLRequestHasMethodSet {
|
|
||||||
NSMutableURLRequest *request = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
|
||||||
|
|
||||||
assertThat(request.HTTPMethod, equalTo(@"POST"));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) testThatOperationHasURLRequestSet {
|
|
||||||
_sut.serverURL = @"http://myserver.com";
|
|
||||||
NSURLRequest *r = [_sut requestWithMethod:@"PUT" path:@"x" parameters:nil];
|
|
||||||
BITHTTPOperation *op = [_sut operationWithURLRequest:r
|
|
||||||
completion:nil];
|
|
||||||
assertThat(op.URLRequest, equalTo(r));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) testThatURLRequestHasParametersInGetAppended {
|
|
||||||
NSDictionary *parameters = @{
|
|
||||||
@"email" : @"peter@pan.de",
|
|
||||||
@"push" : @"pop",
|
|
||||||
};
|
|
||||||
NSMutableURLRequest *request = [_sut requestWithMethod:@"GET"
|
|
||||||
path:@"something"
|
|
||||||
parameters:parameters];
|
|
||||||
NSURL *url = request.URL;
|
|
||||||
NSString *params = [url query];
|
|
||||||
NSArray *paramPairs = [params componentsSeparatedByString:@"&"];
|
|
||||||
assertThat(paramPairs, hasCountOf(2));
|
|
||||||
|
|
||||||
NSMutableDictionary *dict = [NSMutableDictionary new];
|
|
||||||
for(NSString *paramPair in paramPairs) {
|
|
||||||
NSArray *a = [paramPair componentsSeparatedByString:@"="];
|
|
||||||
assertThat(a, hasCountOf(2));
|
|
||||||
dict[a[0]] = a[1];
|
|
||||||
}
|
|
||||||
assertThat(dict, equalTo(parameters));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) testThatURLRequestHasParametersInPostInTheBody {
|
|
||||||
//pending
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Convenience methods
|
|
||||||
- (void) testThatGetPathCreatesAndEnquesAnOperation {
|
|
||||||
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(0));
|
|
||||||
[given([_sut operationWithURLRequest:(id)anything()
|
|
||||||
completion:nil]) willReturn:[NSOperation new]];
|
|
||||||
|
|
||||||
[_sut getPath:@"endpoint"
|
|
||||||
parameters:nil
|
|
||||||
completion:nil];
|
|
||||||
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) testThatPostPathCreatesAndEnquesAnOperation {
|
|
||||||
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(0));
|
|
||||||
[given([_sut operationWithURLRequest:nil
|
|
||||||
completion:nil]) willReturn:[NSOperation new]];
|
|
||||||
|
|
||||||
[_sut postPath:@"endpoint"
|
|
||||||
parameters:nil
|
|
||||||
completion:nil];
|
|
||||||
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Completion Tests
|
|
||||||
- (void) testThatCompletionIsCalled {
|
|
||||||
//TODO
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - HTTPOperation enqueuing / cancellation
|
|
||||||
- (void) testThatOperationIsQueued {
|
|
||||||
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(0));
|
|
||||||
[_sut.operationQueue setSuspended:YES];
|
|
||||||
BITHTTPOperation *op = [BITHTTPOperation new];
|
|
||||||
[_sut enqeueHTTPOperation:op];
|
|
||||||
|
|
||||||
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) testThatOperationCancellingMatchesAllOperationsWithNilMethod {
|
|
||||||
[_sut.operationQueue setSuspended:YES];
|
|
||||||
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:nil parameters:nil];
|
|
||||||
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:nil parameters:nil];
|
|
||||||
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
|
||||||
completion:nil]];
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
|
||||||
completion:nil]];
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
|
||||||
completion:nil]];
|
|
||||||
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(3));
|
|
||||||
NSUInteger numCancelled = [_sut cancelOperationsWithPath:nil method:nil];
|
|
||||||
assertThatUnsignedInt(numCancelled, equalToUnsignedInt(3));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) testThatOperationCancellingMatchesAllOperationsWithNilPath {
|
|
||||||
[_sut.operationQueue setSuspended:YES];
|
|
||||||
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
|
||||||
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
|
||||||
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
|
||||||
completion:nil]];
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
|
||||||
completion:nil]];
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
|
||||||
completion:nil]];
|
|
||||||
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(3));
|
|
||||||
NSUInteger numCancelled = [_sut cancelOperationsWithPath:nil method:nil];
|
|
||||||
assertThatUnsignedInt(numCancelled, equalToUnsignedInt(3));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void) testThatOperationCancellingMatchesAllOperationsWithSetPath {
|
|
||||||
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
|
||||||
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
|
||||||
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
|
||||||
[_sut.operationQueue setSuspended:YES];
|
|
||||||
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
|
||||||
completion:nil]];
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
|
||||||
completion:nil]];
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
|
||||||
completion:nil]];
|
|
||||||
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(3));
|
|
||||||
NSUInteger numCancelled = [_sut cancelOperationsWithPath:@"Another/acas" method:nil];
|
|
||||||
assertThatUnsignedInt(numCancelled, equalToUnsignedInt(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) testThatOperationCancellingMatchesAllOperationsWithSetMethod {
|
|
||||||
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
|
||||||
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
|
||||||
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
|
||||||
completion:nil]];
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
|
||||||
completion:nil]];
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
|
||||||
completion:nil]];
|
|
||||||
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(3));
|
|
||||||
NSUInteger numCancelled = [_sut cancelOperationsWithPath:nil method:@"POST"];
|
|
||||||
assertThatUnsignedInt(numCancelled, equalToUnsignedInt(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) testThatOperationCancellingMatchesAllOperationsWithSetMethodAndPath {
|
|
||||||
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
|
||||||
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
|
||||||
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
|
||||||
completion:nil]];
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
|
||||||
completion:nil]];
|
|
||||||
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
|
||||||
completion:nil]];
|
|
||||||
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(3));
|
|
||||||
NSUInteger numCancelled = [_sut cancelOperationsWithPath:@"Another/acas" method:@"PUT"];
|
|
||||||
assertThatUnsignedInt(numCancelled, equalToUnsignedInt(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark - Operation Testing
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
231
Support/HockeySDKTests/BITHockeyAppClientTests.m
Normal file
231
Support/HockeySDKTests/BITHockeyAppClientTests.m
Normal file
@ -0,0 +1,231 @@
|
|||||||
|
//
|
||||||
|
// BITHockeyAppClientTests
|
||||||
|
// HockeySDKTests
|
||||||
|
//
|
||||||
|
// Created by Stephan Diederich on 06.09.13.
|
||||||
|
//
|
||||||
|
//
|
||||||
|
|
||||||
|
#import <SenTestingKit/SenTestingKit.h>
|
||||||
|
|
||||||
|
#define HC_SHORTHAND
|
||||||
|
#import <OCHamcrestIOS/OCHamcrestIOS.h>
|
||||||
|
|
||||||
|
#define MOCKITO_SHORTHAND
|
||||||
|
#import <OCMockitoIOS/OCMockitoIOS.h>
|
||||||
|
|
||||||
|
#import "HockeySDK.h"
|
||||||
|
#import "BITHockeyAppClient.h"
|
||||||
|
#import "BITHTTPOperation.h"
|
||||||
|
#import "BITTestHelper.h"
|
||||||
|
|
||||||
|
@interface BITHockeyAppClientTests : SenTestCase
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation BITHockeyAppClientTests {
|
||||||
|
BITHockeyAppClient *_sut;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)setUp {
|
||||||
|
[super setUp];
|
||||||
|
|
||||||
|
_sut = [[BITHockeyAppClient alloc] initWithBaseURL:[NSURL URLWithString:@"http://bitbaseurl.com"]];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)tearDown {
|
||||||
|
[_sut cancelOperationsWithPath:nil method:nil];
|
||||||
|
_sut = nil;
|
||||||
|
|
||||||
|
[super tearDown];
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Setup helpers
|
||||||
|
- (NSDictionary *)jsonFromFixture:(NSString *)fixture {
|
||||||
|
NSString *dataString = [BITTestHelper jsonFixture:fixture];
|
||||||
|
|
||||||
|
NSData *data = [dataString dataUsingEncoding:NSUTF8StringEncoding];
|
||||||
|
NSError *error = nil;
|
||||||
|
NSDictionary *json = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
|
||||||
|
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Setup Tests
|
||||||
|
- (void) testThatItInstantiates {
|
||||||
|
STAssertNotNil(_sut, @"Should be there");
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Networking base tests
|
||||||
|
- (void) testThatURLRequestHasBaseURLSet {
|
||||||
|
_sut.baseURL = [NSURL URLWithString:@"http://myserver.com"];
|
||||||
|
NSMutableURLRequest *request = [_sut requestWithMethod:@"GET" path:nil parameters:nil];
|
||||||
|
assertThat(request.URL, equalTo([NSURL URLWithString:@"http://myserver.com/"]));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) testThatURLRequestHasPathAppended {
|
||||||
|
_sut.baseURL = [NSURL URLWithString:@"http://myserver.com"];
|
||||||
|
NSMutableURLRequest *request = [_sut requestWithMethod:@"GET" path:@"projects" parameters:nil];
|
||||||
|
assertThat(request.URL, equalTo([NSURL URLWithString:@"http://myserver.com/projects"]));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) testThatURLRequestHasMethodSet {
|
||||||
|
NSMutableURLRequest *request = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||||
|
|
||||||
|
assertThat(request.HTTPMethod, equalTo(@"POST"));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) testThatOperationHasURLRequestSet {
|
||||||
|
_sut.baseURL = [NSURL URLWithString:@"http://myserver.com"];
|
||||||
|
NSURLRequest *r = [_sut requestWithMethod:@"PUT" path:@"x" parameters:nil];
|
||||||
|
BITHTTPOperation *op = [_sut operationWithURLRequest:r
|
||||||
|
completion:nil];
|
||||||
|
assertThat(op.URLRequest, equalTo(r));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) testThatURLRequestHasParametersInGetAppended {
|
||||||
|
NSDictionary *parameters = @{
|
||||||
|
@"email" : @"peter@pan.de",
|
||||||
|
@"push" : @"pop",
|
||||||
|
};
|
||||||
|
NSMutableURLRequest *request = [_sut requestWithMethod:@"GET"
|
||||||
|
path:@"something"
|
||||||
|
parameters:parameters];
|
||||||
|
NSURL *url = request.URL;
|
||||||
|
NSString *params = [url query];
|
||||||
|
NSArray *paramPairs = [params componentsSeparatedByString:@"&"];
|
||||||
|
assertThat(paramPairs, hasCountOf(2));
|
||||||
|
|
||||||
|
NSMutableDictionary *dict = [NSMutableDictionary new];
|
||||||
|
for(NSString *paramPair in paramPairs) {
|
||||||
|
NSArray *a = [paramPair componentsSeparatedByString:@"="];
|
||||||
|
assertThat(a, hasCountOf(2));
|
||||||
|
dict[a[0]] = a[1];
|
||||||
|
}
|
||||||
|
assertThat(dict, equalTo(parameters));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) testThatURLRequestHasParametersInPostInTheBody {
|
||||||
|
//pending
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Convenience methods
|
||||||
|
- (void) testThatGetPathCreatesAndEnquesAnOperation {
|
||||||
|
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(0));
|
||||||
|
[given([_sut operationWithURLRequest:(id)anything()
|
||||||
|
completion:nil]) willReturn:[NSOperation new]];
|
||||||
|
|
||||||
|
[_sut getPath:@"endpoint"
|
||||||
|
parameters:nil
|
||||||
|
completion:nil];
|
||||||
|
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) testThatPostPathCreatesAndEnquesAnOperation {
|
||||||
|
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(0));
|
||||||
|
[given([_sut operationWithURLRequest:nil
|
||||||
|
completion:nil]) willReturn:[NSOperation new]];
|
||||||
|
|
||||||
|
[_sut postPath:@"endpoint"
|
||||||
|
parameters:nil
|
||||||
|
completion:nil];
|
||||||
|
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Completion Tests
|
||||||
|
- (void) testThatCompletionIsCalled {
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - HTTPOperation enqueuing / cancellation
|
||||||
|
- (void) testThatOperationIsQueued {
|
||||||
|
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(0));
|
||||||
|
[_sut.operationQueue setSuspended:YES];
|
||||||
|
BITHTTPOperation *op = [BITHTTPOperation new];
|
||||||
|
[_sut enqeueHTTPOperation:op];
|
||||||
|
|
||||||
|
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) testThatOperationCancellingMatchesAllOperationsWithNilMethod {
|
||||||
|
[_sut.operationQueue setSuspended:YES];
|
||||||
|
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:nil parameters:nil];
|
||||||
|
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:nil parameters:nil];
|
||||||
|
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
||||||
|
completion:nil]];
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
||||||
|
completion:nil]];
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
||||||
|
completion:nil]];
|
||||||
|
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(3));
|
||||||
|
NSUInteger numCancelled = [_sut cancelOperationsWithPath:nil method:nil];
|
||||||
|
assertThatUnsignedInt(numCancelled, equalToUnsignedInt(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) testThatOperationCancellingMatchesAllOperationsWithNilPath {
|
||||||
|
[_sut.operationQueue setSuspended:YES];
|
||||||
|
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
||||||
|
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
||||||
|
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
||||||
|
completion:nil]];
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
||||||
|
completion:nil]];
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
||||||
|
completion:nil]];
|
||||||
|
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(3));
|
||||||
|
NSUInteger numCancelled = [_sut cancelOperationsWithPath:nil method:nil];
|
||||||
|
assertThatUnsignedInt(numCancelled, equalToUnsignedInt(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
- (void) testThatOperationCancellingMatchesAllOperationsWithSetPath {
|
||||||
|
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
||||||
|
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
||||||
|
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||||
|
[_sut.operationQueue setSuspended:YES];
|
||||||
|
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
||||||
|
completion:nil]];
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
||||||
|
completion:nil]];
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
||||||
|
completion:nil]];
|
||||||
|
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(3));
|
||||||
|
NSUInteger numCancelled = [_sut cancelOperationsWithPath:@"Another/acas" method:nil];
|
||||||
|
assertThatUnsignedInt(numCancelled, equalToUnsignedInt(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) testThatOperationCancellingMatchesAllOperationsWithSetMethod {
|
||||||
|
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
||||||
|
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
||||||
|
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
||||||
|
completion:nil]];
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
||||||
|
completion:nil]];
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
||||||
|
completion:nil]];
|
||||||
|
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(3));
|
||||||
|
NSUInteger numCancelled = [_sut cancelOperationsWithPath:nil method:@"POST"];
|
||||||
|
assertThatUnsignedInt(numCancelled, equalToUnsignedInt(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) testThatOperationCancellingMatchesAllOperationsWithSetMethodAndPath {
|
||||||
|
NSURLRequest *requestGet = [_sut requestWithMethod:@"GET" path:@"test" parameters:nil];
|
||||||
|
NSURLRequest *requestPut = [_sut requestWithMethod:@"PUT" path:@"Another/acas" parameters:nil];
|
||||||
|
NSURLRequest *requestPost = [_sut requestWithMethod:@"POST" path:nil parameters:nil];
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestGet
|
||||||
|
completion:nil]];
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPut
|
||||||
|
completion:nil]];
|
||||||
|
[_sut enqeueHTTPOperation:[_sut operationWithURLRequest:requestPost
|
||||||
|
completion:nil]];
|
||||||
|
assertThatUnsignedInt(_sut.operationQueue.operationCount, equalToUnsignedInt(3));
|
||||||
|
NSUInteger numCancelled = [_sut cancelOperationsWithPath:@"Another/acas" method:@"PUT"];
|
||||||
|
assertThatUnsignedInt(numCancelled, equalToUnsignedInt(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark - Operation Testing
|
||||||
|
|
||||||
|
@end
|
Loading…
x
Reference in New Issue
Block a user