Skip to content

Commit 7020f6b

Browse files
committed
Cleanup Notifications functionality
1 parent 6d7b176 commit 7020f6b

3 files changed

Lines changed: 29 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
- Add extension point for (preview) media types
1111
- Add missing webhook event types
1212
[#359](https://github.com/phadej/github/pull/359)
13+
- Add notifications endpoints
14+
[#324](https://github.com/phadej/github/pull/324)
1315
- Update dependencies
1416
[#364](https://github.com/phadej/github/pull/364)
1517
[#368](https://github.com/phadej/github/pull/368)

src/GitHub.hs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,16 @@ module GitHub (
1616
-- | See <https://developer.github.com/v3/activity/>
1717

1818
-- ** Events
19-
-- | See https://developer.github.com/v3/activity/events/#events
19+
-- | See <https://developer.github.com/v3/activity/events/>
2020
repositoryEventsR,
2121
userEventsR,
22+
23+
-- ** Notifications
24+
-- | See <https://developer.github.com/v3/activity/notifications/>
25+
getNotificationsR,
26+
markNotificationAsReadR,
27+
markAllNotificationsAsReadR,
28+
2229
-- ** Starring
2330
-- | See <https://developer.github.com/v3/activity/starring/>
2431
--
@@ -374,6 +381,7 @@ module GitHub (
374381

375382
import GitHub.Data
376383
import GitHub.Endpoints.Activity.Events
384+
import GitHub.Endpoints.Activity.Notifications
377385
import GitHub.Endpoints.Activity.Starring
378386
import GitHub.Endpoints.Activity.Watching
379387
import GitHub.Endpoints.Gists

src/GitHub/Endpoints/Activity/Notifications.hs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,31 @@ import Prelude ()
1515

1616
getNotifications :: Auth -> IO (Either Error (Vector Notification))
1717
getNotifications auth =
18-
executeRequest auth $ getNotificationsR FetchAll
18+
executeRequest auth $ getNotificationsR FetchAll
1919

20+
-- | List your notifications.
21+
-- See <https://developer.github.com/v3/activity/notifications/#list-your-notifications>
2022
getNotificationsR :: FetchCount -> Request 'RA (Vector Notification)
21-
getNotificationsR =
22-
pagedQuery ["notifications"] []
23+
getNotificationsR = pagedQuery ["notifications"] []
2324

2425
markNotificationAsRead :: Auth -> Id Notification -> IO (Either Error ())
25-
markNotificationAsRead auth notificationId =
26-
executeRequest auth $ markNotificationAsReadR notificationId
26+
markNotificationAsRead auth nid =
27+
executeRequest auth $ markNotificationAsReadR nid
2728

28-
markNotificationAsReadR :: Id Notification -> Request 'RW ()
29-
markNotificationAsReadR notificationId = SimpleQuery $
30-
Command Patch ["notifications", "threads", toPathPart notificationId]
31-
(encode ())
29+
-- | Mark a thread as read.
30+
-- See <https://developer.github.com/v3/activity/notifications/#mark-a-thread-as-read>
31+
markNotificationAsReadR :: Id Notification -> GenRequest 'MtUnit 'RW ()
32+
markNotificationAsReadR nid = Command
33+
Patch
34+
["notifications", "threads", toPathPart nid]
35+
(encode ())
3236

3337
markNotificationsAsRead :: Auth -> IO (Either Error ())
3438
markNotificationsAsRead auth =
3539
executeRequest auth markAllNotificationsAsReadR
3640

37-
markAllNotificationsAsReadR :: Request 'RW ()
38-
markAllNotificationsAsReadR = SimpleQuery $
39-
Command Put ["notifications"] $ encode emptyObject
41+
-- | Mark as read.
42+
-- See <https://developer.github.com/v3/activity/notifications/#mark-as-read>
43+
markAllNotificationsAsReadR :: GenRequest 'MtUnit 'RW ()
44+
markAllNotificationsAsReadR =
45+
Command Put ["notifications"] $ encode emptyObject

0 commit comments

Comments
 (0)