-
Notifications
You must be signed in to change notification settings - Fork 6
/
TVDbUpdater.m
94 lines (71 loc) · 2.45 KB
/
TVDbUpdater.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// TVDbUpdater.m
// iTVDb
//
// Created by Kevin Tuhumury on 7/13/12.
// Copyright (c) 2012 Thmry. All rights reserved.
//
#import "TVDbUpdater.h"
#import "TVDbClient.h"
#import "XMLReader.h"
@interface TVDbUpdater()
- (NSString *)requestTimeUrl;
- (NSString *)requestUpdatesUrlSince:(NSString *)timestamp;
- (NSString *)requestShowUpdatesUrlSince:(NSString *)timestamp;
- (NSString *)requestEpisodeUpdatesUrlSince:(NSString *)timestamp;
- (NSString *)requestUpdatesUrlSince:(NSString *)timestamp withType:(NSString *)type;
@end
@implementation TVDbUpdater
@synthesize lastUpdatedAt;
# pragma mark - singleton
+ (TVDbUpdater *)sharedInstance
{
static dispatch_once_t onlyOnceToken = 0;
__strong static TVDbUpdater *sharedObject = nil;
dispatch_once(&onlyOnceToken, ^{
sharedObject = [[TVDbUpdater alloc] init];
});
return sharedObject;
}
# pragma mark - public methods
- (NSDictionary *)updates
{
return [[TVDbClient sharedInstance] requestURL:[self requestUpdatesUrlSince:[self lastUpdatedAt]]];
}
- (NSDictionary *)showUpdates
{
NSDictionary *showUpdates = [[TVDbClient sharedInstance] requestURL:[self requestShowUpdatesUrlSince:[self lastUpdatedAt]]];
return [showUpdates retrieveForPath:@"Items.Series"];
}
- (NSDictionary *)episodeUpdates
{
NSDictionary *episodeUpdates = [[TVDbClient sharedInstance] requestURL:[self requestEpisodeUpdatesUrlSince:[self lastUpdatedAt]]];
return [episodeUpdates retrieveForPath:@"Items.Episode"];
}
- (void)updateLastUpdatedAtTimestamp
{
NSDictionary *dictionary = [[TVDbClient sharedInstance] requestURL:[self requestTimeUrl]];
self.lastUpdatedAt = [dictionary retrieveForPath:@"Items.Time"];
}
# pragma mark - internal methods
- (NSString *)requestTimeUrl
{
return [NSString stringWithFormat:@"/Updates.php?type=none"];
}
- (NSString *)requestUpdatesUrlSince:(NSString *)timestamp
{
return [self requestUpdatesUrlSince:timestamp withType:@"all"];
}
- (NSString *)requestShowUpdatesUrlSince:(NSString *)timestamp
{
return [self requestUpdatesUrlSince:timestamp withType:@"series"];
}
- (NSString *)requestEpisodeUpdatesUrlSince:(NSString *)timestamp
{
return [self requestUpdatesUrlSince:timestamp withType:@"episode"];
}
- (NSString *)requestUpdatesUrlSince:(NSString *)timestamp withType:(NSString *)type
{
return [NSString stringWithFormat:@"/Updates.php?type=%@&time=%@", type, timestamp];
}
@end