-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSyncStack.m
More file actions
64 lines (60 loc) · 2.46 KB
/
SyncStack.m
File metadata and controls
64 lines (60 loc) · 2.46 KB
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//
// SyncStack.m
// ThirdPartyExtension
//
// Created by Uttam Ukkoji on 02/07/18.
// Copyright © 2018 Contentstack. All rights reserved.
//
#import "SyncStack.h"
#import "CSIOInternalHeaders.h"
@implementation SyncStack
-(instancetype)initWithParmas:(NSDictionary*) parmas {
self = [super init];
if (self) {
self.params = parmas;
if ([[self.params objectForKey:@"sync_token"] isKindOfClass:[NSString class]]) {
self.syncToken = [self.params objectForKey:@"sync_token"];
}
self.items = [NSArray array];
}
return self;
}
-(void)parseSyncResult:(NSDictionary *)dictionary {
if (![dictionary isKindOfClass:[NSNull class]]) {
self.syncToken = nil;
self.paginationToken = nil;
self.hasMorePages = false;
if ([dictionary objectForKey:@"sync_token"]) {
self.syncToken = [dictionary objectForKey:@"sync_token"];
}
if ([dictionary objectForKey:@"pagination_token"]) {
self.hasMorePages = true;
self.paginationToken = [dictionary objectForKey:@"pagination_token"];
}
if ([dictionary objectForKey:@"total_count"]) {
self.totalCount = [[dictionary objectForKey:@"total_count"] unsignedIntValue];
}
if ([dictionary objectForKey:@"skip"] != nil && [[dictionary objectForKey:@"skip"] isKindOfClass:[NSNumber class]]){
self.skip = [[dictionary objectForKey:@"skip"] unsignedIntValue];
}
if ([dictionary objectForKey:@"limit"] != nil && [[dictionary objectForKey:@"limit"] isKindOfClass:[NSNumber class]]){
self.limit = [[dictionary objectForKey:@"limit"] unsignedIntValue];
}
if ([dictionary objectForKey:@"items"] && [[dictionary objectForKey:@"items"] isKindOfClass:[NSArray class]]) {
self.items = [dictionary objectForKey:@"items"];//[[self.items mutableCopy] arrayByAddingObjectsFromArray:[dictionary objectForKey:@"items"]];
}
}
}
-(NSDictionary*)getParameters {
NSMutableDictionary *syncParams = [NSMutableDictionary dictionary];
if (self.syncToken != nil) {
[syncParams setValue:self.syncToken forKey:@"sync_token"];
}else if (self.paginationToken != nil) {
[syncParams setValue:self.paginationToken forKey:@"pagination_token"];
}else {
syncParams = [NSMutableDictionary dictionaryWithDictionary:self.params];
[syncParams setValue:@"true" forKey:@"init"];
}
return syncParams;
}
@end