Created
March 21, 2012 08:15
-
-
Save fannheyward/2145564 to your computer and use it in GitHub Desktop.
Add OAuth Echo methods to TWRequest
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 <Twitter/Twitter.h> | |
#import <Accounts/Accounts.h> | |
@interface TWRequest (OAuthEcho) | |
/* | |
* code example: | |
* | |
* NSURL *url = [NSURL URLWithString:@"https://api.twitter.com/1/account/verify_credentials.json"]; | |
* TWRequest *request = [[TWRequest alloc] initWithURL:url parameters:nil requestMethod:TWRequestMethodGET]; | |
* [request setAccount:account]; | |
* NSDictionary *headerFields = [request oauthEchoHeaderFields]; | |
* | |
* // NSMutableURL | |
* NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:apiURL]; | |
* [headerFields enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { | |
* [request setValue:obj forHTTPHeaderField:key]; | |
* }]; | |
* | |
* // MKNetWorkKit | |
* MKNetworkEngine *engine = [[[MKNetworkEngine alloc] initWithHostName:@"example.com" customHeaderFields:headerFields]; | |
* | |
* see: | |
* https://gist.github.com/1575035 | |
*/ | |
- (NSDictionary *)oauthEchoHeaderFields; | |
@end |
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 "TWRequest+OAuthEcho.h" | |
@implementation TWRequest (OAuthEcho) | |
- (NSDictionary *)oauthEchoHeaderFields | |
{ | |
NSURLRequest *signedURLRequest = [self signedURLRequest]; | |
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; | |
[dictionary setValue:[[signedURLRequest URL] absoluteString] | |
forKey:@"X-Auth-Service-Provider"]; | |
[dictionary setValue:[signedURLRequest valueForHTTPHeaderField:@"Authorization"] | |
forKey:@"X-Verify-Credentials-Authorization"]; | |
return [NSDictionary dictionaryWithDictionary:dictionary]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment