Permalink
Browse files

Merge pull request #27 from bryanhales/master

Integrate Github Notifications API
  • Loading branch information...
2 parents 4ce7b0e + 03941af commit 877e0c8eab0d1fb604d19cc121a8f6374f367a4c @owainhunt committed Jan 7, 2013
Showing with 93 additions and 0 deletions.
  1. +18 −0 UAGithubEngine/UAGithubEngine.h
  2. +67 −0 UAGithubEngine/UAGithubEngine.m
  3. +8 −0 UAGithubEngine/UAGithubEngineRequestTypes.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;
@@ -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
@@ -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

0 comments on commit 877e0c8

Please sign in to comment.