Skip to content

Commit

Permalink
Add booleanSuccess: variant of -invoke:, for API calls that would ret…
Browse files Browse the repository at this point in the history
…urn a YES or NO.
  • Loading branch information
Owain R Hunt committed Apr 7, 2012
1 parent 747e748 commit 45241cb
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Classes/UAGithubEngine.m
Expand Up @@ -343,6 +343,24 @@ - (void)invoke:(void (^)(id obj))invocationBlock success:(UAGithubEngineSuccessB
}


- (void)invoke:(void (^)(id obj))invocationBlock booleanSuccess:(UAGithubEngineBooleanSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
{
__unsafe_unretained NSError *error = nil;
BOOL result;

NSInvocation *invocation = [NSInvocation jr_invocationWithTarget:self block:invocationBlock];
[invocation setArgument:&error atIndex:5];
[invocation invoke];
[invocation getReturnValue:&result];
if (error)
{
failureBlock(error);
}

successBlock(result);
}


#pragma mark
#pragma mark Gists
#pragma mark
Expand Down Expand Up @@ -389,9 +407,9 @@ - (void)editGist:(NSString *)gistId withDictionary:(NSDictionary *)gistDictionar
}


- (void)starGist:(NSString *)gistId success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
- (void)starGist:(NSString *)gistId success:(UAGithubEngineBooleanSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
{
[self invoke:^(id self){[self sendRequest:[NSString stringWithFormat:@"gists/%@/star", gistId] requestType:UAGithubGistStarRequest responseType:UAGithubNoContentResponse error:nil];} success:successBlock failure:failureBlock];
[self invoke:^(id self){[self sendRequest:[NSString stringWithFormat:@"gists/%@/star", gistId] requestType:UAGithubGistStarRequest responseType:UAGithubNoContentResponse error:nil];} booleanSuccess:successBlock failure:failureBlock];
}


Expand Down

0 comments on commit 45241cb

Please sign in to comment.