Skip to content

Instantly share code, notes, and snippets.

@dmason82
Created February 25, 2014 01:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dmason82/9200614 to your computer and use it in GitHub Desktop.
Save dmason82/9200614 to your computer and use it in GitHub Desktop.
#import "OAuthConsumer.h"
#import <YAJL/YAJL.h>
/**Mostly uses https://github.com/Yelp/yelp-api/tree/master/v2/ios/YelpAPI as the template, this is a snippet from a project that
imported theOAuthConsumer library and their YAJL Framework and disabled ARC on the entire OAuthConsumer library.
In the end, this returns an NSDictionary* that contains the Yelp request output.
**/
-(IBAction)fetchYelp{
NSURL *URL = [NSURL URLWithString:@"http://api.yelp.com/v2/search?term=restaurants&location=new%20york"];
OAConsumer *consumer = [[OAConsumer alloc] initWithKey:@"CONSUMER_KEY" secret:@"CONSUMER_SECRET"];
OAToken *token = [[OAToken alloc] initWithKey:@"TOKEN" secret:@"TOKEN_SECRET"] ;
id<OASignatureProviding, NSObject> provider = [[OAHMAC_SHA1SignatureProvider alloc] init] ;
NSString *realm = nil;
OAMutableURLRequest *request = [[OAMutableURLRequest alloc] initWithURL:URL
consumer:consumer
token:token
realm:realm
signatureProvider:provider];
[request prepare];
_responseData = [[NSMutableData alloc] init];
// NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSURLSessionTask* task = [[NSURLSession sharedSession] dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){ _JSON = [data yajl_JSON];
NSLog(@"%@",_JSON);
[self performSelectorOnMainThread:@selector(updateStuff) withObject:self waitUntilDone:NO];
}];
[task resume];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment