Skip to content

Hi! I cleaned up your code for you! #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions TKPostsRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ - (void)dealloc;
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict;
{
_currentElementName = elementName;

if ([elementName isEqualToString:@"post"])
_currentPost = [[TKPost postWithAttributes:attributeDict] retain];
}
Expand All @@ -59,7 +59,7 @@ - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName names
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;
{
static NSDictionary *elementToSelectorDict = nil;

if (!elementToSelectorDict) {
elementToSelectorDict = [[NSDictionary alloc] initWithObjectsAndKeys:
@"appendToText:", @"text",
Expand All @@ -69,7 +69,7 @@ - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;
@"setURLWithString:", @"url",
nil];
}

NSString *key = [[_currentElementName componentsSeparatedByString:@"-"] lastObject];
SEL selector = NSSelectorFromString([elementToSelectorDict objectForKey:key]);
if (selector && [_currentPost respondsToSelector:selector]) {
Expand Down Expand Up @@ -98,7 +98,7 @@ - (NSURL *)URL;
NSString *value = [options objectForKey:key];
[queryStringArray addObject:[NSString stringWithFormat:@"%@=%@", key, value]];
}

[URLString appendString:[queryStringArray componentsJoinedByString:@"&"]];
NSURL *URL = [NSURL URLWithString:URLString];
return URL;
Expand All @@ -125,11 +125,11 @@ - (id)initWithOptions:(NSDictionary *)options delegate:(id<TKPostsRequestDelegat

if (![options objectForKey:TKPostsRequestDomainKey])
[NSException raise:@"TKPostsRequestDomainKey is mandatory" format:@"TKPostsRequestDomainKey is mandatory"];
_receivedPosts = [[NSMutableArray alloc] init];

_receivedPosts = [[NSMutableArray alloc] init];
_options = [options retain];
_delegate = delegate;

return self;
}

Expand Down
4 changes: 2 additions & 2 deletions TKPostsResponse.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ - (id)initWithPosts:(NSArray *)posts;
{
if (!(self = [self init]))
return nil;

_posts = [posts retain];

return self;
}

Expand Down
12 changes: 6 additions & 6 deletions TKRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ - (id)init;
{
if (!(self = [super init]))
return nil;

_receivedData = [[NSMutableData alloc] init];

return self;
}

Expand Down Expand Up @@ -66,7 +66,7 @@ - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data;

- (void)connectionDidFinishLoading:(NSURLConnection *)connection;
{
[self connectionDidFinishLoadingData:_receivedData];
[self connectionDidFinishLoadingData:_receivedData];
}

#pragma mark - API
Expand All @@ -75,15 +75,15 @@ - (void)start;
{
NSAssert(!_connection, @"start can't be called twice without being cancelled.");
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[self URL]];

if ([self respondsToSelector:@selector(HTTPBody)]) {
theRequest.HTTPMethod = @"POST";
theRequest.HTTPBody = self.HTTPBody;
}
}
else {
theRequest.HTTPMethod = @"GET";
}

_connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
}

Expand Down
2 changes: 1 addition & 1 deletion TKTumblelog.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ - (id)initWithAttributes:(NSDictionary *)attributeDict
self.URL = [NSURL URLWithString:[attributeDict objectForKey:@"url"]];
self.avatarURL = [NSURL URLWithString:[attributeDict objectForKey:@"avatar-url"]];
self.privateID = [NSNumber numberWithInt:[[attributeDict objectForKey:@"private-id"] intValue]];
self.primary = [[attributeDict objectForKey:@"is-primary"] isEqualToString:@"yes"];
self.primary = [[attributeDict objectForKey:@"is-primary"] isEqualToString:@"yes"];
}
return self;
}
Expand Down
22 changes: 11 additions & 11 deletions TumblrKit Tests for Mac/TumblrKit_Tests_for_Mac.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ - (void)testPostsRequest001;
[options setObject:[NSNumber numberWithInt:10] forKey:TKPostsRequestNumberOfPostsKey];
request = [[[TKPostsRequest alloc] initWithOptions:options delegate:self] autorelease];
STAssertEqualObjects([[request URL] absoluteString], @"http://tumblrkit-test.tumblr.com/api/read?num=10", nil);

[options setObject:[NSNumber numberWithInt:10] forKey:TKPostsRequestStartAtIndexKey];
request = [[[TKPostsRequest alloc] initWithOptions:options delegate:self] autorelease];
STAssertEqualObjects([[request URL] absoluteString], @"http://tumblrkit-test.tumblr.com/api/read?num=10&start=10", nil);

[options setObject:[NSNumber numberWithInt:10] forKey:TKPostsRequestPostIDKey];
request = [[[TKPostsRequest alloc] initWithOptions:options delegate:self] autorelease];
STAssertEqualObjects([[request URL] absoluteString], @"http://tumblrkit-test.tumblr.com/api/read?num=10&id=10&start=10", nil);
Expand All @@ -45,12 +45,12 @@ - (void)testPostsRequest001;
- (void)testPostsRequest002;
{
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
@"tumblrkit-test.tumblr.com", TKPostsRequestDomainKey,
[NSNumber numberWithInt:10], TKPostsRequestNumberOfPostsKey,
@"tumblrkit-test.tumblr.com", TKPostsRequestDomainKey,
[NSNumber numberWithInt:10], TKPostsRequestNumberOfPostsKey,
nil];
TKPostsRequest *request = [[[TKPostsRequest alloc] initWithOptions:options delegate:self] autorelease];
[request start];

while (!_testIsDone)
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];

Expand All @@ -66,7 +66,7 @@ - (void)testPostsRequest003;

TKPostsRequest *request = [[[TKPostsRequest alloc] initWithOptions:options delegate:self] autorelease];
[request start];

while (!_testIsDone)
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
}
Expand All @@ -77,10 +77,10 @@ - (void)testPostsRequest004;
@"tumblrkit-test.tumblr.com", TKPostsRequestDomainKey,
[NSNumber numberWithLong:8819125974], TKPostsRequestPostIDKey,
nil];

TKPostsRequest *request = [[[TKPostsRequest alloc] initWithOptions:options delegate:self] autorelease];
[request start];

while (!_testIsDone)
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:1.0]];
}
Expand All @@ -90,10 +90,10 @@ - (void)testPostsRequest004;
- (void)postsRequest:(TKPostsRequest *)request didReceiveResponse:(TKPostsResponse *)response;
{
_testIsDone = YES;

if ([request.options objectForKey:TKPostsRequestNumberOfPostsKey])
STAssertEquals([[request.options objectForKey:TKPostsRequestNumberOfPostsKey] intValue], (int)[response.posts count], nil);

if ([request.options objectForKey:TKPostsRequestPostIDKey]) {
STAssertEquals((int)[response.posts count], 1, nil);
TKPost *post = [response.posts objectAtIndex:0];
Expand All @@ -105,7 +105,7 @@ - (void)postsRequest:(TKPostsRequest *)request didReceiveResponse:(TKPostsRespon
- (void)postsRequest:(TKPostsRequest *)request didFailWithError:(NSError *)error;
{
_testIsDone = YES;

STFail(@"%@", error);
}

Expand Down
2 changes: 1 addition & 1 deletion TumblrKit for Mac/TumblrKit_for_Mac.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ - (id)init
if (self) {
// Initialization code here.
}

return self;
}

Expand Down
2 changes: 1 addition & 1 deletion TumblrKit for iOS/TumblrKit_for_iOS.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ - (id)init
if (self) {
// Initialization code here.
}

return self;
}

Expand Down