Permalink
Browse files

started repositories model with a GET to GH for user repos

  • Loading branch information...
sschroed committed Jan 19, 2009
1 parent 22c1db2 commit 57cff40f6663a2c095d03c9e4fbd989f9829e68e
View
@@ -12,11 +12,14 @@
@interface Config : NSObject {
NSString *gitHubUserName;
NSString *baseURL;
+ NSMutableArray *repositories;
}
@property (copy) NSString *gitHubUserName;
@property (copy) NSString *baseURL;
+@property (copy) NSMutableArray *repositories;
+ (Config *)instance;
+- (NSString *)baseAPIURL;
@end
View
@@ -13,6 +13,7 @@ @implementation Config
@synthesize gitHubUserName;
@synthesize baseURL;
+@synthesize repositories;
// Make model a singleton
+ (Config *)instance
@@ -27,6 +28,10 @@ + (Config *)instance
return(gInstance);
}
+- (NSString *)baseAPIURL {
+ return [NSString stringWithFormat:@"%@/api/v1/json", [[Config instance] baseURL]];
+}
+
- (void) dealloc {
[gitHubUserName release];
[baseURL release];
@@ -32,6 +32,7 @@ - (BOOL)textFieldShouldReturn:(UITextField *)textField {
if (nil != textField.text && [textField.text length] > 0){
[[Config instance] setGitHubUserName:[textField text]];
[textField resignFirstResponder];
+ [Repository loadAll];
return YES;
} else {
[self showAlert:@"Please enter your GitHub username" withTitle:@"Octocat FAIL"];
View
@@ -7,3 +7,4 @@
//
#import "Config.h"
+#import "Repository.h"
@@ -63,6 +63,7 @@ - (void) loadPreferences {
[window addSubview:[loginViewController view]];
[navigationController presentModalViewController:loginViewController animated:YES];
} else {
+ //TODO: Autologin
DevLog(@"NOT NULL");
}
}
View
@@ -0,0 +1,19 @@
+//
+// Repository.h
+// git-phone
+//
+// Created by Sam Schroeder on 1/19/09.
+// Copyright 2009 Proton Microsystems, LLC. All rights reserved.
+//
+
+
+@interface Repository : NSObject {
+ NSString *name;
+}
+
+@property (nonatomic, retain) NSString *name;
+
++ (NSString *)indexURL;
++ (void)loadAll;
+
+@end
View
@@ -0,0 +1,45 @@
+//
+// Repository.m
+// git-phone
+//
+// Created by Sam Schroeder on 1/19/09.
+// Copyright 2009 Proton Microsystems, LLC. All rights reserved.
+//
+
+#import "Repository.h"
+#import "Connector.h"
+
+
+@implementation Repository
+
+@synthesize name;
+
++ (NSString *)indexURL {
+
+ return [NSString stringWithFormat:@"%@/%@",
+ [[Config instance] baseAPIURL],
+ [[Config instance] gitHubUserName]];
+}
+
++ (void)loadAll {
+ NSString *resultJSON = [Connector getJSONFromURL:[self indexURL]];
+
+ NSMutableArray *returnArray = [[[NSMutableArray alloc] init] autorelease];
+ NSMutableArray *repositories = [[[NSMutableArray alloc] init] autorelease];
+
+ // GitHub JSON: {"user": {"repositories": [{repo1},{repo1}] }}
+ repositories = [[[resultJSON JSONValue] valueForKey:@"user"] valueForKey:@"repositories"];
+
+ for (NSDictionary *repository in repositories) {
+ Repository *tempRepo = [[[Repository alloc] init] autorelease];
+ [tempRepo setName:[repository valueForKey:@"name"]];
+ DevLog2(@"Loaded Repo: %@", [tempRepo name]);
+
+ [returnArray addObject:tempRepo];
+ }
+
+ [[Config instance] setRepositories:returnArray];
+}
+
+
+@end
@@ -21,6 +21,7 @@
22E17C3B0F22490800D2853B /* Login.xib in Resources */ = {isa = PBXBuildFile; fileRef = 22E17C3A0F22490800D2853B /* Login.xib */; };
22E17C410F224A5700D2853B /* octocat_large.png in Resources */ = {isa = PBXBuildFile; fileRef = 22E17C400F224A5700D2853B /* octocat_large.png */; };
22E17D0D0F24F08C00D2853B /* Connector.m in Sources */ = {isa = PBXBuildFile; fileRef = 22E17D0C0F24F08C00D2853B /* Connector.m */; };
+ 22E17D580F25043800D2853B /* Repository.m in Sources */ = {isa = PBXBuildFile; fileRef = 22E17D570F25043800D2853B /* Repository.m */; };
22FA50040F212ED300709123 /* Settings.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 22FA50030F212ED300709123 /* Settings.bundle */; };
22FA502E0F21374300709123 /* octocat.png in Resources */ = {isa = PBXBuildFile; fileRef = 22FA502D0F21374300709123 /* octocat.png */; };
22FA50CE0F21463D00709123 /* Config.m in Sources */ = {isa = PBXBuildFile; fileRef = 22FA50CD0F21463D00709123 /* Config.m */; };
@@ -51,6 +52,8 @@
22E17C400F224A5700D2853B /* octocat_large.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = octocat_large.png; path = images/octocat_large.png; sourceTree = "<group>"; };
22E17D0B0F24F08C00D2853B /* Connector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Connector.h; sourceTree = "<group>"; };
22E17D0C0F24F08C00D2853B /* Connector.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Connector.m; sourceTree = "<group>"; };
+ 22E17D560F25043800D2853B /* Repository.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Repository.h; sourceTree = "<group>"; };
+ 22E17D570F25043800D2853B /* Repository.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Repository.m; sourceTree = "<group>"; };
22FA50030F212ED300709123 /* Settings.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = Settings.bundle; sourceTree = "<group>"; };
22FA502D0F21374300709123 /* octocat.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = octocat.png; path = images/octocat.png; sourceTree = "<group>"; };
22FA50CC0F21463D00709123 /* Config.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Config.h; path = Classes/Config.h; sourceTree = "<group>"; };
@@ -137,6 +140,8 @@
22FA50DB0F2147DC00709123 /* Models.h */,
22FA50CC0F21463D00709123 /* Config.h */,
22FA50CD0F21463D00709123 /* Config.m */,
+ 22E17D560F25043800D2853B /* Repository.h */,
+ 22E17D570F25043800D2853B /* Repository.m */,
);
name = Models;
sourceTree = "<group>";
@@ -279,6 +284,7 @@
22E17B9D0F223AA600D2853B /* ApplicationErrorViewController.m in Sources */,
22E17C1E0F22467200D2853B /* LoginViewController.m in Sources */,
22E17D0D0F24F08C00D2853B /* Connector.m in Sources */,
+ 22E17D580F25043800D2853B /* Repository.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

0 comments on commit 57cff40

Please sign in to comment.