Permalink
Browse files

Added branches. Closes #39.

  • Loading branch information...
dbloete committed Jan 27, 2010
1 parent a84de27 commit b356f870cee0f9ad88dbf479358672397957bc49
View
@@ -14,6 +14,7 @@
#define kIssueCellIdentifier @"IssueCell"
#define kUserCellIdentifier @"UserCell"
#define kNetworkCellIdentifier @"NetworkCell"
+#define kBranchCellIdentifier @"BranchCell"
// URLs
#define kUserGithubFormat @"http://github.com/%@"
@@ -22,8 +23,8 @@
#define kUserFeedFormat @"http://github.com/%@.atom"
#define kNewsFeedFormat @"https://github.com/%@.private.atom?token=%@"
#define kActivityFeedFormat @"https://github.com/%@.private.actor.atom?token=%@"
-#define kRepoFeedFormat @"http://github.com/feeds/%@/commits/%@/master"
-#define kPrivateRepoFeedFormat @"https://github.com/feeds/%@/commits/%@/master"
+#define kRepoFeedFormat @"http://github.com/feeds/%@/commits/%@/%@"
+#define kPrivateRepoFeedFormat @"https://github.com/feeds/%@/commits/%@/%@"
#define kUserXMLFormat @"https://github.com/api/v2/xml/user/show/%@"
#define kAuthenticateUserXMLFormat @"https://github.com/api/v2/xml/user/show/%@?login=%@&token=%@"
#define kUserReposFormat @"https://github.com/api/v2/xml/repos/show/%@"
@@ -38,6 +39,7 @@
#define kRepoUnwatchFormat @"https://github.com/api/v2/xml/repos/watch/%@/%@?token=%@"
#define kUserFollowFormat @"https://github.com/api/v2/xml/user/follow/%@?token=%@"
#define kUserUnfollowFormat @"https://github.com/api/v2/xml/user/unfollow/%@?token=%@"
+#define kRepoBranchesJSONFormat @"http://github.com/api/v2/json/repos/show/%@/%@/branches"
#define kRepoIssuesXMLFormat @"http://github.com/api/v2/xml/issues/list/%@/%@/%@"
#define kOpenIssueXMLFormat @"http://github.com/api/v2/xml/issues/open/%@/%@"
#define kEditIssueXMLFormat @"http://github.com/api/v2/xml/issues/edit/%@/%@/%d"
View
@@ -0,0 +1,11 @@
+#import <UIKit/UIKit.h>
+#import "GHBranch.h"
+
+
+@interface BranchCell : UITableViewCell {
+ GHBranch *branch;
+}
+
+@property(nonatomic,retain)GHBranch *branch;
+
+@end
View
@@ -0,0 +1,29 @@
+#import "BranchCell.h"
+
+
+@implementation BranchCell
+
+@synthesize branch;
+
+- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
+ [super initWithStyle:style reuseIdentifier:reuseIdentifier];
+ self.textLabel.font = [UIFont systemFontOfSize:16.0f];
+ self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
+ self.opaque = YES;
+ return self;
+}
+
+- (void)dealloc {
+ [branch release], branch = nil;
+ [super dealloc];
+}
+
+- (void)setBranch:(GHBranch *)theBranch {
+ [theBranch retain];
+ [branch release];
+ branch = theBranch;
+ self.imageView.image = [UIImage imageNamed:@"commit.png"];
+ self.textLabel.text = branch.name;
+}
+
+@end
View
@@ -0,0 +1,21 @@
+#import <Foundation/Foundation.h>
+#import "GHResource.h"
+
+
+@class GHRepository, GHFeed;
+
+@interface GHBranch : GHResource {
+ GHRepository *repository;
+ GHFeed *recentCommits;
+ NSString *name;
+ NSString *sha;
+}
+
+@property(nonatomic,retain)GHRepository *repository;
+@property(nonatomic,retain)GHFeed *recentCommits;
+@property(nonatomic,retain)NSString *name;
+@property(nonatomic,retain)NSString *sha;
+
+- (id)initWithRepository:(GHRepository *)theRepository andName:(NSString *)theName;
+
+@end
View
@@ -0,0 +1,33 @@
+#import "GHBranch.h"
+#import "GHRepository.h"
+#import "GHFeed.h"
+
+
+@implementation GHBranch
+
+@synthesize repository;
+@synthesize recentCommits;
+@synthesize name;
+@synthesize sha;
+
+- (id)initWithRepository:(GHRepository *)theRepository andName:(NSString *)theName {
+ [super init];
+ self.repository = theRepository;
+ self.name = theName;
+ // Recent Commits
+ NSString *urlString = [NSString stringWithFormat:(repository.isPrivate ? kPrivateRepoFeedFormat : kRepoFeedFormat), repository.owner, repository.name, name];
+ NSURL *feedURL = [NSURL URLWithString:urlString];
+ self.recentCommits = [[[GHFeed alloc] initWithURL:feedURL] autorelease];
+ return self;
+}
+
+
+- (void)dealloc {
+ [repository release], repository = nil;
+ [recentCommits release], recentCommits = nil;
+ [name release], name = nil;
+ [sha release], sha = nil;
+ [super dealloc];
+}
+
+@end
View
@@ -0,0 +1,18 @@
+#import <Foundation/Foundation.h>
+#import "GHResource.h"
+
+
+@class GHRepository;
+
+@interface GHBranches : GHResource {
+ NSMutableArray *branches;
+ GHRepository *repository;
+}
+
+@property(nonatomic,retain)NSMutableArray *branches;
+@property(nonatomic,retain)GHRepository *repository;
+
+- (id)initWithRepository:(GHRepository *)theRepository;
+- (void)loadBranches;
+
+@end
View
@@ -0,0 +1,72 @@
+#import "GHBranches.h"
+#import "GHBranch.h"
+#import "GHRepository.h"
+#import "ASIFormDataRequest.h"
+#import "CJSONDeserializer.h"
+
+
+@interface GHBranches ()
+- (void)parseBranches;
+@end
+
+
+@implementation GHBranches
+
+@synthesize branches;
+@synthesize repository;
+
+- (id)initWithRepository:(GHRepository *)theRepository {
+ [super init];
+ self.repository = theRepository;
+ self.branches = [NSMutableArray array];
+ return self;
+}
+
+- (void)dealloc {
+ [branches release], branches = nil;
+ [repository release], repository = nil;
+ [super dealloc];
+}
+
+- (NSString *)description {
+ return [NSString stringWithFormat:@"<GHBranches repository:'%@'>", repository];
+}
+
+- (void)loadBranches {
+ if (self.isLoading) return;
+ self.error = nil;
+ self.loadingStatus = GHResourceStatusLoading;
+ [self performSelectorInBackground:@selector(parseBranches) withObject:nil];
+}
+
+- (void)parseBranches {
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSString *urlString = [NSString stringWithFormat:kRepoBranchesJSONFormat, repository.owner, repository.name];
+ NSURL *branchesURL = [NSURL URLWithString:urlString];
+ ASIFormDataRequest *request = [GHResource authenticatedRequestForURL:branchesURL];
+ [request start];
+ NSError *parseError = nil;
+ NSDictionary *dict = [[CJSONDeserializer deserializer] deserialize:[request responseData] error:&parseError];
+ NSMutableArray *resources = [NSMutableArray array];
+ for (NSString *branchName in [[dict objectForKey:@"branches"] allKeys]) {
+ GHBranch *branch = [[GHBranch alloc] initWithRepository:repository andName:branchName];
+ branch.sha = [[dict objectForKey:@"branches"] objectForKey:branchName];
+ [resources addObject:branch];
+ [branch release];
+ }
+ id result = parseError ? (id)parseError : (id)resources;
+ [self performSelectorOnMainThread:@selector(loadedBranches:) withObject:result waitUntilDone:YES];
+ [pool release];
+}
+
+- (void)loadedBranches:(id)theResult {
+ if ([theResult isKindOfClass:[NSError class]]) {
+ self.error = theResult;
+ self.loadingStatus = GHResourceStatusNotLoaded;
+ } else {
+ self.branches = theResult;
+ self.loadingStatus = GHResourceStatusLoaded;
+ }
+}
+
+@end
View
@@ -4,7 +4,7 @@
#import "GHFeed.h"
-@class GHIssues, GHNetworks;
+@class GHIssues, GHNetworks, GHBranches;
@interface GHRepository : GHResource {
NSString *name;
@@ -17,7 +17,7 @@
GHIssues *openIssues;
GHIssues *closedIssues;
GHNetworks *networks;
- GHFeed *recentCommits;
+ GHBranches *branches;
BOOL isPrivate;
BOOL isFork;
}
@@ -27,10 +27,10 @@
@property (nonatomic, retain) NSString *descriptionText;
@property (nonatomic, retain) NSURL *githubURL;
@property (nonatomic, retain) NSURL *homepageURL;
-@property (nonatomic, retain) GHFeed *recentCommits;
@property (nonatomic, retain) GHIssues *openIssues;
@property (nonatomic, retain) GHIssues *closedIssues;
@property (nonatomic, retain) GHNetworks *networks;
+@property (nonatomic, retain) GHBranches *branches;
@property (nonatomic, readonly) GHUser *user;
@property (nonatomic, readwrite) NSInteger forks;
@property (nonatomic, readwrite) NSInteger watchers;
View
@@ -4,6 +4,7 @@
#import "GHCommitsParserDelegate.h"
#import "GHIssues.h"
#import "GHNetworks.h"
+#import "GHBranches.h"
@interface GHRepository ()
@@ -14,7 +15,8 @@ - (void)parseXML;
@implementation GHRepository
@synthesize name, owner, descriptionText, githubURL, homepageURL, isPrivate;
-@synthesize isFork, forks, watchers, recentCommits, openIssues, closedIssues, networks;
+@synthesize isFork, forks, watchers, openIssues, closedIssues;
+@synthesize networks, branches;
- (id)initWithOwner:(NSString *)theOwner andName:(NSString *)theName {
[super init];
@@ -28,10 +30,10 @@ - (void)dealloc {
[descriptionText release];
[githubURL release];
[homepageURL release];
- [recentCommits release];
[openIssues release];
[closedIssues release];
[networks release];
+ [branches release];
[super dealloc];
}
@@ -47,12 +49,10 @@ - (NSString *)description {
- (void)setOwner:(NSString *)theOwner andName:(NSString *)theName {
self.owner = theOwner;
self.name = theName;
- // Recent Commits
- NSString *commitFeedURLString = [NSString stringWithFormat:(isPrivate ? kPrivateRepoFeedFormat : kRepoFeedFormat), owner, name];
- NSURL *commitFeedURL = [NSURL URLWithString:commitFeedURLString];
- self.recentCommits = [[[GHFeed alloc] initWithURL:commitFeedURL] autorelease];
// Networks
self.networks = [[[GHNetworks alloc] initWithRepository:self] autorelease];
+ // Branches
+ self.branches = [[[GHBranches alloc] initWithRepository:self] autorelease];
// Issues
self.openIssues = [[[GHIssues alloc] initWithRepository:self andState:kIssueStateOpen] autorelease];
self.closedIssues = [[[GHIssues alloc] initWithRepository:self andState:kIssueStateClosed] autorelease];
@@ -56,7 +56,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
[[NSBundle mainBundle] loadNibNamed:@"NetworkCell" owner:self options:nil];
cell = networkCell;
}
- cell.network = [self.currentNetworks.entries objectAtIndex:indexPath.row];
+ cell.network = [self.currentNetworks.entries objectAtIndex:indexPath.row];
return cell;
}
@@ -1,7 +1,7 @@
#import <UIKit/UIKit.h>
-@class GHRepository, GHUser, FeedEntryCell, TextCell, LabeledCell, IssueCell, NetworkCell;
+@class GHRepository, GHUser, TextCell, LabeledCell;
@interface RepositoryController : UITableViewController <UIActionSheetDelegate> {
@private
@@ -13,7 +13,7 @@
IBOutlet UILabel *websiteLabel;
IBOutlet UILabel *forkLabel;
IBOutlet UITableViewCell *loadingCell;
- IBOutlet UITableViewCell *commitsCell;
+ IBOutlet UITableViewCell *branchCell;
IBOutlet UITableViewCell *issuesCell;
IBOutlet UITableViewCell *networkCell;
IBOutlet UIImageView *iconView;
Oops, something went wrong.

0 comments on commit b356f87

Please sign in to comment.