Skip to content

Commit

Permalink
closes #86
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewShmig committed Mar 17, 2014
1 parent 292a21f commit 1d65fa8
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
18 changes: 14 additions & 4 deletions Project/Project/ASAAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
#import "ASAViewController.h"


//static NSString *const kVKAppID = @"3974432";
static NSString *const kVKAppID = @"3541027";
static NSString *const kVKAppID = @"4249589";
static NSString *const kVKPermissionsArray = @"photos,friends,wall,audio,video,docs,notes,pages,status,groups,messages";


Expand Down Expand Up @@ -103,9 +102,15 @@ - (void)VKRequest:(VKRequest *)request
NSLog(@"request: %@", request);
NSLog(@"response: %@", response);

[[VKUser currentUser] logout];
VKRequestManager *manager = [[VKRequestManager alloc]
initWithDelegate:self
user:[VKUser currentUser]];

NSLog(@"users: %@", @([[VKStorage sharedStorage] count]));
for(int i=0; i<100; i++) {
[manager wallPost:@{
@"message": @"Testing Vkontakte iOS SDK by Andrew Shmig"
}];
}
}

- (void) VKRequest:(VKRequest *)request
Expand All @@ -122,6 +127,11 @@ - (void)VKRequest:(VKRequest *)request
NSLog(@"%s", __FUNCTION__);
NSLog(@"captchaSid: %@", captchaSid);
NSLog(@"captchaImage: %@", captchaImage);

[request appendCaptchaSid:@"captcha sid"
captchaKey:@"captcha key"];

[request start];
}

- (void) VKRequest:(VKRequest *)request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,14 @@ VKRequestDelegate protocol)
*/
- (void)cancel;

/**
@name Captcha
*/
/** Appends captcha options
*/
- (void)appendCaptchaSid:(NSString *)captchaSid
captchaKey:(NSString *)captchaKey;

/**
@name Appending files
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ - (void)start
VKStorageItem *item = [[VKStorage sharedStorage]
storageItemForUserID:currentUserID];

NSData *cachedResponseData = [item.cache cacheForURL:[self removeAccessTokenFromURL:_request.URL]
NSData *cachedResponseData = [item.cache cacheForURL:[self removeTemporaryRequestOptions:_request.URL]
offlineMode:_offlineMode];
if (nil != cachedResponseData) {
_receivedData = [cachedResponseData mutableCopy];
Expand Down Expand Up @@ -366,6 +366,21 @@ - (void)appendVideoFile:(NSData *)file
field:field];
}

#pragma mark - Captcha

- (void)appendCaptchaSid:(NSString *)captchaSid
captchaKey:(NSString *)captchaKey
{
NSString *urlAsString = [_request.URL absoluteString];
NSString *urlAsStringWithCaptcha = [NSString stringWithFormat:@"%@&captcha_sid=%@&captcha_key=%@",
urlAsString,
[captchaSid encodeURL],
[captchaKey encodeURL]];

NSURL *URLWithCaptcha = [NSURL URLWithString:urlAsStringWithCaptcha];
_request.URL = URLWithCaptcha;
}

#pragma mark - Overridden methods

- (NSString *)description
Expand Down Expand Up @@ -544,7 +559,7 @@ - (void)connectionDidFinishLoading:(NSURLConnection *)connection
storageItemForUserID:currentUserID];

[item.cache addCache:_receivedData
forURL:[self removeAccessTokenFromURL:_request.URL]
forURL:[self removeTemporaryRequestOptions:_request.URL]
liveTime:self.cacheLiveTime];
}

Expand All @@ -569,7 +584,7 @@ - (void)connection:(NSURLConnection *)connection

#pragma mark - private methods

- (NSURL *)removeAccessTokenFromURL:(NSURL *)url
- (NSURL *)removeTemporaryRequestOptions:(NSURL *)url
{
VK_LOG(@"%@", @{
@"url" : url
Expand All @@ -582,7 +597,7 @@ - (NSURL *)removeAccessTokenFromURL:(NSURL *)url
NSString *query = [url query];
NSArray *params = [query componentsSeparatedByString:@"&"];

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (SELF BEGINSWITH \"access_token\")"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"NOT (SELF BEGINSWITH \"access_token\" OR SELF BEGINSWITH \"captcha_sid\" OR SELF BEGINSWITH \"captcha_key\")"];
NSArray *newParams = [params filteredArrayUsingPredicate:predicate];

NSString *part1 = [[url absoluteString]
Expand Down

0 comments on commit 1d65fa8

Please sign in to comment.