Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Category prefixing and string constants #1

Merged
merged 4 commits into from

2 participants

@toco

I choose xngo as prefix to not clash with XNGAPIClient categories.

XNGOAuth1Client/NSDictionary+XNGOAuth1Additions.h
@@ -1,9 +1,9 @@
@interface NSDictionary (XNGOAuth1Additions)
-+ (id)dictionaryFromQueryString:(NSString *)queryString;
++ (id)xngo_dictionaryFromQueryString:(NSString *)queryString;
@pietbrauer Owner

We would prefer the old xng_ prefix instead of xngo_

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@toco

Now you have to make sure that XNGAPIClient does not contain that categories as well, but it should be fine.

@pietbrauer
Owner

Sure, they were included in the APIClient, I removed it. Thanks! :space_invader:

@pietbrauer pietbrauer merged commit 740dd55 into xing:master
@pietbrauer
Owner


Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 26, 2014
  1. @toco

    prefix category methods

    toco authored
  2. @toco

    move strings to constants

    toco authored
  3. @toco

    fix typo

    toco authored
  4. @toco
This page is out of date. Refresh to see the latest.
View
6 XNGOAuth1Client/NSDictionary+XNGOAuth1Additions.h
@@ -1,9 +1,9 @@
@interface NSDictionary (XNGOAuth1Additions)
-+ (id)dictionaryFromQueryString:(NSString *)queryString;
++ (id)xng_dictionaryFromQueryString:(NSString *)queryString;
-- (id)initWithQueryString:(NSString *)queryString;
+- (id)xng_initWithQueryString:(NSString *)queryString;
-- (NSString *)queryStringRepresentation;
+- (NSString *)xng_queryStringRepresentation;
@end
View
14 XNGOAuth1Client/NSDictionary+XNGOAuth1Additions.m
@@ -3,29 +3,29 @@
@implementation NSDictionary (XNGOAuth1Additions)
-+ (id)dictionaryFromQueryString:(NSString *)queryString {
- return [[NSDictionary alloc] initWithQueryString:queryString];
++ (id)xng_dictionaryFromQueryString:(NSString *)queryString {
+ return [[NSDictionary alloc] xng_initWithQueryString:queryString];
}
-- (id)initWithQueryString:(NSString *)queryString {
+- (id)xng_initWithQueryString:(NSString *)queryString {
NSArray *components = [queryString componentsSeparatedByString:@"&"];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
for (NSString *component in components) {
NSArray *keyValue = [component componentsSeparatedByString:@"="];
- NSString *key = [keyValue[0] URLDecode];
- NSString *value = [keyValue[1] URLDecode];
+ NSString *key = [keyValue[0] xng_URLDecode];
+ NSString *value = [keyValue[1] xng_URLDecode];
[dictionary setObject:value forKey:key];
}
return dictionary;
}
-- (NSString *)queryStringRepresentation {
+- (NSString *)xng_queryStringRepresentation {
NSMutableArray *paramArray = [NSMutableArray array];
[self enumerateKeysAndObjectsUsingBlock:^(id key, id value, BOOL *stop) {
- NSString *param = [NSString stringWithFormat:@"%@=%@", [key URLEncode], [value URLEncode]];
+ NSString *param = [NSString stringWithFormat:@"%@=%@", [key xng_URLEncode], [value xng_URLEncode]];
[paramArray addObject:param];
}];
View
4 XNGOAuth1Client/NSString+XNGOAuth1Additions.h
@@ -1,7 +1,7 @@
@interface NSString (XNGOAuth1Additions)
-- (NSString *)URLEncode;
+- (NSString *)xng_URLEncode;
-- (NSString *)URLDecode;
+- (NSString *)xng_URLDecode;
@end
View
4 XNGOAuth1Client/NSString+XNGOAuth1Additions.m
@@ -2,7 +2,7 @@
@implementation NSString (XNGOAuth1Additions)
-- (NSString *)URLEncode {
+- (NSString *)xng_URLEncode {
return (__bridge_transfer NSString *)
CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(__bridge CFStringRef)self,
@@ -11,7 +11,7 @@ - (NSString *)URLEncode {
kCFStringEncodingUTF8);
}
-- (NSString *)URLDecode {
+- (NSString *)xng_URLDecode {
return (__bridge_transfer NSString *)
CFURLCreateStringByReplacingPercentEscapesUsingEncoding(kCFAllocatorDefault,
(__bridge CFStringRef)self,
View
19 XNGOAuth1Client/XNGOAuthToken.m
@@ -1,6 +1,11 @@
#import "XNGOAuthToken.h"
#import "NSDictionary+XNGOAuth1Additions.h"
+static NSString *const XNGOAuthTokenTokenKey = @"oauth_token";
+static NSString *const XNGOAuthTokenSecretKey = @"oauth_token_secret";
+static NSString *const XNGOAuthTokenVerifierKey = @"oauth_verifier";
+static NSString *const XNGOAuthTokenDurationKey = @"oauth_token_duration";
+
@interface XNGOAuthToken ()
@property (nonatomic) NSDate *expiration;
@@ -27,19 +32,19 @@ - (id)initWithQueryString:(NSString *)queryString {
return nil;
}
- NSDictionary *attributes = [NSDictionary dictionaryFromQueryString:queryString];
+ NSDictionary *attributes = [NSDictionary xng_dictionaryFromQueryString:queryString];
if (attributes.allKeys.count == 0) {
return nil;
}
- NSString *token = attributes[@"oauth_token"];
- NSString *secret = attributes[@"oauth_token_secret"];
- NSString *verifier = attributes[@"oauth_verifier"];
+ NSString *token = attributes[XNGOAuthTokenTokenKey];
+ NSString *secret = attributes[XNGOAuthTokenSecretKey];
+ NSString *verifier = attributes[XNGOAuthTokenVerifierKey];
NSDate *expiration;
- if (attributes[@"oauth_token_duration"]) {
- expiration = [NSDate dateWithTimeIntervalSinceNow:[attributes[@"oauth_token_duration"] doubleValue]];
+ if (attributes[XNGOAuthTokenDurationKey]) {
+ expiration = [NSDate dateWithTimeIntervalSinceNow:[attributes[XNGOAuthTokenDurationKey] doubleValue]];
}
self = [self initWithToken:token secret:secret expiration:expiration];
@@ -48,7 +53,7 @@ - (id)initWithQueryString:(NSString *)queryString {
_verifier = verifier;
NSMutableDictionary *mutableUserInfo = [attributes mutableCopy];
- [mutableUserInfo removeObjectsForKeys:@[@"oauth_token", @"oauth_token_secret", @"oauth_verifier", @"oauth_token_duration"]];
+ [mutableUserInfo removeObjectsForKeys:@[XNGOAuthTokenTokenKey, XNGOAuthTokenSecretKey, XNGOAuthTokenVerifierKey, XNGOAuthTokenDurationKey]];
if (mutableUserInfo.allKeys.count > 0) {
_userInfo = [NSDictionary dictionaryWithDictionary:mutableUserInfo];
}
View
8 XNGOAuth1ClientTests/NSDictionaryAdditionsTests.m
@@ -12,7 +12,7 @@ @implementation NSDictionaryAdditionsTests
- (void)testInitializer {
NSString *queryString = @"param1=HELLO&param2=XING";
- NSDictionary *resultDict = [[NSDictionary alloc] initWithQueryString:queryString];
+ NSDictionary *resultDict = [[NSDictionary alloc] xng_initWithQueryString:queryString];
expect(resultDict[@"param1"]).to.equal(@"HELLO");
expect(resultDict[@"param2"]).to.equal(@"XING");
@@ -20,7 +20,7 @@ - (void)testInitializer {
- (void)testClassMethod {
NSString *queryString = @"param1=HELLO&param2=XING";
- NSDictionary *resultDict = [NSDictionary dictionaryFromQueryString:queryString];
+ NSDictionary *resultDict = [NSDictionary xng_dictionaryFromQueryString:queryString];
expect(resultDict[@"param1"]).to.equal(@"HELLO");
expect(resultDict[@"param2"]).to.equal(@"XING");
@@ -29,8 +29,8 @@ - (void)testClassMethod {
- (void)testQueryStringRepresentation {
NSDictionary *dictionary = @{
@"param1": @"HELLO",
- @"param2":@"XING"};
- NSString *queryString = [dictionary queryStringRepresentation];
+ @"param2": @"XING"};
+ NSString *queryString = [dictionary xng_queryStringRepresentation];
expect(queryString).to.equal(@"param1=HELLO&param2=XING");
}
Something went wrong with that request. Please try again.