Skip to content

Commit

Permalink
Integrate Github Notifications API
Browse files Browse the repository at this point in the history
Integrated all options for the Notifications API: http://developer.github.com/v3/activity/notifications/
  • Loading branch information
bryanhales committed Nov 7, 2012
1 parent 4ce7b0e commit 03941af
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
18 changes: 18 additions & 0 deletions UAGithubEngine/UAGithubEngine.h
Expand Up @@ -92,6 +92,24 @@ typedef void (^UAGithubEngineFailureBlock)(NSError *);
- (void)deleteComment:(NSInteger)commentNumber forRepository:(NSString *)repositoryPath success:(UAGithubEngineBooleanSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock;


#pragma mark
#pragma mark Activity
#pragma mark


#pragma mark Notifications

- (void)notificationsWithSuccess:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock;
- (void)notificationsForRepository:(NSString *)repositoryPath success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock;
- (void)notificationsForThread:(NSInteger)threadId success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock;
- (void)markNotificationsAsReadWithSuccess:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock;
- (void)markNotificationsAsReadInRepository:(NSString *)repositoryPath success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock;
- (void)markNotificationThreadAsRead:(NSInteger)threadId success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock;
- (void)currentUserIsSubscribedToNotificationThread:(NSInteger)threadId success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock;
- (void)subscribeCurrentUserToNotificationThread:(NSInteger)threadId success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock;
- (void)unsubscribeCurrentUserFromNotificationThread:(NSInteger)threadId success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock;


#pragma mark Events

- (void)eventsForIssue:(NSInteger)issueId forRepository:(NSString *)repositoryPath success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock;
Expand Down
67 changes: 67 additions & 0 deletions UAGithubEngine/UAGithubEngine.m
Expand Up @@ -196,6 +196,8 @@ - (id)sendRequest:(NSString *)path requestType:(UAGithubRequestType)requestType
case UAGithubOrganizationMembershipPublicizeRequest:
case UAGithubTeamMemberAddRequest:
case UAGithubTeamRepositoryManagershipAddRequest:
case UAGithubNotificationsMarkReadRequest:
case UAGithubNotificationThreadSubscriptionRequest:
{
[urlRequest setHTTPMethod:@"PUT"];
}
Expand All @@ -215,6 +217,7 @@ - (id)sendRequest:(NSString *)path requestType:(UAGithubRequestType)requestType
case UAGithubPullRequestCommentUpdateRequest:
case UAGithubOrganizationUpdateRequest:
case UAGithubTeamUpdateRequest:
case UAGithubNotificationsMarkThreadReadRequest:
{
[urlRequest setHTTPMethod:@"PATCH"];
}
Expand All @@ -238,6 +241,7 @@ - (id)sendRequest:(NSString *)path requestType:(UAGithubRequestType)requestType
case UAGithubTeamDeleteRequest:
case UAGithubTeamMemberRemoveRequest:
case UAGithubTeamRepositoryManagershipRemoveRequest:
case UAGithubNotificationDeleteSubscriptionRequest:
{
[urlRequest setHTTPMethod:@"DELETE"];
}
Expand Down Expand Up @@ -660,6 +664,69 @@ - (void)deleteComment:(NSInteger)commentNumber forRepository:(NSString *)reposit
}


#pragma mark
#pragma mark Activity
#pragma mark


#pragma mark Notifications

- (void)notificationsWithSuccess:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
{
[self invoke:^(id self){[self sendRequest:@"notifications" requestType:UAGithubNotificationsRequest responseType:UAGithubNotificationsResponse error:nil];} success:successBlock failure:failureBlock];
}

- (void)notificationsForRepository:(NSString *)repositoryPath success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
{
[self invoke:^(id self){[self sendRequest:[NSString stringWithFormat:@"repos/%@/notifications", repositoryPath] requestType:UAGithubNotificationsRequest responseType:UAGithubNotificationsResponse error:nil];} success:successBlock failure:failureBlock];
}

- (void)notificationsForThread:(NSInteger)threadId success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
{
[self invoke:^(id self){[self sendRequest:[NSString stringWithFormat:@"notifications/threads/%ld", threadId] requestType:UAGithubNotificationsRequest responseType:UAGithubNotificationThreadsResponse error:nil];} success:successBlock failure:failureBlock];
}

- (void)markNotificationsAsReadWithSuccess:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
{
NSDictionary *params = [@{ @"read" : @"true" } copy];

[self invoke:^(id self){[self sendRequest:@"notifications" requestType:UAGithubNotificationsMarkReadRequest responseType:UAGithubNoContentResponse withParameters:params error:nil];} success:successBlock failure:failureBlock];
}

