-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from TheSooth/master
Removing unused code, and refactoring
- Loading branch information
Showing
19 changed files
with
316 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
DXHTTPKit/Code/Base/DXHTTPConnection/DXHTTPConnectionOperation/DXHTTPConnectionOperation.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// DXHTTPConnectionOperation.h | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "DXHTTPConnectionThread.h" | ||
|
||
@interface DXHTTPConnectionOperation : NSOperation <NSURLConnectionDelegate, NSURLConnectionDataDelegate> | ||
|
||
- (id)initWithURLRequest:(NSURLRequest *)aURLRequest; | ||
|
||
@property (nonatomic, readonly) NSData *connectionData; | ||
@property (nonatomic, strong, readonly) NSURLConnection *urlConnection; | ||
|
||
@end |
79 changes: 79 additions & 0 deletions
79
DXHTTPKit/Code/Base/DXHTTPConnection/DXHTTPConnectionOperation/DXHTTPConnectionOperation.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// | ||
// DXHTTPConnectionOperation.m | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import "DXHTTPConnectionOperation.h" | ||
|
||
@interface DXHTTPConnectionOperation() { | ||
NSURLRequest *_urlRequest; | ||
NSURLConnection *_urlConnection; | ||
NSMutableData *_connectionData; | ||
NSMutableDictionary *_connectionResponseHeaders; | ||
BOOL _executing; | ||
BOOL _finished; | ||
} | ||
|
||
@end | ||
|
||
@implementation DXHTTPConnectionOperation | ||
|
||
- (id)initWithURLRequest:(NSURLRequest *)aURLRequest { | ||
self = [super init]; | ||
if (self) { | ||
_urlRequest = aURLRequest; | ||
_connectionData = [NSMutableData new]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)start { | ||
_executing = YES; | ||
[self performSelector:@selector(connectionOpeartionDidStart) onThread:[DXHTTPConnectionThread requestConnectionThread] withObject:nil waitUntilDone:NO]; | ||
|
||
} | ||
|
||
- (void)connectionOpeartionDidStart { | ||
_urlConnection = [[NSURLConnection alloc] initWithRequest:_urlRequest delegate:self]; | ||
NSRunLoop *connectionRunLoop = [NSRunLoop currentRunLoop]; | ||
[_urlConnection scheduleInRunLoop:connectionRunLoop forMode:NSRunLoopCommonModes]; | ||
[_urlConnection start]; | ||
} | ||
|
||
|
||
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { | ||
[_connectionData setLength:0]; | ||
} | ||
|
||
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { | ||
[_connectionData appendData:data]; | ||
} | ||
|
||
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { | ||
|
||
} | ||
|
||
- (NSData *)connectionData { | ||
return _connectionData; | ||
} | ||
|
||
- (NSURLConnection *)urlConnection { | ||
return _urlConnection; | ||
} | ||
|
||
- (BOOL)isExecuting { | ||
return _executing; | ||
} | ||
|
||
- (BOOL)isFinished { | ||
return _finished; | ||
} | ||
|
||
- (BOOL)isConcurrent { | ||
return YES; | ||
} | ||
|
||
@end |
15 changes: 15 additions & 0 deletions
15
DXHTTPKit/Code/Base/DXHTTPConnection/DXHTTPConnectionThread/DXHTTPConnectionThread.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// DXHTTPConnectionThread.h | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface DXHTTPConnectionThread : NSObject | ||
|
||
+ (NSThread *)requestConnectionThread; | ||
|
||
@end |
37 changes: 37 additions & 0 deletions
37
DXHTTPKit/Code/Base/DXHTTPConnection/DXHTTPConnectionThread/DXHTTPConnectionThread.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// | ||
// DXHTTPConnectionThread.m | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import "DXHTTPConnectionThread.h" | ||
|
||
@interface DXHTTPConnectionThread() | ||
|
||
@end | ||
|
||
@implementation DXHTTPConnectionThread | ||
|
||
static NSThread *_connectionThread; | ||
|
||
+ (void)connectionThreadEntry:(id)object { | ||
do { | ||
@autoreleasepool { | ||
[[NSRunLoop currentRunLoop] run]; | ||
} | ||
} while (YES); | ||
} | ||
|
||
+ (NSThread *)requestConnectionThread { | ||
static dispatch_once_t allocThreadOnce; | ||
|
||
dispatch_once(&allocThreadOnce, ^{ | ||
_connectionThread = [[NSThread alloc] initWithTarget:self selector:@selector(connectionThreadEntry:) object:nil]; | ||
[_connectionThread start]; | ||
}); | ||
return _connectionThread; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// DXHTTPConnectionOperation.h | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface DXHTTPConnectionOperation : NSOperation | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// DXHTTPConnectionOperation.m | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import "DXHTTPConnectionOperation.h" | ||
|
||
@implementation DXHTTPConnectionOperation | ||
|
||
@end |
13 changes: 13 additions & 0 deletions
13
DXHTTPKit/Code/Base/DXHTTPConnectionThread/DXHTTPConnectionThread.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// DXHTTPConnectionThread.h | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface DXHTTPConnectionThread : NSObject | ||
|
||
@end |
13 changes: 13 additions & 0 deletions
13
DXHTTPKit/Code/Base/DXHTTPConnectionThread/DXHTTPConnectionThread.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// DXHTTPConnectionThread.m | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import "DXHTTPConnectionThread.h" | ||
|
||
@implementation DXHTTPConnectionThread | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// DXHTTPConnection.h | ||
// DXHTTPKit | ||
// | ||
// Created by dev2 on 10/22/12. | ||
// Copyright (c) 2012 111Minutes. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@interface DXHTTPConnection : NSObject | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#import "Kiwi.h" | ||
#import "DXHTTPConnectionOperation.h" | ||
|
||
SPEC_BEGIN(DXHTTPConnectionSpec) | ||
|
||
describe(@"DXHTTPConnection", ^{ | ||
|
||
__block DXHTTPConnectionOperation *connectionOperation; | ||
__block NSURLRequest *urlRequest; | ||
|
||
beforeEach(^{ | ||
urlRequest = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://localhost"]]; | ||
connectionOperation = [[DXHTTPConnectionOperation alloc] initWithURLRequest:urlRequest]; | ||
[connectionOperation start]; | ||
}); | ||
|
||
context(@"Right values", ^{ | ||
|
||
it(@"DXHTTPConnection should be executing", ^{ | ||
[[theValue([connectionOperation isExecuting]) should] beTrue]; | ||
}); | ||
|
||
it(@"Should set connectionData in DXHTTPConnectionOperation", ^{ | ||
NSData *dataForTesting = [[NSString stringWithFormat:@"Data for Testing"] dataUsingEncoding:NSUTF8StringEncoding]; | ||
[connectionOperation connection:[connectionOperation urlConnection] didReceiveData:dataForTesting]; | ||
|
||
[[[connectionOperation connectionData] should] equal:dataForTesting]; | ||
}); | ||
|
||
it(@"Data in connectionOperation should be zero in time of resiveResponce", ^{ | ||
[connectionOperation connection:[connectionOperation urlConnection] didReceiveResponse:nil]; | ||
[[theValue([[connectionOperation connectionData] length]) should] equal:theValue(0)]; | ||
}); | ||
|
||
it(@"DXConnectionOperation shoul be concurrent", ^{ | ||
[[theValue([connectionOperation isConcurrent]) should] beTrue]; | ||
}); | ||
}); | ||
}); | ||
|
||
SPEC_END |
Empty file.
Oops, something went wrong.