From 03941af6e92a6f5795b0e23dadb289d1d57b1970 Mon Sep 17 00:00:00 2001 From: Bryan Hales Date: Tue, 6 Nov 2012 22:38:14 -0700 Subject: [PATCH] Integrate Github Notifications API Integrated all options for the Notifications API: http://developer.github.com/v3/activity/notifications/ --- UAGithubEngine/UAGithubEngine.h | 18 ++++++ UAGithubEngine/UAGithubEngine.m | 67 +++++++++++++++++++++ UAGithubEngine/UAGithubEngineRequestTypes.h | 8 +++ 3 files changed, 93 insertions(+) diff --git a/UAGithubEngine/UAGithubEngine.h b/UAGithubEngine/UAGithubEngine.h index 0eeb808..a539a51 100644 --- a/UAGithubEngine/UAGithubEngine.h +++ b/UAGithubEngine/UAGithubEngine.h @@ -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; diff --git a/UAGithubEngine/UAGithubEngine.m b/UAGithubEngine/UAGithubEngine.m index ed9d993..14a5322 100644 --- a/UAGithubEngine/UAGithubEngine.m +++ b/UAGithubEngine/UAGithubEngine.m @@ -196,6 +196,8 @@ - (id)sendRequest:(NSString *)path requestType:(UAGithubRequestType)requestType case UAGithubOrganizationMembershipPublicizeRequest: case UAGithubTeamMemberAddRequest: case UAGithubTeamRepositoryManagershipAddRequest: + case UAGithubNotificationsMarkReadRequest: + case UAGithubNotificationThreadSubscriptionRequest: { [urlRequest setHTTPMethod:@"PUT"]; } @@ -215,6 +217,7 @@ - (id)sendRequest:(NSString *)path requestType:(UAGithubRequestType)requestType case UAGithubPullRequestCommentUpdateRequest: case UAGithubOrganizationUpdateRequest: case UAGithubTeamUpdateRequest: + case UAGithubNotificationsMarkThreadReadRequest: { [urlRequest setHTTPMethod:@"PATCH"]; } @@ -238,6 +241,7 @@ - (id)sendRequest:(NSString *)path requestType:(UAGithubRequestType)requestType case UAGithubTeamDeleteRequest: case UAGithubTeamMemberRemoveRequest: case UAGithubTeamRepositoryManagershipRemoveRequest: + case UAGithubNotificationDeleteSubscriptionRequest: { [urlRequest setHTTPMethod:@"DELETE"]; } @@ -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 diff --git a/UAGithubEngine/UAGithubEngineRequestTypes.h b/UAGithubEngine/UAGithubEngineRequestTypes.h index 1d74bf8..e7e58a8 100644 --- a/UAGithubEngine/UAGithubEngineRequestTypes.h +++ b/UAGithubEngine/UAGithubEngineRequestTypes.h @@ -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 @@ -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