Permalink
Browse files

Use spaces instead of tabs.

  • Loading branch information...
1 parent 0d322f9 commit 5b702b1049920a73a21aac45331be8d7e15126ed @adamjernst committed Oct 13, 2011
@@ -13,24 +13,24 @@ @implementation AEJSONProcessingBlock
static AEURLConnectionResponseProcessingBlock JSONProcessingBlock = nil;
+ (AEURLConnectionResponseProcessingBlock)JSONResponseProcessingBlock {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- JSONProcessingBlock = [[self JSONResponseProcessingBlockWithOptions:JKParseOptionNone] retain];
- });
- return JSONProcessingBlock;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ JSONProcessingBlock = [[self JSONResponseProcessingBlockWithOptions:JKParseOptionNone] retain];
+ });
+ return JSONProcessingBlock;
}
+ (AEURLConnectionResponseProcessingBlock)JSONResponseProcessingBlockWithOptions:(JKParseOptionFlags)options {
- return [[(id)^(NSURLResponse *response, NSData *data, NSError **error){
- return [data objectFromJSONDataWithParseOptions:options error:error];
- } copy] autorelease];
+ return [[(id)^(NSURLResponse *response, NSData *data, NSError **error){
+ return [data objectFromJSONDataWithParseOptions:options error:error];
+ } copy] autorelease];
}
+ (AEURLConnectionParameterProcessingBlock)JSONParameterProcessingBlock {
- return [[^(NSDictionary *parameters, NSMutableURLRequest *targetRequest){
- [targetRequest setHTTPBody:[parameters JSONData]];
- [targetRequest setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
- } copy] autorelease];
+ return [[^(NSDictionary *parameters, NSMutableURLRequest *targetRequest){
+ [targetRequest setHTTPBody:[parameters JSONData]];
+ [targetRequest setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
+ } copy] autorelease];
}
@end
@@ -26,8 +26,8 @@ typedef id (^AEURLConnectionResponseProcessingBlock)(NSURLResponse *, NSData *,
// of an NSData* object.
// Check out AEJSONProcessingBlock for an example usage.
+ (void)sendAsynchronousRequest:(NSURLRequest *)request
- queue:(NSOperationQueue *)queue
- processingBlock:(AEURLConnectionResponseProcessingBlock)processingBlock
- completionHandler:(void (^)(NSURLResponse *, id, NSError *))handler;
+ queue:(NSOperationQueue *)queue
+ processingBlock:(AEURLConnectionResponseProcessingBlock)processingBlock
+ completionHandler:(void (^)(NSURLResponse *, id, NSError *))handler;
@end

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -11,7 +11,7 @@
typedef id (^AEURLConnectionParameterProcessingBlock)(NSDictionary *parameters, NSMutableURLRequest *targetRequest);
@interface AEURLRequestFactory : NSObject {
- NSMutableDictionary *_defaultHeaderValues;
+ NSMutableDictionary *_defaultHeaderValues;
}
// A singleton request factory. If you set any default header values on this
@@ -23,15 +23,15 @@ typedef id (^AEURLConnectionParameterProcessingBlock)(NSDictionary *parameters,
// submitted POST form).
// Need to modify the returned request further? Just use -mutableCopy.
- (NSURLRequest *)requestWithURL:(NSURL *)url
- method:(NSString *)method
- parameters:(NSDictionary *)parameters;
+ method:(NSString *)method
+ parameters:(NSDictionary *)parameters;
// You can pass any block to put the parameters into the generated request: e.g.
// JSON, or you could write your own for XML or other encodings.
- (NSURLRequest *)requestWithURL:(NSURL *)url
- method:(NSString *)method
- parameters:(NSDictionary *)parameters
- parameterProcessingBlock:(AEURLConnectionParameterProcessingBlock)parameterProcessingBlock;
+ method:(NSString *)method
+ parameters:(NSDictionary *)parameters
+ parameterProcessingBlock:(AEURLConnectionParameterProcessingBlock)parameterProcessingBlock;
- (NSString *)defaultValueForHeader:(NSString *)header;
- (void)setDefaultValue:(NSString *)value forHeader:(NSString *)header;
@@ -16,91 +16,91 @@
@implementation AEURLRequestFactory
+ (AEURLRequestFactory *)defaultFactory {
- static AEURLRequestFactory *defaultFactory;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- defaultFactory = [[AEURLRequestFactory alloc] init];
- });
- return defaultFactory;
+ static AEURLRequestFactory *defaultFactory;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ defaultFactory = [[AEURLRequestFactory alloc] init];
+ });
+ return defaultFactory;
}
- (id)init {
- self = [super init];
- if (self) {
- _defaultHeaderValues = [[NSMutableDictionary alloc] init];
- }
- return self;
+ self = [super init];
+ if (self) {
+ _defaultHeaderValues = [[NSMutableDictionary alloc] init];
+ }
+ return self;
}
- (void)dealloc {
- [_defaultHeaderValues release];
- [super dealloc];
+ [_defaultHeaderValues release];
+ [super dealloc];
}
- (NSURLRequest *)requestWithURL:(NSURL *)url
- method:(NSString *)method
- parameters:(NSDictionary *)parameters {
- AEURLConnectionParameterProcessingBlock processingBlock = nil;
- if ([method isEqualToString:@"GET"]) {
- processingBlock = [AEURLRequestFactory queryStringProcessingBlock];
- } else {
- processingBlock = [AEURLRequestFactory formURLEncodedProcessingBlock];
- }
- return [self requestWithURL:url method:method parameters:parameters parameterProcessingBlock:processingBlock];
+ method:(NSString *)method
+ parameters:(NSDictionary *)parameters {
+ AEURLConnectionParameterProcessingBlock processingBlock = nil;
+ if ([method isEqualToString:@"GET"]) {
+ processingBlock = [AEURLRequestFactory queryStringProcessingBlock];
+ } else {
+ processingBlock = [AEURLRequestFactory formURLEncodedProcessingBlock];
+ }
+ return [self requestWithURL:url method:method parameters:parameters parameterProcessingBlock:processingBlock];
}
- (NSURLRequest *)requestWithURL:(NSURL *)url
- method:(NSString *)method
- parameters:(NSDictionary *)parameters
- parameterProcessingBlock:(AEURLConnectionParameterProcessingBlock)parameterProcessingBlock {
- NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
- [request setHTTPMethod:method];
- [request setAllHTTPHeaderFields:_defaultHeaderValues];
- parameterProcessingBlock(parameters, request);
- return request;
+ method:(NSString *)method
+ parameters:(NSDictionary *)parameters
+ parameterProcessingBlock:(AEURLConnectionParameterProcessingBlock)parameterProcessingBlock {
+ NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
+ [request setHTTPMethod:method];
+ [request setAllHTTPHeaderFields:_defaultHeaderValues];
+ parameterProcessingBlock(parameters, request);
+ return request;
}
#pragma mark - Default Header Values
- (NSString *)defaultValueForHeader:(NSString *)header {
- return [_defaultHeaderValues objectForKey:header];
+ return [_defaultHeaderValues objectForKey:header];
}
- (void)setDefaultValue:(NSString *)value forHeader:(NSString *)header {
- [_defaultHeaderValues setObject:value forKey:header];
+ [_defaultHeaderValues setObject:value forKey:header];
}
#pragma mark - Authorization Header Generation
+ (NSString *)authorizationHeaderForUsername:(NSString *)username password:(NSString *)password {
- return [NSString stringWithFormat:@"Basic %@", AEBase64EncodedStringFromString([NSString stringWithFormat:@"%@:%@", username, password])];
+ return [NSString stringWithFormat:@"Basic %@", AEBase64EncodedStringFromString([NSString stringWithFormat:@"%@:%@", username, password])];
}
#pragma mark - Parameter Encoding Blocks
+ (AEURLConnectionParameterProcessingBlock)queryStringProcessingBlock {
- static AEURLConnectionParameterProcessingBlock queryStringProcessingBlock;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- queryStringProcessingBlock = [^(NSDictionary *parameters, NSMutableURLRequest *targetRequest){
- NSString *oldURL = [[targetRequest URL] absoluteString];
- NSURL *newURL = [NSURL URLWithString:[oldURL stringByAppendingFormat:[oldURL rangeOfString:@"?"].location == NSNotFound ? @"?%@" : @"&%@", AEQueryStringFromParameters(parameters)]];
- [targetRequest setURL:newURL];
- } copy];
- });
- return queryStringProcessingBlock;
+ static AEURLConnectionParameterProcessingBlock queryStringProcessingBlock;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ queryStringProcessingBlock = [^(NSDictionary *parameters, NSMutableURLRequest *targetRequest){
+ NSString *oldURL = [[targetRequest URL] absoluteString];
+ NSURL *newURL = [NSURL URLWithString:[oldURL stringByAppendingFormat:[oldURL rangeOfString:@"?"].location == NSNotFound ? @"?%@" : @"&%@", AEQueryStringFromParameters(parameters)]];
+ [targetRequest setURL:newURL];
+ } copy];
+ });
+ return queryStringProcessingBlock;
}
+ (AEURLConnectionParameterProcessingBlock)formURLEncodedProcessingBlock {
- static AEURLConnectionParameterProcessingBlock formURLEncodedProcessingBlock;
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- formURLEncodedProcessingBlock = [^(NSDictionary *parameters, NSMutableURLRequest *targetRequest){
- [targetRequest setValue:@"application/x-www-form-urlencoded; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
- [targetRequest setHTTPBody:[AEQueryStringFromParameters(parameters) dataUsingEncoding:NSUTF8StringEncoding]];
- } copy];
- });
- return formURLEncodedProcessingBlock;
+ static AEURLConnectionParameterProcessingBlock formURLEncodedProcessingBlock;
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ formURLEncodedProcessingBlock = [^(NSDictionary *parameters, NSMutableURLRequest *targetRequest){
+ [targetRequest setValue:@"application/x-www-form-urlencoded; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
+ [targetRequest setHTTPBody:[AEQueryStringFromParameters(parameters) dataUsingEncoding:NSUTF8StringEncoding]];
+ } copy];
+ });
+ return formURLEncodedProcessingBlock;
}
#pragma mark - URLEncoding
@@ -112,7 +112,7 @@ + (AEURLConnectionParameterProcessingBlock)formURLEncodedProcessingBlock {
static NSString * AEURLEncodedStringFromString(NSString *string) {
static NSString * const kAFLegalCharactersToBeEscaped = @"?!@#$^&%*+,:;='\"`<>()[]{}/\\|~ ";
- return [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, (CFStringRef)kAFLegalCharactersToBeEscaped, CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)) autorelease];
+ return [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, (CFStringRef)kAFLegalCharactersToBeEscaped, CFStringConvertNSStringEncodingToEncoding(NSUTF8StringEncoding)) autorelease];
}
static NSString * AEQueryStringFromParameters(NSDictionary *parameters) {
@@ -143,7 +143,7 @@ + (AEURLConnectionParameterProcessingBlock)formURLEncodedProcessingBlock {
}
static uint8_t const kAFBase64EncodingTable[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
-
+
NSUInteger idx = (i / 3) * 4;
output[idx + 0] = kAFBase64EncodingTable[(value >> 18) & 0x3F];
output[idx + 1] = kAFBase64EncodingTable[(value >> 12) & 0x3F];
@@ -100,6 +100,7 @@
C4C186831445FF9C003DBCC0 /* Products */,
);
sourceTree = "<group>";
+ usesTabs = 0;
};
C4C186831445FF9C003DBCC0 /* Products */ = {
isa = PBXGroup;
@@ -17,17 +17,17 @@ @implementation AEAppDelegate
@synthesize navigationController = _navigationController;
- (void)dealloc {
- [_window release];
- [_viewController release];
- [_navigationController release];
+ [_window release];
+ [_viewController release];
+ [_navigationController release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
- self.viewController = [[[AEViewController alloc] initWithNibName:@"AEViewController" bundle:nil] autorelease];;
- self.navigationController = [[[UINavigationController alloc] initWithRootViewController:self.viewController] autorelease];
- self.window.rootViewController = self.navigationController;
+ self.viewController = [[[AEViewController alloc] initWithNibName:@"AEViewController" bundle:nil] autorelease];;
+ self.navigationController = [[[UINavigationController alloc] initWithRootViewController:self.viewController] autorelease];
+ self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
@@ -9,6 +9,6 @@
#endif
#ifdef __OBJC__
- #import <UIKit/UIKit.h>
- #import <Foundation/Foundation.h>
+ #import <UIKit/UIKit.h>
+ #import <Foundation/Foundation.h>
#endif
@@ -21,57 +21,57 @@ @implementation AEViewController
@synthesize result=_result;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- UIActivityIndicatorView *spinner = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
-
- [self setTitle:@"AEURL Example"];
- [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] initWithCustomView:spinner] autorelease]];
- [spinner startAnimating];
-
- NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://graph.facebook.com/137947732957611"]];
- [AEURLConnection sendAsynchronousRequest:request
- queue:[NSOperationQueue mainQueue]
- processingBlock:[AEJSONProcessingBlock JSONResponseProcessingBlock]
- completionHandler:^(NSURLResponse *response, id data, NSError *error) {
- [spinner stopAnimating];
-
- if (error) {
- [[[[UIAlertView alloc] initWithTitle:[error localizedDescription]
- message:[error localizedRecoverySuggestion]
- delegate:nil
- cancelButtonTitle:@"OK"
- otherButtonTitles:nil] autorelease] show];
- } else {
- [self setKeys:[data allKeys]];
- [self setResult:data];
- [[self tableView] reloadData];
- }
- }];
- }
- return self;
+ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
+ if (self) {
+ UIActivityIndicatorView *spinner = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite] autorelease];
+
+ [self setTitle:@"AEURL Example"];
+ [[self navigationItem] setRightBarButtonItem:[[[UIBarButtonItem alloc] initWithCustomView:spinner] autorelease]];
+ [spinner startAnimating];
+
+ NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://graph.facebook.com/137947732957611"]];
+ [AEURLConnection sendAsynchronousRequest:request
+ queue:[NSOperationQueue mainQueue]
+ processingBlock:[AEJSONProcessingBlock JSONResponseProcessingBlock]
+ completionHandler:^(NSURLResponse *response, id data, NSError *error) {
+ [spinner stopAnimating];
+
+ if (error) {
+ [[[[UIAlertView alloc] initWithTitle:[error localizedDescription]
+ message:[error localizedRecoverySuggestion]
+ delegate:nil
+ cancelButtonTitle:@"OK"
+ otherButtonTitles:nil] autorelease] show];
+ } else {
+ [self setKeys:[data allKeys]];
+ [self setResult:data];
+ [[self tableView] reloadData];
+ }
+ }];
+ }
+ return self;
}
- (void)dealloc {
- [_keys release];
- [_result release];
- [super dealloc];
+ [_keys release];
+ [_result release];
+ [super dealloc];
}
#pragma mark - UITableViewDelegate/UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return [[self keys] count];
+ return [[self keys] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
- id key = [[self keys] objectAtIndex:[indexPath row]];
- id value = [[self result] objectForKey:key];
-
- UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:nil] autorelease];
- [[cell textLabel] setText:[key description]];
- [[cell detailTextLabel] setText:[value description]];
- return cell;
+ id key = [[self keys] objectAtIndex:[indexPath row]];
+ id value = [[self result] objectForKey:key];
+
+ UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 reuseIdentifier:nil] autorelease];
+ [[cell textLabel] setText:[key description]];
+ [[cell detailTextLabel] setText:[value description]];
+ return cell;
}
@end
@@ -12,7 +12,7 @@
int main(int argc, char *argv[])
{
- @autoreleasepool {
- return UIApplicationMain(argc, argv, nil, NSStringFromClass([AEAppDelegate class]));
- }
+ @autoreleasepool {
+ return UIApplicationMain(argc, argv, nil, NSStringFromClass([AEAppDelegate class]));
+ }
}
Oops, something went wrong.

0 comments on commit 5b702b1

Please sign in to comment.