Skip to content

Commit

Permalink
Merge in @theorm's additions to RKRequest, and re-vendor cocoa-oauth …
Browse files Browse the repository at this point in the history
…from our fork with @theorm's additions applied
  • Loading branch information
Christopher Swasey committed May 10, 2012
1 parent e8825f1 commit 856854a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
12 changes: 6 additions & 6 deletions Code/Network/RKRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -328,28 +328,28 @@ - (void)addHeadersToRequest {
parameters = [_URL queryParameters];

if (self.method == RKRequestMethodPUT)
echo = [GCOAuth URLRequestForPath:[_URL path]
echo = [GCOAuth URLRequestForPath:[_URL originalPath]
PUTParameters:parameters
scheme:[_URL scheme]
host:[_URL host]
host:[_URL hostAndPort]
consumerKey:self.OAuth1ConsumerKey
consumerSecret:self.OAuth1ConsumerSecret
accessToken:self.OAuth1AccessToken
tokenSecret:self.OAuth1AccessTokenSecret];
else if (self.method == RKRequestMethodPOST)
echo = [GCOAuth URLRequestForPath:[_URL path]
echo = [GCOAuth URLRequestForPath:[_URL originalPath]
POSTParameters:parameters
scheme:[_URL scheme]
host:[_URL host]
host:[_URL hostAndPort]
consumerKey:self.OAuth1ConsumerKey
consumerSecret:self.OAuth1ConsumerSecret
accessToken:self.OAuth1AccessToken
tokenSecret:self.OAuth1AccessTokenSecret];
else
echo = [GCOAuth URLRequestForPath:[_URL path]
echo = [GCOAuth URLRequestForPath:[_URL originalPath]
GETParameters:[_URL queryParameters]
scheme:[_URL scheme]
host:[_URL host]
host:[_URL hostAndPort]
consumerKey:self.OAuth1ConsumerKey
consumerSecret:self.OAuth1ConsumerSecret
accessToken:self.OAuth1AccessToken
Expand Down
13 changes: 12 additions & 1 deletion Vendor/cocoa-oauth/GCOAuth.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
tokenSecret:(NSString *)tokenSecret;

/*
Creates and returns a URL request that will perform a POST HTTPS operation. All
Creates and returns a URL request that will perform a POST HTTP operation. All
data will be sent as form URL encoded. Restrictions on the arguments to this
method are the same as the GET request methods.
*/
Expand Down Expand Up @@ -135,10 +135,21 @@
consumerSecret:(NSString *)consumerSecret
accessToken:(NSString *)accessToken
tokenSecret:(NSString *)tokenSecret;
@end

@interface NSString (GCOAuthAdditions)

// better percent escape
- (NSString *)pcen;
@end

@interface NSURL (GCOAuthURL)

/*
Get host:port from URL unless port is 80 or 443 (http://tools.ietf.org/html/rfc5849#section-3.4.1.2). Otherwis reurn only host.
*/
- (NSString *)hostAndPort;
@end
/*
XAuth example (because you may otherwise be scratching your head):
Expand Down
22 changes: 13 additions & 9 deletions Vendor/cocoa-oauth/GCOAuth.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ + (NSURLRequest *)URLRequestForPath:(NSString *)path
consumerSecret:(NSString *)consumerSecret
accessToken:(NSString *)accessToken
tokenSecret:(NSString *)tokenSecret;

@end
@interface NSString (GCOAuthAdditions)

// better percent escape
- (NSString *)pcen;

@end

@implementation GCOAuth
Expand Down Expand Up @@ -182,8 +175,8 @@ - (NSString *)signatureBase {
NSURL *URL = self.URL;
NSString *URLString = [NSString stringWithFormat:@"%@://%@%@",
[[URL scheme] lowercaseString],
[[URL host] lowercaseString],
[[URL path] lowercaseString]];
[[URL hostAndPort] lowercaseString],
[URL path]];

// create components
NSArray *components = [NSArray arrayWithObjects:
Expand Down Expand Up @@ -411,6 +404,17 @@ + (NSURLRequest *)URLRequestForPath:(NSString *)path
}

@end

@implementation NSURL (GCOAuthURL)
- (NSString *)hostAndPort {
if ([self port] != nil && [[self port] intValue] != 80 && [[self port] intValue] != 443) {
return [NSString stringWithFormat:@"%@:%@", [self host], [self port]];
} else {
return [self host];
}
}
@end

@implementation NSString (GCOAuthAdditions)
- (NSString *)pcen {
CFStringRef string = CFURLCreateStringByAddingPercentEscapes(NULL,
Expand Down

0 comments on commit 856854a

Please sign in to comment.