Created
September 9, 2011 02:30
-
-
Save jhalickman/1205360 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSString *safeGist = (NSString*)CFURLCreateStringByAddingPercentEscapes(NULL, | |
(CFStringRef)gist, | |
NULL, | |
(CFStringRef)@";/?:@&=+$,", | |
kCFStringEncodingUTF8); | |
NSString *body = [NSString stringWithFormat:@"file_contents[gistfile1]=%@&file_ext[gistfile1]=%@", safeGist, ext]; | |
[safeGist release]; | |
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; | |
NSString *urlString = [NSString stringWithFormat:@"%@/gists", [defaults stringForKey:@"GIST_URL"]]; | |
NSURL *url = [NSURL URLWithString:urlString]; | |
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url]; | |
[theRequest setHTTPMethod:@"POST"]; | |
[theRequest setHTTPBody: [body dataUsingEncoding:NSUTF8StringEncoding]]; | |
NSURLConnection *conn = [NSURLConnection connectionWithRequest:theRequest delegate:self]; | |
[conn start]; | |
} | |
-(void) sendGistToGitHub: (NSString *)gist withExtension: (NSString *) ext{ | |
NSDictionary *body = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:TRUE], @"public", | |
[NSDictionary dictionaryWithObjectsAndKeys:[NSDictionary dictionaryWithObjectsAndKeys:gist, @"content", nil], [NSString stringWithFormat:@"file1%@", ext], nil], @"files", | |
nil]; | |
SBJsonWriter *writer = [[SBJsonWriter alloc] init]; | |
NSString *bodyString = [writer stringWithObject:body]; | |
[writer release]; | |
NSLog(@"%@", bodyString); | |
NSURL *url = [NSURL URLWithStri |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment