-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMModelCollectionPaginatingFetcher.m
47 lines (37 loc) · 1.37 KB
/
MModelCollectionPaginatingFetcher.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//
// MModelCollectionPaginatingFetcher.m
// Endorsee
//
// Created by Ben Gotow on 3/30/14.
// Copyright (c) 2014 Foundry376. All rights reserved.
//
#import "MModelCollectionPaginatingFetcher.h"
#import "MAPIClient.h"
@implementation MModelCollectionPaginatingFetcher
- (void)fetch
{
_fetched = 0;
_fetchedFewerThanRequested = NO;
[[MAPIClient shared] arrayAtPath:[self.delegate resourcePath] userTriggered:NO success:^(id responseObject) {
_fetched += [responseObject count];
_fetchedFewerThanRequested = ([responseObject count] < _pageSize);
[self.delegate modelsFetched: responseObject replaceExistingContents:YES];
} failure:^(NSError *err) {
[self.delegate modelsFetchFailed];
}];
}
- (void)fetchMore
{
if (_fetchedFewerThanRequested)
return;
int page = floorf(_fetched / _pageSize) + 1;
NSString * path = [[self.delegate resourcePath] stringByAppendingFormat:@"?page=%d&count=%d", page, _pageSize];
[[MAPIClient shared] arrayAtPath:path userTriggered:NO success:^(id responseObject) {
_fetched += [responseObject count];
_fetchedFewerThanRequested = ([responseObject count] < _pageSize);
[self.delegate modelsFetched: responseObject replaceExistingContents:NO];
} failure:^(NSError *err) {
[self.delegate modelsFetchFailed];
}];
}
@end