Skip to content

Commit

Permalink
Adding quick hack to notify users of new release on github.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Paul Searles committed Jan 28, 2014
1 parent e3afaae commit 4b9a98e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 2 additions & 0 deletions objective-octocat-notifications/AFGithubClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

+ (AFGithubClient *)sharedClient;

- (void)checkForNewRelease;

- (void)getNotifications;

- (void)setTimerWithPoll:(float) poll;
Expand Down
25 changes: 24 additions & 1 deletion objective-octocat-notifications/AFGithubClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
static NSString * const kAFGithubBaseURLString = @"https://api.github.com/";
static NSString * const kOAuthBaseUrl = @"https://github.com/login/oauth/";
static float const kPollInterval = 60.0;
static NSString * const kAppVersion = @"0.1.0";

@implementation AFGithubClient

Expand All @@ -25,6 +26,7 @@ + (void)startNotifications {
}

[[AFGithubClient sharedClient] setDefaultHeader:@"Authorization" value:[[NSString alloc] initWithFormat:@"token %@", token]];
[[AFGithubClient sharedClient] checkForNewRelease];
[[AFGithubClient sharedClient] getNotifications];
}

Expand All @@ -51,6 +53,28 @@ - (id)initWithBaseURL:(NSURL *)url {
return self;
}

- (void)checkForNewRelease
{
NSString *tags = @"repos/squaresurf/objective-octocat-notifications/tags";

[[AFGithubClient sharedClient] getPath:tags parameters:@{} success:^(AFHTTPRequestOperation *operation, id response) {
if ([response count] > 0) {
NSString *latestVersion = response[0][@"name"];
if (![kAppVersion isEqualToString:latestVersion]) {
NSString *latestUrl = [NSString stringWithFormat:@"https://github.com/squaresurf/objective-octocat-notifications/releases/%@", latestVersion];

NSUserNotification *macNotification = [[NSUserNotification alloc] init];
macNotification.title = @"New Release!";
macNotification.informativeText = @"Click here to download the latest release of Objective Octocat Notifications.";
macNotification.userInfo = @{@"url": latestUrl};
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:macNotification];
}
}
} failure:^(AFHTTPRequestOperation *operation, id json) {
NSLog(@"error: %@", json);
}];
}

- (void)getNotifications
{
AppDelegate *appDelegate = [NSApp delegate];
Expand Down Expand Up @@ -95,7 +119,6 @@ - (void)getNotifications
NSLog(@"error: %@", json);
[self setTimerWithPoll:kPollInterval];
}];

}

- (void)setTimerWithPoll:(float)poll {
Expand Down

0 comments on commit 4b9a98e

Please sign in to comment.