Skip to content

Commit

Permalink
closes #106
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewShmig committed Jul 29, 2014
1 parent 809b4a3 commit cd78778
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 126 deletions.
23 changes: 16 additions & 7 deletions Project/Project/ASAAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ - (BOOL) application:(UIApplication *)application
bounds]];
self.webView.hidden = NO;

[[VKConnector sharedInstance] startWithAppID:kVKAppID
permissons:[kVKPermissionsArray componentsSeparatedByString:@","]
webView:self.webView
delegate:self];
// [[VKConnector sharedInstance] startWithAppID:kVKAppID
// permissons:[kVKPermissionsArray componentsSeparatedByString:@","]
// webView:self.webView
// delegate:self];
_rm = [[VKRequestManager alloc] initWithDelegate:self];
_rm.startAllRequestsImmediately = NO;

VKRequest *r = [_rm info:@{@"user_ids": @"christian.burns"}];
r.cacheLiveTime = VKCacheLiveTimeOneDay;
[r start];

// Override point for customization after application launch.
self.viewController = [[ASAViewController alloc]
Expand All @@ -52,9 +58,12 @@ - (void) connector:(VKConnector *)connector

NSLog(@"Access token: %@", accessToken);

_rm = [[VKRequestManager alloc] initWithDelegate:self];
[_rm info:@{@"user_ids": @"christian.burns"}];

// _rm = [[VKRequestManager alloc] initWithDelegate:self];
// _rm.startAllRequestsImmediately = NO;
//
// VKRequest *r = [_rm info:@{@"user_ids": @"christian.burns"}];
// r.cacheLiveTime = VKCacheLiveTimeOneDay;
// [r start];
}

- (void)request:(VKRequest *)request responseError:(NSError *)error
Expand Down
39 changes: 19 additions & 20 deletions Project/Vkontakte-iOS-SDK-LV/VKRequestManager/VKRequest/VKRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -195,30 +195,29 @@ - (void)start
return;

// перед тем как начать выполнение запроса проверим кэш
if (self.requestManager.user) {
NSUInteger currentUserID = self.requestManager.user.accessToken.userID;
VKStorageItem *item = [[VKStorage sharedStorage]
storageItemForUserID:currentUserID];
NSUInteger currentUserID = self.requestManager.user.accessToken.userID;
VKStorageItem *item = [[VKStorage sharedStorage]
storageItemForUserID:currentUserID];

NSData *cachedResponseData = [item.cache cacheForURL:[self uniqueRequestURL]
offlineMode:self.offlineMode];
if (nil != cachedResponseData) {
_receivedData = [cachedResponseData mutableCopy];

NSData *cachedResponseData = [item.cache cacheForURL:[self uniqueRequestURL]
offlineMode:self.offlineMode];
if (nil != cachedResponseData) {
_receivedData = [cachedResponseData mutableCopy];

// данные взяты из кэша
_isDataFromCache = YES;

[self connectionDidFinishLoading:_connection];

// нет надобности следить за состоянием "обновляющего" запроса
// только при удачном исходе данные в кэше будут обновлены
self.delegate = nil;
}
// данные взяты из кэша
_isDataFromCache = YES;

// добавляем актуальный пользовательский токен доступа
self.HTTPQueryParameters[@"access_token"] = item.accessToken.token;
[self connectionDidFinishLoading:_connection];

// нет надобности следить за состоянием "обновляющего" запроса
// только при удачном исходе данные в кэше будут обновлены
self.delegate = nil;
}

// добавляем актуальный пользовательский токен доступа
if (!item.accessToken.token.isEmpty)
self.HTTPQueryParameters[@"access_token"] = item.accessToken.token;

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

// HTTP метод отправки запроса
Expand Down
13 changes: 13 additions & 0 deletions Project/Vkontakte-iOS-SDK-LV/VKRequestManager/VKRequestManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@


@implementation VKRequestManager
{
VKUser *_user;
}

#pragma mark - Init

Expand All @@ -53,6 +56,16 @@ - (instancetype)initWithDelegate:(id <VKRequestDelegate>)delegate
user:nil];
}

#pragma mark - Getters & Setters

- (VKUser *)user {
return _user ? _user : [VKUser ghostUser];
}

- (void)setUser:(VKUser *)user {
_user = user;
}

#pragma mark - Users

- (VKRequest *)info
Expand Down
8 changes: 8 additions & 0 deletions Project/Vkontakte-iOS-SDK-LV/VKUser/VKUser.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ Second example:
*/
+ (instancetype)currentUser;

/** Non-authorized user, guest.
This "ghost user" is used to help caching metchanism to work with non-authorized
requests (requests that don't have access_token)
*/
+ (instancetype)ghostUser;

/** Activates user with passed unique user identifier
If there is no such user then NO will be returned, otherwise - YES.
Expand Down
Loading

0 comments on commit cd78778

Please sign in to comment.