This repository has been archived by the owner on May 19, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b80d45
commit 06ffbb5
Showing
41 changed files
with
1,135 additions
and
103 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,60 @@ | ||
#import "GHResource.h" | ||
#import "GHRepository.h" | ||
#import "GHNotification.h" | ||
#import "GHPullRequest.h" | ||
#import "GHIssue.h" | ||
#import "GHCommit.h" | ||
#import "NSDictionary+Extensions.h" | ||
|
||
|
||
@interface GHNotification () | ||
@property(nonatomic,readwrite)BOOL read; | ||
@end | ||
|
||
|
||
@implementation GHNotification | ||
|
||
- (id)initWithId:(NSString *)notificationId { | ||
- (id)initWithDict:(NSDictionary *)dict { | ||
self = [super init]; | ||
if (self) { | ||
self.notificationId = notificationId; | ||
self.read = NO; | ||
[self setValues:dict]; | ||
} | ||
return self; | ||
} | ||
|
||
- (void)markAsRead { | ||
self.read = YES; | ||
} | ||
|
||
#pragma mark Loading | ||
|
||
- (void)setValues:(id)dict { | ||
NSDictionary *repoDict = [dict safeDictForKey:@"repository"]; | ||
NSString *owner = [repoDict safeStringForKeyPath:@"owner.login"]; | ||
NSString *name = [repoDict safeStringForKey:@"name"]; | ||
NSURL *subjectURL = [dict safeURLForKeyPath:@"subject.url"]; | ||
self.notificationId = [dict safeStringForKey:@"id"]; | ||
self.updatedAtDate = [dict safeDateForKey:@"updated_at"]; | ||
self.lastReadAtDate = [dict safeDateForKey:@"last_read_at"]; | ||
self.isUnread = [dict safeBoolForKey:@"unread"]; | ||
self.read = [dict safeBoolForKey:@"unread"] ? ![dict safeBoolForKey:@"unread"] : NO; | ||
self.title = [dict safeStringForKeyPath:@"subject.title"]; | ||
self.subjectType = [dict safeStringForKeyPath:@"subject.type"]; | ||
self.repository = [[GHRepository alloc] initWithOwner:owner andName:name]; | ||
[self.repository setValues:repoDict]; | ||
if ([self.subjectType isEqualToString:@"PullRequest"]) { | ||
self.subject = [[GHPullRequest alloc] initWithRepository:self.repository]; | ||
NSInteger num = [[subjectURL lastPathComponent] intValue]; | ||
[(GHPullRequest *)self.subject setNum:num]; | ||
} else if ([self.subjectType isEqualToString:@"Issue"]) { | ||
self.subject = [[GHIssue alloc] initWithRepository:self.repository]; | ||
NSInteger num = [[subjectURL lastPathComponent] intValue]; | ||
[(GHIssue *)self.subject setNum:num]; | ||
} else if ([self.subjectType isEqualToString:@"Commit"]) { | ||
NSString *sha = [subjectURL lastPathComponent]; | ||
self.subject = [[GHCommit alloc] initWithRepository:self.repository andCommitID:sha]; | ||
} | ||
if (self.subject) self.subject.resourcePath = subjectURL.path; | ||
} | ||
|
||
@end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,32 @@ | ||
#import "AFHTTPRequestOperation.h" | ||
#import "GHNotifications.h" | ||
#import "GHNotification.h" | ||
#import "GHRepository.h" | ||
#import "NSDictionary+Extensions.h" | ||
|
||
|
||
@implementation GHNotifications | ||
|
||
- (void)setValues:(id)values { | ||
self.items = [NSMutableArray array]; | ||
self.byRepository = [NSMutableDictionary dictionary]; | ||
for (id dict in values) { | ||
GHNotification *resource = [[GHNotification alloc] initWithId:[dict safeStringForKey:@"id"]]; | ||
[resource setValues:dict]; | ||
[self addObject:resource]; | ||
GHNotification *notification = [[GHNotification alloc] initWithDict:dict]; | ||
if ([notification.lastReadAtDate compare:self.lastUpdate] != NSOrderedDescending) { | ||
[notification markAsRead]; | ||
} | ||
[self addObject:notification]; | ||
if (!self.byRepository[notification.repository.repoId]) { | ||
self.byRepository[notification.repository.repoId] = [NSMutableArray array]; | ||
} | ||
[self.byRepository[notification.repository.repoId] addObject:notification]; | ||
} | ||
self.lastUpdate = [NSDate date]; | ||
} | ||
|
||
- (void)setHeaderValues:(NSDictionary *)values { | ||
[super setHeaderValues:values]; | ||
self.pollInterval = [values safeIntegerForKey:@"X-Poll-Interval"]; | ||
} | ||
|
||
@end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.