55--
66module GitHub.Data.Activities where
77
8- import GitHub.Data.Repos (Repo )
8+ import GitHub.Data.Id (Id , mkId )
9+ import GitHub.Data.Repos (Repo , RepoRef )
10+ import GitHub.Data.URL (URL )
911import GitHub.Internal.Prelude
12+
1013import Prelude ()
1114
1215data RepoStarred = RepoStarred
@@ -24,3 +27,82 @@ instance FromJSON RepoStarred where
2427 <$> o .: " starred_at"
2528 <*> o .: " repo"
2629
30+ data Subject = Subject
31+ { subjectTitle :: ! Text
32+ , subjectURL :: ! URL
33+ , subjectLatestCommentURL :: ! (Maybe URL )
34+ -- https://developer.github.com/v3/activity/notifications/ doesn't indicate
35+ -- what the possible values for this field are.
36+ -- TODO: Make an ADT for this.
37+ , subjectType :: ! Text
38+ }
39+ deriving (Show , Data , Typeable , Eq , Ord , Generic )
40+
41+ instance NFData Subject where rnf = genericRnf
42+ instance Binary Subject
43+
44+ instance FromJSON Subject where
45+ parseJSON = withObject " Subject" $ \ o -> Subject
46+ <$> o .: " title"
47+ <*> o .: " url"
48+ <*> o .:? " latest_comment_url"
49+ <*> o .: " type"
50+
51+ data NotificationReason
52+ = AssignReason
53+ | AuthorReason
54+ | CommentReason
55+ | InvitationReason
56+ | ManualReason
57+ | MentionReason
58+ | ReviewRequestedReason
59+ | StateChangeReason
60+ | SubscribedReason
61+ | TeamMentionReason
62+ deriving (Show , Data , Enum , Bounded , Typeable , Eq , Ord , Generic )
63+
64+ instance NFData NotificationReason where rnf = genericRnf
65+ instance Binary NotificationReason
66+
67+ instance FromJSON NotificationReason where
68+ parseJSON = withText " NotificationReason" $ \ t -> case t of
69+ " assign" -> pure AssignReason
70+ " author" -> pure AuthorReason
71+ " comment" -> pure CommentReason
72+ " invitation" -> pure InvitationReason
73+ " manual" -> pure ManualReason
74+ " mention" -> pure MentionReason
75+ " review_requested" -> pure ReviewRequestedReason
76+ " state_change" -> pure StateChangeReason
77+ " subscribed" -> pure SubscribedReason
78+ " team_mention" -> pure TeamMentionReason
79+ _ -> fail $ " Unknown NotificationReason " ++ show t
80+
81+ data Notification = Notification
82+ -- XXX: The notification id field type IS in fact string. Not sure why gh
83+ -- chose to do this when all the other ids are Numbers...
84+ { notificationId :: ! (Id Notification )
85+ , notificationRepo :: ! RepoRef
86+ , notificationSubject :: ! Subject
87+ , notificationReason :: ! NotificationReason
88+ , notificationUnread :: ! Bool
89+ , notificationUpdatedAt :: ! (Maybe UTCTime )
90+ , notificationLastReadAt :: ! (Maybe UTCTime )
91+ , notificationUrl :: ! URL
92+ }
93+ deriving (Show , Data , Typeable , Eq , Ord , Generic )
94+
95+ instance NFData Notification where rnf = genericRnf
96+ instance Binary Notification
97+
98+ instance FromJSON Notification where
99+ parseJSON = withObject " Notification" $ \ o -> Notification
100+ <$> (mkId undefined . read <$> o .: " id" )
101+ <*> o .: " repository"
102+ <*> o .: " subject"
103+ <*> o .: " reason"
104+ <*> o .: " unread"
105+ <*> o .: " updated_at"
106+ <*> o .: " last_read_at"
107+ <*> o .: " url"
108+
0 commit comments