This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)importTweets:(NSArray *)tweets | |
{ | |
for (NSDictionary *tweetDictionary in tweets) { | |
[TGRTweet importFromDictionary:tweetDictionary inManagedObjectContext:self.managedObjectContext]; | |
} | |
NSError *error = nil; | |
BOOL succeeded = [self.managedObjectContext save:&error]; | |
if (!succeeded) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (SLRequest *)requestForOldTweets | |
{ | |
TGRTweet *firstTweet = [TGRTweet firstTweetInManagedObjectContext:self.managedObjectContext]; | |
if (!firstTweet) { | |
NSLog(@"requestForOldTweets shouldn't be called when the cache is empty"); | |
return nil; | |
} | |
NSNumber *maxIdentifier = [NSNumber numberWithLongLong:[firstTweet.identifier longLongValue] - 1]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (SLRequest *)requestForNewTweets | |
{ | |
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; | |
parameters[@"include_rts"] = @"true"; | |
TGRTweet *lastTweet = [TGRTweet lastTweetInManagedObjectContext:self.managedObjectContext]; | |
if (lastTweet) { | |
parameters[@"since_id"] = [lastTweet.identifier stringValue]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static NSString * const kHomeTimelineURL = @"https://api.twitter.com/1.1/statuses/home_timeline.json"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSDate *)dateFromTwitterDate:(NSString *)dateString | |
{ | |
static dispatch_once_t onceToken; | |
static NSDateFormatter *dateFormatter; | |
dispatch_once(&onceToken, ^{ | |
dateFormatter = [[NSDateFormatter alloc] init]; | |
[dateFormatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]]; | |
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; | |
[dateFormatter setDateFormat:@"eee MMM dd HH:mm:ss ZZZZ yyyy"]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (void)importValuesFromDictionary:(NSDictionary *)dictionary | |
{ | |
self.identifier = dictionary[@"id"]; | |
NSDictionary *retweetedStatus = dictionary[@"retweeted_status"]; | |
NSString *dateString = nil; | |
NSDictionary *userDictionary = nil; | |
NSDictionary *retweetedByDictionary = nil; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (id)lastTweetInManagedObjectContext:(NSManagedObjectContext *)context | |
{ | |
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"identifier" | |
ascending:NO]; | |
NSFetchRequest *fetchRequest = [self fetchRequest]; | |
[fetchRequest setSortDescriptors:@[sortDescriptor]]; | |
[fetchRequest setFetchLimit:1]; | |
return [[context executeFetchRequest:fetchRequest error:NULL] lastObject]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (id)firstTweetInManagedObjectContext:(NSManagedObjectContext *)context | |
{ | |
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"identifier" | |
ascending:YES]; | |
NSFetchRequest *fetchRequest = [self fetchRequest]; | |
[fetchRequest setSortDescriptors:@[sortDescriptor]]; | |
[fetchRequest setFetchLimit:1]; | |
return [[context executeFetchRequest:fetchRequest error:NULL] lastObject]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSFetchRequest *)fetchRequestForAllTweets | |
{ | |
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"identifier" | |
ascending:NO]; | |
NSFetchRequest *fetchRequest = [self fetchRequest]; | |
[fetchRequest setSortDescriptors:@[sortDescriptor]]; | |
return fetchRequest; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (NSFetchRequest *)fetchRequestForAllTweets; | |
+ (id)firstTweetInManagedObjectContext:(NSManagedObjectContext *)context; | |
+ (id)lastTweetInManagedObjectContext:(NSManagedObjectContext *)context; |