Permalink
Browse files

Started token auth and repo pull

  • Loading branch information...
1 parent 5afc5f7 commit 894e41a5027f356af1800a9161dc4589519f52b8 @sschroed committed Jan 25, 2009
Showing with 58 additions and 14 deletions.
  1. +2 −0 Classes/Config.h
  2. +3 −0 Classes/Config.m
  3. +1 −0 Classes/Connector.h
  4. +32 −2 Classes/Connector.m
  5. +0 −11 Info.plist
  6. +2 −1 Repository.m
  7. +18 −0 Settings.bundle/Root.plist
View
@@ -11,11 +11,13 @@
@interface Config : NSObject {
NSString *gitHubUserName;
+ NSString *gitHubToken;
NSString *baseURL;
NSMutableArray *repositories;
}
@property (copy) NSString *gitHubUserName;
+@property (copy) NSString *gitHubToken;
@property (copy) NSString *baseURL;
@property (copy) NSMutableArray *repositories;
View
@@ -12,6 +12,7 @@
@implementation Config
@synthesize gitHubUserName;
+@synthesize gitHubToken;
@synthesize baseURL;
@synthesize repositories;
@@ -34,7 +35,9 @@ - (NSString *)baseAPIURL {
- (void) dealloc {
[gitHubUserName release];
+ [gitHubToken release];
[baseURL release];
+ [repositories release];
[super dealloc];
}
View
@@ -16,5 +16,6 @@
+ (NSString *) getJSONFromURL:(NSString *)url; // issue a GET request
+ (NSString *) getJSONFromURL:(NSString *)url withDictionary:(NSDictionary *)dictionary; // issues a POST request
++ (NSString *)postToURL:(NSString *)url;
@end
View
@@ -52,7 +52,7 @@ + (NSString *) getJSONFromURL:(NSString *)url {
NSURLResponse *response;
NSError *error = nil;
- NSLog(@"Retrieving JSON from URL: %@", url);
+ DevLog2(@"Retrieving JSON from URL: %@", url);
urlData = [NSURLConnection sendSynchronousRequest:req returningResponse:&response error:&error];
@@ -64,7 +64,7 @@ + (NSString *) getJSONFromURL:(NSString *)url {
}
-// Sent a POST to the server with the attached JSON dictionary, return JSON string.
+// Send a POST to the server with the attached JSON dictionary, return JSON string.
+ (NSString *) getJSONFromURL:(NSString *)url withDictionary:(NSDictionary *)dictionary {
DevLog3(@"Sending JSON to %@: %@", url, [dictionary JSONRepresentation]);
@@ -82,4 +82,34 @@ + (NSString *) getJSONFromURL:(NSString *)url withDictionary:(NSDictionary *)dic
}
+// Standard POST
++ (NSString *)postToURL:(NSString *)url {
+
+ NSString *post = [NSString stringWithFormat:@"login=%@&token=%@", [[Config instance] gitHubUserName], [[Config instance] gitHubToken]];
+ NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
+
+ NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
+
+ NSMutableURLRequest *postRequest = [[[NSMutableURLRequest alloc] init] autorelease];
+ [postRequest setURL:[NSURL URLWithString:url]];
+ [postRequest setHTTPMethod:@"POST"];
+ [postRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
+ [postRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
+ [postRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
+ [postRequest setHTTPBody:postData];
+
+
+ NSData *urlData;
+ NSURLResponse *response;
+ NSError *error = nil;
+
+ urlData = [NSURLConnection sendSynchronousRequest:postRequest returningResponse:&response error:&error];
+
+ NSString *resp = [[[NSString alloc] initWithData:urlData encoding:NSUTF8StringEncoding] autorelease];
+
+ DevLog3(@"Received JSON from URL via POST: %@\n%@", url, resp);
+
+ return resp;
+}
+
@end
View
@@ -26,16 +26,5 @@
<true/>
<key>NSMainNibFile</key>
<string>MainWindow</string>
- <key>CFBundleURLTypes</key>
- <array>
- <dict>
- <key>CFBundleURLName</key>
- <string>com.protonmicro.git-phone</string>
- <key>CFBundleURLSchemes</key>
- <array>
- <string>git-phone</string>
- </array>
- </dict>
- </array>
</dict>
</plist>
View
@@ -22,7 +22,8 @@ + (NSString *)indexURL {
}
+ (void)loadAll {
- NSString *resultJSON = [Connector getJSONFromURL:[self indexURL]];
+
+ NSString *resultJSON = [Connector postToURL:[self indexURL]];
NSMutableArray *returnArray = [[[NSMutableArray alloc] init] autorelease];
NSMutableArray *repositories = [[[NSMutableArray alloc] init] autorelease];
View
@@ -26,6 +26,24 @@
<key>AutocorrectionType</key>
<string>No</string>
</dict>
+ <dict>
+ <key>Type</key>
+ <string>PSTextFieldSpecifier</string>
+ <key>Title</key>
+ <string>API Token</string>
+ <key>Key</key>
+ <string>GitHubToken</string>
+ <key>DefaultValue</key>
+ <string></string>
+ <key>IsSecure</key>
+ <true/>
+ <key>KeyboardType</key>
+ <string>Alphabet</string>
+ <key>AutocapitalizationType</key>
+ <string>None</string>
+ <key>AutocorrectionType</key>
+ <string>No</string>
+ </dict>
</array>
</dict>
</plist>

0 comments on commit 894e41a

Please sign in to comment.