Skip to content

Commit

Permalink
ARCized Tin. Removed JSONKit since were in a new century.
Browse files Browse the repository at this point in the history
  • Loading branch information
Inferis committed Apr 6, 2013
1 parent dff2db6 commit 4e0871d
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 144 deletions.
33 changes: 15 additions & 18 deletions Tin.m
Expand Up @@ -11,7 +11,6 @@
// Since ASIHTTP is no longer maintained, we switched to [AFNetworking](https://github.com/AFNetworking/AFNetworking)
#import "AFHTTPClient.h"
#import "AFHTTPRequestOperation.h"
#import "AFJSONUtilities.h"

// Each request returns a [TinResponse](TinResponse.html)
#import "TinBasicAuthenticator.h"
Expand Down Expand Up @@ -71,7 +70,7 @@ + (void)get:(NSString *)url success:(void(^)(TinResponse *response))callback {
}

+ (void)get:(NSString *)url query:(id)query success:(void(^)(TinResponse *response))callback {
[[[[self alloc] init] autorelease] get:url query:query success:callback];
[[[self alloc] init] get:url query:query success:callback];
}

#pragma mark GET SYNCHRONOUS
Expand All @@ -81,7 +80,7 @@ + (TinResponse *)get:(NSString *)url{
}

+ (TinResponse *)get:(NSString *)url query:(id)query {
return [[[[self alloc] init] autorelease] get:url query:query];
return [[[self alloc] init] get:url query:query];
}

