Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Used the GitHub API v3 instead of the deprecated v2 in the ObjectionE…

…xample target
  • Loading branch information...
commit f2fa824aaa3cdcb11dabb8e012a9bd55af3a6a9d 1 parent 6d0d7ee
rvillarreal authored
View
19 Examples/ObjectionExample/ObjectionExample/GitHubAPI/OEGitHubAPI.m
@@ -11,15 +11,18 @@ @implementation OEGitHubAPI
@synthesize networkQueue = _networkQueue;
- (void)commitsWithAuthor:(NSString *)author inRepository:(NSString *)repo onBranch:(NSString *)branch completed:(void (^)(NSArray *))completedBlock {
- ASIHTTPRequest *request = [self.requestFactory requestWithRelativeURL:[NSString stringWithFormat:@"%@/%@/%@", author, repo, branch]];
+ // There's no documentation in the GitHub API v3 to get the commits from a branch
+ // TODO: Use the repo parameter when the documentation includes getting the commits from a branch
+ // http://developer.github.com/v3/repos/commits/
+ ASIHTTPRequest *request = [self.requestFactory requestWithRelativeURL:[NSString stringWithFormat:@"%@/%@/commits", author, repo]];
[request setCompletionBlock:^{
- NSArray *commitDictionaries = [[[request responseData] objectFromJSONData] objectForKey:@"commits"];
- NSMutableArray *commits = [[[NSMutableArray alloc] init] autorelease];
- for (NSDictionary *commitDictionary in commitDictionaries) {
- [commits addObject:[self.builder buildCommit:commitDictionary]];
- }
- completedBlock(commits);
+ NSArray *commitDictionaries = [[request responseData] objectFromJSONData];
+ NSMutableArray *commits = [[[NSMutableArray alloc] init] autorelease];
+ for (NSDictionary *commitDictionary in commitDictionaries) {
+ [commits addObject:[self.builder buildCommit:[commitDictionary objectForKey:@"commit"]]];
+ }
+ completedBlock(commits);
}];
[request setFailedBlock:^{
NSLog(@"Network Error: %@", [request error]);
@@ -29,7 +32,7 @@ - (void)commitsWithAuthor:(NSString *)author inRepository:(NSString *)repo onBra
}
- (void)dealloc {
- [_networkQueue release];
+ [_networkQueue release];
[_requestFactory release];
[_builder release];
[super dealloc];
View
10 Examples/ObjectionExample/ObjectionExample/GitHubAPI/OEGitHubObjectBuilder.m
@@ -5,11 +5,11 @@ @implementation OEGitHubObjectBuilder
objection_register(OEGitHubObjectBuilder)
- (OECommit *)buildCommit:(NSDictionary *)commitDictionary {
- OECommit *commit = [[[OECommit alloc] init] autorelease];
- commit.authorName = [[commitDictionary objectForKey:@"author"] objectForKey:@"name"];
- commit.authoredDate = [self parseGitHubDateString:[commitDictionary objectForKey:@"authored_date"]];
- commit.message = [commitDictionary objectForKey:@"message"];
- return commit;
+ OECommit *commit = [[[OECommit alloc] init] autorelease];
+ commit.authorName = [[commitDictionary objectForKey:@"author"] objectForKey:@"name"];
+ commit.authoredDate = [self parseGitHubDateString:[[commitDictionary objectForKey:@"author"] objectForKey:@"date"]];
+ commit.message = [commitDictionary objectForKey:@"message"];
+ return commit;
}
- (NSDate *)parseGitHubDateString:(NSString *)dateString {
View
3  Examples/ObjectionExample/ObjectionExample/GitHubAPI/OERequestFactory.m
@@ -1,6 +1,6 @@
#import "OERequestFactory.h"
-NSString *const kBaseURL = @"http://github.com/api/v2/json/commits/list/";
+NSString *const kBaseURL = @"https://api.github.com/repos/";
NSString *const kContentType = @"application/json";
NSString *const kContentEncoding = @"UTF-8";
@@ -11,6 +11,7 @@ - (ASIHTTPRequest *)requestWithRelativeURL:(NSString *)relativeURL {
NSURL *url = [NSURL URLWithString:relativeURL relativeToURL:[NSURL URLWithString:kBaseURL]];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
+ NSLog(@"Requesting Commits: %@", [url absoluteString]);
// Extra headers - ensure correct values
[request addRequestHeader:@"Accept" value:kContentType];
[request addRequestHeader:@"Accept-Charset" value:kContentEncoding];
Please sign in to comment.
Something went wrong with that request. Please try again.