Skip to content

Instantly share code, notes, and snippets.

@jhalickman
Created September 9, 2011 02:30
Show Gist options
  • Save jhalickman/1205360 to your computer and use it in GitHub Desktop.
Save jhalickman/1205360 to your computer and use it in GitHub Desktop.
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