forked from haskell-github/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInvitation.hs
More file actions
87 lines (75 loc) · 2.83 KB
/
Invitation.hs
File metadata and controls
87 lines (75 loc) · 2.83 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
-----------------------------------------------------------------------------
-- |
-- License : BSD-3-Clause
-- Maintainer : Oleg Grenrus <oleg.grenrus@iki.fi>
--
module GitHub.Data.Invitation where
import GitHub.Data.Definitions
import GitHub.Data.Id (Id)
import GitHub.Data.Name (Name)
import GitHub.Data.Repos (Repo)
import GitHub.Data.URL (URL)
import GitHub.Internal.Prelude
import Prelude ()
import qualified Data.Text as T
data Invitation = Invitation
{ invitationId :: !(Id Invitation)
-- TODO: technically either one should be, maybe both. use `these` ?
, invitationLogin :: !(Maybe (Name User))
, invitationEmail :: !(Maybe Text)
, invitationRole :: !InvitationRole
, invitationCreatedAt :: !UTCTime
, inviter :: !SimpleUser
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData Invitation where rnf = genericRnf
instance Binary Invitation
instance FromJSON Invitation where
parseJSON = withObject "Invitation" $ \o -> Invitation
<$> o .: "id"
<*> o .:? "login"
<*> o .:? "email"
<*> o .: "role"
<*> o .: "created_at"
<*> o .: "inviter"
data InvitationRole
= InvitationRoleDirectMember
| InvitationRoleAdmin
| InvitationRoleBillingManager
| InvitationRoleHiringManager
| InvitationRoleReinstate
deriving
(Eq, Ord, Show, Enum, Bounded, Generic, Typeable, Data)
instance NFData InvitationRole where rnf = genericRnf
instance Binary InvitationRole
instance FromJSON InvitationRole where
parseJSON = withText "InvitationRole" $ \t -> case T.toLower t of
"direct_member" -> pure InvitationRoleDirectMember
"admin" -> pure InvitationRoleAdmin
"billing_manager" -> pure InvitationRoleBillingManager
"hiring_manager" -> pure InvitationRoleHiringManager
"reinstate" -> pure InvitationRoleReinstate
_ -> fail $ "Unknown InvitationRole: " <> T.unpack t
data RepoInvitation = RepoInvitation
{ repoInvitationId :: !(Id RepoInvitation)
, repoInvitationInvitee :: !SimpleUser
, repoInvitationInviter :: !SimpleUser
, repoInvitationRepo :: !Repo
, repoInvitationUrl :: !URL
, repoInvitationCreatedAt :: !UTCTime
, repoInvitationPermission :: !Text
, repoInvitationHtmlUrl :: !URL
}
deriving (Show, Data, Typeable, Eq, Ord, Generic)
instance NFData RepoInvitation where rnf = genericRnf
instance Binary RepoInvitation
instance FromJSON RepoInvitation where
parseJSON = withObject "RepoInvitation" $ \o -> RepoInvitation
<$> o .: "id"
<*> o .: "invitee"
<*> o .: "inviter"
<*> o .: "repository"
<*> o .: "url"
<*> o .: "created_at"
<*> o .: "permissions"
<*> o .: "html_url"