#pragma mark POST ASYNCHRONOUS
Expand All @@ -108,7 +107,7 @@ + (void)post:(NSString *)url query:(id)query body:(id)body success:(void(^)(TinR
}

+ (void)post:(NSString *)url query:(id)aQuery body:(NSDictionary *)bodyData files:(NSMutableDictionary *)files success:(void(^)(TinResponse *response))callback {
[[[[self alloc] init] autorelease] post:url query:aQuery body:bodyData files:files success:callback];
[[[self alloc] init] post:url query:aQuery body:bodyData files:files success:callback];
}

#pragma mark POST SYNCHRONOUS
Expand All @@ -122,11 +121,11 @@ + (TinResponse *)post:(NSString *)url body:(NSDictionary *)bodyData{
}

+ (TinResponse *)post:(NSString *)url query:(id)aQuery body:(NSDictionary *)bodyData {
return [[[[self alloc] init] autorelease] post:url query:aQuery body:bodyData files:nil];
return [[[self alloc] init] post:url query:aQuery body:bodyData files:nil];
}

+ (TinResponse *)post:(NSString *)url query:(id)aQuery body:(NSDictionary *)bodyData files:(NSMutableDictionary *)files {
return [[[[self alloc] init] autorelease] post:url query:aQuery body:bodyData files:files];
return [[[self alloc] init] post:url query:aQuery body:bodyData files:files];
}

#pragma mark PUT ASYNCHRONOUS
Expand All @@ -153,7 +152,7 @@ + (void)put:(NSString *)url query:(id)query body:(id)body success:(void(^)(TinRe
}

+ (void)put:(NSString *)url query:(id)aQuery body:(id)body files:(NSMutableDictionary *)files success:(void(^)(TinResponse *response))callback {
[[[[self alloc] init] autorelease] put:url query:aQuery body:body files:files success:callback];
[[[self alloc] init] put:url query:aQuery body:body files:files success:callback];
}

#pragma mark PUT SYNCHRONOUS
Expand All @@ -171,7 +170,7 @@ + (TinResponse *)put:(NSString *)url query:(id)aQuery body:(id)body {
}

+ (TinResponse *)put:(NSString *)url query:(id)aQuery body:(id)body files:(NSMutableDictionary *)files {
return [[[[self alloc] init] autorelease] put:url query:aQuery body:body files:files];
return [[[self alloc] init] put:url query:aQuery body:body files:files];
}

#pragma mark DELETE ASYNCHRONOUS
Expand All @@ -185,7 +184,7 @@ + (void)delete:(NSString *)url body:(id)body success:(void(^)(TinResponse *respo
}

+ (void)delete:(NSString *)url query:(id)query body:(id)body success:(void(^)(TinResponse *response))callback {
[[[[self alloc] init] autorelease] delete:url query:query body:body success:callback];
[[[self alloc] init] delete:url query:query body:body success:callback];
}

#pragma mark DELETE SYNCHRONOUS
Expand All @@ -199,7 +198,7 @@ + (TinResponse *)delete:(NSString *)url body:(id)body {
}

+ (TinResponse *)delete:(NSString *)url query:(id)aQuery body:(id)body {
return [[[[self alloc] init] autorelease] delete:url query:aQuery body:body];
return [[[self alloc] init] delete:url query:aQuery body:body];
}

#pragma mark - Instance Methods
Expand All @@ -217,8 +216,6 @@ - (void)dealloc {
self.baseURI = nil;
self.contentType = nil;
self.headers = nil;

[super dealloc];
}

#pragma mark GET ASYNCHRONOUS
Expand Down Expand Up @@ -367,7 +364,7 @@ - (TinResponse *)performSynchronousRequest:(NSString *)method withURL:(NSString

[self waitFor:^(void(^done)(void)) {
[self performRequest:method withURL:urlString andQuery:query andBody:body andFiles:files andSuccessCallback:^(TinResponse *response) {
synchronousRequest = [response retain];
synchronousRequest = response;
done();
}];
}];
Expand All @@ -383,7 +380,7 @@ - (void)performRequest:(NSString *)method withURL:(NSString *)urlString andQuery

- (NSArray*)buildRequest:(NSString *)method withURL:(NSString *)urlString andQuery:(id)query andBody:(id)body andFiles:(NSMutableDictionary *)files {
// Initialize client
AFHTTPClient *_client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:self.baseURI]];
AFHTTPClient *_client = [[AFHTTPClient alloc] initWithBaseURL:[NSURL URLWithString:self.baseURI ?: @"http://localhost"]];
[self setOptionsOnClient:_client];

if (body && self.contentType != nil && ![self.contentType isEqualToString:@""]) {
Expand Down Expand Up @@ -422,9 +419,9 @@ - (void)performRequest:(NSString *)method withURL:(NSString *)urlString andQuery
NSURLRequest* _request = [req objectAtIndex:1];

// Initialize operation
TinHTTPRequestOperation *_operation = [[[TinHTTPRequestOperation alloc] initWithRequest:_request] autorelease];
TinHTTPRequestOperation *_operation = [[TinHTTPRequestOperation alloc] initWithRequest:_request] ;
if (files) {
[_operation setUploadProgressBlock:^(NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite) {
[_operation setUploadProgressBlock:^(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
if ([self.delegate respondsToSelector:@selector(didProgressRequest:totalBytesWriten:totalBytesExpectedToWrite:)]) {
[self.delegate didProgressRequest:_request totalBytesWriten:totalBytesWritten totalBytesExpectedToWrite:totalBytesExpectedToWrite];
}
Expand Down Expand Up @@ -509,7 +506,7 @@ + (NSDictionary*)splitQuery:(id)query
if ([query isKindOfClass:[NSDictionary class]]) return query;
if ([query isKindOfClass:[NSArray class]]) return query;
if ([query isKindOfClass:[NSData class]])
query = [[[NSString alloc] initWithData:query encoding:NSUTF8StringEncoding] autorelease];
query = [[NSString alloc] initWithData:query encoding:NSUTF8StringEncoding];

// make sure we have a string
query = [query description];
Expand Down Expand Up @@ -541,7 +538,7 @@ + (NSDictionary*)splitQuery:(id)query

+ (NSString *)decodeFromURL:(NSString*)source
{
NSString *decoded = [NSMakeCollectable(CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)source, CFSTR(""), kCFStringEncodingUTF8)) autorelease];
NSString *decoded = (__bridge_transfer NSString*) CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault, (CFStringRef)source, CFSTR(""), kCFStringEncodingUTF8);
return [decoded stringByReplacingOccurrencesOfString:@"+" withString:@" "];
}

Expand Down

0 comments on commit 4e0871d

Please sign in to comment.