Skip to content

Commit 750d045

Browse files
committed
return URL for friendlier api; update test
1 parent ad414ac commit 750d045

File tree

3 files changed

+29
-35
lines changed

3 files changed

+29
-35
lines changed

Classes/Auth/TMOAuth.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,14 @@ __attribute__((objc_subclassing_restricted))
6161
@param tokenSecret OAuth user secret
6262
@param timestamp Unix / epoch time
6363
*/
64-
+ (NSString *)signUrlWithQueryComponent:(NSURL *)URL
65-
method:(NSString *)method
66-
postParameters:(NSDictionary *)postParameters
67-
nonce:(NSString *)nonce
68-
consumerKey:(NSString *)consumerKey
69-
consumerSecret:(NSString *)consumerSecret
70-
token:(NSString *)token
71-
tokenSecret:(NSString *)tokenSecret
72-
timestamp:(NSString *)timestamp;
64+
+ (NSURL *)signUrlWithQueryComponent:(NSURL *)URL
65+
method:(NSString *)method
66+
postParameters:(NSDictionary *)postParameters
67+
nonce:(NSString *)nonce
68+
consumerKey:(NSString *)consumerKey
69+
consumerSecret:(NSString *)consumerSecret
70+
token:(NSString *)token
71+
tokenSecret:(NSString *)tokenSecret
72+
timestamp:(NSString *)timestamp;
7373

7474
@end

Classes/Auth/TMOAuth.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ + (NSString *)headerForURL:(NSURL *)URL
5252
return auth.headerString;
5353
}
5454

55-
+ (NSString *)signUrlWithQueryComponent:(NSURL *)URL
56-
method:(NSString *)method
57-
postParameters:(NSDictionary *)postParameters
58-
nonce:(NSString *)nonce
59-
consumerKey:(NSString *)consumerKey
60-
consumerSecret:(NSString *)consumerSecret
61-
token:(NSString *)token
62-
tokenSecret:(NSString *)tokenSecret
63-
timestamp:(NSString *)timestamp {
55+
+ (NSURL *)signUrlWithQueryComponent:(NSURL *)URL
56+
method:(NSString *)method
57+
postParameters:(NSDictionary *)postParameters
58+
nonce:(NSString *)nonce
59+
consumerKey:(NSString *)consumerKey
60+
consumerSecret:(NSString *)consumerSecret
61+
token:(NSString *)token
62+
tokenSecret:(NSString *)tokenSecret
63+
timestamp:(NSString *)timestamp {
6464

6565
NSMutableDictionary *oAuthParameters = [TMOAuth OAuthParametersFromURL:nil
6666
url: URL
@@ -72,7 +72,7 @@ + (NSString *)signUrlWithQueryComponent:(NSURL *)URL
7272
token: token
7373
tokenSecret: tokenSecret
7474
timestamp: timestamp];
75-
return [URL.absoluteString stringByAppendingFormat:@"?%@", [TMURLEncoding encodedDictionary:oAuthParameters]];
75+
return [NSURL URLWithString:[URL.absoluteString stringByAppendingFormat:@"?%@", [TMURLEncoding encodedDictionary:oAuthParameters]]];
7676
}
7777

7878
- (id)initWithURL:(NSURL *)URL

ExampleiOS/ExampleiOSTests/TMOAuthTests.m

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,16 @@ @interface TMOAuthTests : XCTestCase
1616
@implementation TMOAuthTests
1717

1818
- (void)testSignUrlWithQueryComponentCalculatesProperSignature {
19-
NSString *signedURL = [TMOAuth signUrlWithQueryComponent:[NSURL URLWithString:@"https://tumblr.com/"]
20-
method:@"GET"
21-
postParameters:[NSDictionary dictionary]
22-
nonce:@"1234"
23-
consumerKey:@"consumerKey"
24-
consumerSecret:@"consumerSecret"
25-
token:@"token"
26-
tokenSecret:@"tokenSecret"
27-
timestamp:@"1511967770"];
28-
29-
NSURLComponents *urlComponents = [NSURLComponents componentsWithString:signedURL];
30-
NSArray *queryItems = urlComponents.queryItems;
31-
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name=%@", @"oauth_signature"];
32-
NSURLQueryItem *queryItem = [queryItems filteredArrayUsingPredicate:predicate].firstObject;
33-
34-
XCTAssert([queryItem.value isEqualToString:@"w/LP1MdJwiCfakR3GbW9IoeOz1E="], @"The generated OAuth signature should match the expected value.");
19+
NSURL *signedURL = [TMOAuth signUrlWithQueryComponent:[NSURL URLWithString:@"https://tumblr.com/"]
20+
method:@"GET"
21+
postParameters:[NSDictionary dictionary]
22+
nonce:@"1234"
23+
consumerKey:@"consumerKey"
24+
consumerSecret:@"consumerSecret"
25+
token:@"token"
26+
tokenSecret:@"tokenSecret"
27+
timestamp:@"1511967770"];
28+
XCTAssert([signedURL.absoluteString isEqualToString:@"https://tumblr.com/?oauth_consumer_key=consumerKey&oauth_nonce=1234&oauth_signature=w/LP1MdJwiCfakR3GbW9IoeOz1E%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1511967770&oauth_token=token&oauth_version=1.0"], @"The generated OAuth signature should match the expected value.");
3529
}
3630

3731
- (void)testInitSetsInstanceVariables {

0 commit comments

Comments
 (0)