Skip to content
This repository has been archived by the owner on Dec 18, 2022. It is now read-only.

Commit

Permalink
0.3.4: Login works again!
Browse files Browse the repository at this point in the history
  • Loading branch information
NSExceptional committed Sep 12, 2015
1 parent 10996c2 commit 3ce3871
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
38 changes: 20 additions & 18 deletions Pod/Classes/Categories/NSString+SnapchatKit.m
Expand Up @@ -116,12 +116,12 @@ + (NSString *)queryStringWithParams:(NSDictionary *)params URLEscapeValues:(BOOL
if (params.allKeys.count == 0) return @"";

NSMutableString *q = [NSMutableString string];
[params enumerateKeysAndObjectsUsingBlock:^(NSString *key, id value, BOOL *stop) {
[params enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *value, BOOL *stop) {
if ([value isKindOfClass:[NSString class]]) {
if (escapeValues) {
value = [(NSString *)value urlencode];
value = [value URLEncodedString];
} else {
value = [(NSString *)value stringByReplacingOccurrencesOfString:@" " withString:@"+"];
value = [value stringByReplacingOccurrencesOfString:@" " withString:@"+"];
}
}
[q appendFormat:@"%@=%@&", key, value];
Expand All @@ -132,24 +132,26 @@ + (NSString *)queryStringWithParams:(NSDictionary *)params URLEscapeValues:(BOOL
return q;
}

- (NSString *)urlencode {
NSMutableString *output = [NSMutableString string];
const unsigned char *source = (const unsigned char *)[self UTF8String];
int sourceLen = (int)strlen((const char *)source);
for (int i = 0; i < sourceLen; ++i) {
const unsigned char thisChar = source[i];
if (thisChar == ' '){
[output appendString:@"+"];
} else if (thisChar == '.' || thisChar == '-' || thisChar == '_' || thisChar == '~' ||
(thisChar >= 'a' && thisChar <= 'z') ||
(thisChar >= 'A' && thisChar <= 'Z') ||
(thisChar >= '0' && thisChar <= '9')) {
[output appendFormat:@"%c", thisChar];
- (NSString *)URLEncodedString {
NSMutableString *encoded = [NSMutableString string];
const unsigned char *source = (const unsigned char *)self.UTF8String;
NSInteger sourceLen = (NSInteger)strlen((const char *)source);

for (NSInteger i = 0; i < sourceLen; i++) {
const unsigned char c = source[i];
if (c == ' '){
[encoded appendString:@"+"];
} else if (c == '.' || c == '-' || c == '_' || c == '~' ||
(c >= 'a' && c <= 'z') ||
(c >= 'A' && c <= 'Z') ||
(c >= '0' && c <= '9')) {
[encoded appendFormat:@"%c", c];
} else {
[output appendFormat:@"%%%02X", thisChar];
[encoded appendFormat:@"%%%02X", c];
}
}
return output;

return encoded;
}

@end
Expand Down
12 changes: 6 additions & 6 deletions Pod/Classes/Networking/SKClient.m
Expand Up @@ -337,13 +337,11 @@ - (void)getAttestation:(NSString *)username password:(NSString *)password ts:(NS
NSDictionary *query = @{@"bytecode_proto": bytecodeProtobuf,
@"nonce": hashString,
@"apk_digest": SKAttestation.digest9_14_2};

request.URL = [NSURL URLWithString:SKAttestation.protobufPOSTURL];
request.HTTPBody = [[NSString queryStringWithParamsForAttestion:query] dataUsingEncoding:NSUTF8StringEncoding];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
request.HTTPBody = [[NSString queryStringWithParams:query URLEscapeValues:YES] dataUsingEncoding:NSUTF8StringEncoding];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:SKHeaders.contentType];

[[session dataTaskWithRequest:request completionHandler:^(NSData *data2, NSURLResponse *response2, NSError *error2) {

if (!error2 && [(NSHTTPURLResponse *)response2 statusCode] == 200) {
jsonError = nil;
json = [NSJSONSerialization JSONObjectWithData:data2 options:0 error:&jsonError];
Expand All @@ -361,7 +359,10 @@ - (void)getAttestation:(NSString *)username password:(NSString *)password ts:(NS
if (!error3 && [(NSHTTPURLResponse *)response3 statusCode] == 200) {
jsonError = nil;
json = [NSJSONSerialization JSONObjectWithData:data3 options:0 error:&jsonError];
callback(json[@"signedAttestation"], nil);
if (json)
callback(json[@"signedAttestation"], nil);
else
callback(nil, jsonError);
} else {
callback(nil, error3);
}
Expand All @@ -371,7 +372,6 @@ - (void)getAttestation:(NSString *)username password:(NSString *)password ts:(NS
callback(nil, jsonError);
}
} else {
// Error: 400, bad request (missing parameter according to Liam)
callback(nil, error2);
}
}] resume];
Expand Down
2 changes: 1 addition & 1 deletion SnapchatKit.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "SnapchatKit"
s.version = "0.3.3"
s.version = "0.3.4"
s.summary = "An Objective-C implementation of the unofficial Snapchat API."
s.homepage = "https://github.com/ThePantsThief/SnapchatKit"
s.license = 'MIT'
Expand Down

0 comments on commit 3ce3871

Please sign in to comment.