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
114 lines (99 loc) · 3.85 KB
/
Copy pathActivities.hs
File metadata and controls
114 lines (99 loc) · 3.85 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
110
111
112
113
114
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 :: !(Maybe 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
= ApprovalRequestedReason
| AssignReason
| AuthorReason
| CommentReason
| CiActivityReason
| InvitationReason
| ManualReason
| MemberFeatureRequestedReason
| MentionReason
| ReviewRequestedReason
| SecurityAlertReason
| SecurityAdvisoryCreditReason
| 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
"approval_requested" -> pure ApprovalRequestedReason
"assign" -> pure AssignReason
"author" -> pure AuthorReason
"comment" -> pure CommentReason
"ci_activity" -> pure CiActivityReason
"invitation" -> pure InvitationReason
"manual" -> pure ManualReason
"member_feature_requested" -> pure MemberFeatureRequestedReason
"mention" -> pure MentionReason
"review_requested" -> pure ReviewRequestedReason
"security_alert" -> pure SecurityAlertReason
"security_advisory_credit" -> pure SecurityAdvisoryCreditReason
"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"