Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Final integration of the TDOAuth library to the RestKit Framework.

  • Loading branch information...
commit 24174aea6901bcf92add4f52d7dc0bd3047b7acc 1 parent 8bf05c3
@rodchile authored
View
6 Code/Network/RKClient.m
@@ -118,7 +118,6 @@ + (RKClient*)clientWithBaseURL:(NSString*)baseURL username:(NSString*)username p
RKClient* client = [RKClient clientWithBaseURL:baseURL];
client.username = username;
client.password = password;
-
return client;
}
@@ -208,6 +207,11 @@ - (void)setupRequest:(RKRequest*)request {
request.forceBasicAuthentication = self.forceBasicAuthentication;
request.cachePolicy = self.cachePolicy;
request.cache = self.cache;
+ request.accessToken = self.accessToken;
+ request.accessTokenSecret = self.accessTokenSecret;
+ request.consumerKey = self.consumerKey;
+ request.consumerSecret = self.consumerSecret;
+ request.forceOAuthUse = self.forceOAuthUse;
}
View
17 Code/Network/RKRequest.h
@@ -82,6 +82,11 @@ typedef enum RKRequestBackgroundPolicy {
id _userData;
NSString* _username;
NSString* _password;
+ NSString* _consumerKey;
+ NSString* _consumerSecret;
+ NSString* _accessToken;
+ NSString* _accessTokenSecret;
+ BOOL _forceOAuthUse;
RKRequestMethod _method;
BOOL _isLoading;
BOOL _isLoaded;
@@ -192,6 +197,18 @@ typedef enum RKRequestBackgroundPolicy {
*/
@property (nonatomic, assign) NSTimeInterval cacheTimeoutInterval;
+
+/**
+ * The OAuth Secrets
+ *
+ **/
+
+@property(nonatomic,retain) NSString* consumerKey;
+@property(nonatomic,retain) NSString* consumerSecret;
+@property(nonatomic,retain) NSString* accessToken;
+@property(nonatomic,retain) NSString* accessTokenSecret;
+@property(nonatomic,assign) BOOL forceOAuthUse;
+
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
View
30 Code/Network/RKRequest.m
@@ -31,7 +31,7 @@ @implementation RKRequest
@synthesize URL = _URL, URLRequest = _URLRequest, delegate = _delegate, additionalHTTPHeaders = _additionalHTTPHeaders,
params = _params, userData = _userData, username = _username, password = _password, method = _method,
forceBasicAuthentication = _forceBasicAuthentication, cachePolicy = _cachePolicy, cache = _cache,
- cacheTimeoutInterval = _cacheTimeoutInterval;
+ cacheTimeoutInterval = _cacheTimeoutInterval, consumerKey = _consumerKey, consumerSecret = _consumerSecret, accessToken = _accessToken, accessTokenSecret = _accessTokenSecret, forceOAuthUse = _forceOAuthUse;
#if TARGET_OS_IPHONE
@synthesize backgroundPolicy = _backgroundPolicy, backgroundTaskIdentifier = _backgroundTaskIdentifier;
@@ -47,6 +47,7 @@ - (id)initWithURL:(NSURL*)URL {
_URL = [URL retain];
[self reset];
_forceBasicAuthentication = NO;
+ _forceOAuthUse = NO;
_cachePolicy = RKRequestCachePolicyDefault;
_cacheTimeoutInterval = 0;
}
@@ -194,6 +195,22 @@ - (void)addHeadersToRequest {
CFRelease(authorizationString);
}
+ // Add OAuth headers if is need it
+
+ if(_forceOAuthUse){
+ NSURLRequest *echo = [TDOAuth URLRequestForPath:[self resourcePath]
+ GETParameters:nil
+ scheme:[_URL scheme]
+ host:[_URL host]
+ consumerKey:_consumerKey
+ consumerSecret:_consumerSecret
+ accessToken:_accessToken
+ tokenSecret:_accessTokenSecret];
+ [_URLRequest setValue:[echo valueForHTTPHeaderField:@"Authorization"] forHTTPHeaderField:@"Authorization"];
+ [_URLRequest setValue:[echo valueForHTTPHeaderField:@"Accept-Encoding"] forHTTPHeaderField:@"Accept-Encoding"];
+ [_URLRequest setValue:[echo valueForHTTPHeaderField:@"User-Agent"] forHTTPHeaderField:@"User-Agent"];
+ }
+
if (self.cachePolicy & RKRequestCachePolicyEtag) {
NSString* etag = [self.cache etagForRequest:self];
if (etag) {
@@ -268,15 +285,8 @@ - (void)fireAsynchronousRequest {
}
RKResponse* response = [[[RKResponse alloc] initWithRequest:self] autorelease];
- NSURLRequest *echo = [TDOAuth URLRequestForPath:@"/1/statuses/home_timeline.json"
- GETParameters:nil
- scheme:@"https"
- host:@"api.twitter.com"
- consumerKey:@"Q93lF1U7DDKlINbYCyMN1A"
- consumerSecret:@"IgWmSDUvdJhkFjQQ1DmKZLXYNtYdyVRgVbC8uM1MA"
- accessToken:@"9717582-ZL0VMdytzcdRhcCyM0lSodZI1qvTRveH3xDsQ1aXwS"
- tokenSecret:@"mjHXBd3nbjyXDbh8MvfVQPsPrRdtTB2RH7ZqkjT2U4"];
- _connection = [[NSURLConnection connectionWithRequest:echo delegate:response] retain];
+
+ _connection = [[NSURLConnection connectionWithRequest:_URLRequest delegate:response] retain];
[[NSNotificationCenter defaultCenter] postNotificationName:RKRequestSentNotification object:self userInfo:nil];
}
View
2  Examples/RKTwitter/Classes/RKTwitterAppDelegate.m
@@ -18,7 +18,7 @@ @implementation RKTwitterAppDelegate
#pragma mark Application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
-// RKLogConfigureByName("RestKit/Network*", RKLogLevelTrace);
+ RKLogConfigureByName("RestKit/Network*", RKLogLevelTrace);
// Initialize RestKit
RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:@"http://twitter.com"];
View
9 Examples/RKTwitter/Classes/RKTwitterViewController.m
@@ -18,7 +18,12 @@ @implementation RKTwitterViewController
- (void)loadTimeline {
// Load the object model via RestKit
RKObjectManager* objectManager = [RKObjectManager sharedManager];
- objectManager.client.baseURL = @"http://www.twitter.com";
+ objectManager.client.baseURL = @"https://api.twitter.com";
+ objectManager.client.consumerKey = @"YOUR CONSUMER KEY HERE";
+ objectManager.client.consumerSecret = @"YOUR CONSUMER SECRET HERE";
+ objectManager.client.accessToken = @"YOUR ACCESS TOKEN HERE";
+ objectManager.client.accessTokenSecret = @"YOUR ACCESS TOKEN SECRET HERE";
+ objectManager.client.forceOAuthUse = YES;
RKObjectMapping* statusMapping = nil;
// Twitter returns statuses as a naked array in JSON, so we instruct the loader
@@ -27,7 +32,7 @@ - (void)loadTimeline {
statusMapping = [objectManager.mappingProvider objectMappingForKeyPath:@"status"];
}
- [objectManager loadObjectsAtResourcePath:@"/status/user_timeline/RestKit" objectMapping:statusMapping delegate:self];
+ [objectManager loadObjectsAtResourcePath:@"/1/statuses/home_timeline.json" objectMapping:statusMapping delegate:self];
}
- (void)loadView {
Please sign in to comment.
Something went wrong with that request. Please try again.