Created
February 25, 2014 01:06
-
-
Save dmason82/9200614 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
#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