- (void)markNotificationsAsReadInRepository:(NSString *)repositoryPath success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
{
NSDictionary *params = [@{ @"read" : @"true" } copy];

[self invoke:^(id self){[self sendRequest:[NSString stringWithFormat:@"repos/%@/notifications", repositoryPath] requestType:UAGithubNotificationsMarkReadRequest responseType:UAGithubNoContentResponse withParameters:params error:nil];} success:successBlock failure:failureBlock];
}

- (void)markNotificationThreadAsRead:(NSInteger)threadId success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
{
NSDictionary *params = [@{ @"read" : @"true" } copy];

[self invoke:^(id self){[self sendRequest:[NSString stringWithFormat:@"notifications/threads/%ld", threadId] requestType:UAGithubNotificationsMarkThreadReadRequest responseType:UAGithubNoContentResponse withParameters:params error:nil];} success:successBlock failure:failureBlock];
}

- (void)currentUserIsSubscribedToNotificationThread:(NSInteger)threadId success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
{
[self invoke:^(id self){[self sendRequest:[NSString stringWithFormat:@"notifications/threads/%ld/subscription", threadId] requestType:UAGithubNotificationsRequest responseType:UAGithubNotificationThreadSubscriptionResponse error:nil];} success:successBlock failure:failureBlock];
}

- (void)subscribeCurrentUserToNotificationThread:(NSInteger)threadId success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
{
NSDictionary *params = [@{ @"subscribed" : @"true" } copy];

[self invoke:^(id self){[self sendRequest:[NSString stringWithFormat:@"notifications/threads/%ld/subscription", threadId] requestType:UAGithubNotificationThreadSubscriptionRequest responseType:UAGithubNotificationThreadSubscriptionResponse withParameters:params error:nil];} success:successBlock failure:failureBlock];
}

- (void)unsubscribeCurrentUserFromNotificationThread:(NSInteger)threadId success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
{
NSDictionary *params = [@{ @"subscribed" : @"false" } copy];

[self invoke:^(id self){[self sendRequest:[NSString stringWithFormat:@"notifications/threads/%ld/subscription", threadId] requestType:UAGithubNotificationDeleteSubscriptionRequest responseType:UAGithubNotificationThreadSubscriptionResponse withParameters:params error:nil];} success:successBlock failure:failureBlock];
}


#pragma mark Events

- (void)eventsForIssue:(NSInteger)issueId forRepository:(NSString *)repositoryPath success:(UAGithubEngineSuccessBlock)successBlock failure:(UAGithubEngineFailureBlock)failureBlock
Expand Down
8 changes: 8 additions & 0 deletions UAGithubEngine/UAGithubEngineRequestTypes.h
Expand Up @@ -124,6 +124,11 @@ typedef enum UAGithubRequestType
UAGithubGistCommentCreateRequest, // Create a new gist comment
UAGithubGistCommentUpdateRequest, // Edit a gist comment
UAGithubGistCommentDeleteRequest, // Delete a gist comment
UAGithubNotificationsRequest, // List all notifications for the current user, grouped by repository
UAGithubNotificationsMarkReadRequest, // Mark a notification as read
UAGithubNotificationsMarkThreadReadRequest, // Mark a notification thread as read
UAGithubNotificationThreadSubscriptionRequest, // Subscribe or unsubscribe from a notification thread
UAGithubNotificationDeleteSubscriptionRequest, // Delete a notification thread subscription
UAGithubIssueEventsRequest, // Get one or more issue events
UAGithubIssueEventRequest, // Get exactly one issue event
UAGithubPullRequestsRequest, // Get one or more pull requests
Expand Down Expand Up @@ -228,6 +233,9 @@ typedef enum UAGithubResponseType
UAGithubPullRequestCommentsResponse, // One or more pull request comments
UAGithubPullRequestCommentResponse, // Exactly one pull request comment
UAGithubTagsResponse, // Tags in name-SHA pairs
UAGithubNotificationsResponse, // One or more notifications
UAGithubNotificationThreadsResponse, // One or more notification threads
UAGithubNotificationThreadSubscriptionResponse, // Exactly one notification thread subscription
UAGithubEventsResponse, // One or more events of unspecified type
UAGithubOrganizationsResponse, // One or more organizations
UAGithubOrganizationResponse, // Exactly one organization
Expand Down

0 comments on commit 03941af

Please sign in to comment.