forked from haskell-github/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActivities.hs
More file actions
110 lines (94 loc) · 3.49 KB
/
Activities.hs
File metadata and controls
110 lines (94 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
-----------------------------------------------------------------------------
-- |
-- License : BSD-3-Clause
-- Maintainer : Oleg Grenrus <oleg.grenrus@iki.fi>
--
module GitHub.Data.Activities where
import GitHub.Data.Id (Id, mkId)
import GitHub.Data.Repos (Repo, RepoRef)
import GitHub.Data.URL (URL)
import GitHub.Internal.Prelude
import Prelude ()
import qualified Data.Text as T
data RepoStarred = RepoStarred
{ repoStarredStarredAt :: !UTCTime
, repoStarredRepo :: !Repo
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData RepoStarred where rnf = genericRnf
instance Binary RepoStarred
-- JSON Instances
instance FromJSON RepoStarred where
parseJSON = withObject "RepoStarred" $ \o -> RepoStarred
<$> o .: "starred_at"
<*> o .: "repo"
data Subject = Subject
{ subjectTitle :: !Text
, subjectURL :: !URL
, subjectLatestCommentURL :: !(Maybe URL)
-- https://developer.github.com/v3/activity/notifications/ doesn't indicate
-- what the possible values for this field are.
-- TODO: Make an ADT for this.
, subjectType :: !Text
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData Subject where rnf = genericRnf
instance Binary Subject
instance FromJSON Subject where
parseJSON = withObject "Subject" $ \o -> Subject
<$> o .: "title"
<*> o .: "url"
<*> o .:? "latest_comment_url"
<*> o .: "type"
data NotificationReason
= AssignReason
| AuthorReason
| CommentReason
| InvitationReason
| ManualReason
| MentionReason
| ReviewRequestedReason
| StateChangeReason
| SubscribedReason
| TeamMentionReason
deriving (Show, Data, Enum, Bounded, Typeable, Eq, Ord, Generic)
instance NFData NotificationReason where rnf = genericRnf
instance Binary NotificationReason
instance FromJSON NotificationReason where
parseJSON = withText "NotificationReason" $ \t -> case T.toLower t of
"assign" -> pure AssignReason
"author" -> pure AuthorReason
"comment" -> pure CommentReason
"invitation" -> pure InvitationReason
"manual" -> pure ManualReason
"mention" -> pure MentionReason
"review_requested" -> pure ReviewRequestedReason
"state_change" -> pure StateChangeReason
"subscribed" -> pure SubscribedReason
"team_mention" -> pure TeamMentionReason
_ -> fail $ "Unknown NotificationReason " ++ show t
data Notification = Notification
-- XXX: The notification id field type IS in fact string. Not sure why gh
-- chose to do this when all the other ids are Numbers...
{ notificationId :: !(Id Notification)
, notificationRepo :: !RepoRef
, notificationSubject :: !Subject
, notificationReason :: !NotificationReason
, notificationUnread :: !Bool
, notificationUpdatedAt :: !(Maybe UTCTime)
, notificationLastReadAt :: !(Maybe UTCTime)
, notificationUrl :: !URL
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData Notification where rnf = genericRnf
instance Binary Notification
instance FromJSON Notification where
parseJSON = withObject "Notification" $ \o -> Notification
<$> (mkId undefined . read <$> o .: "id")
<*> o .: "repository"
<*> o .: "subject"
<*> o .: "reason"
<*> o .: "unread"
<*> o .: "updated_at"
<*> o .: "last_read_at"
<*> o .: "url"