|
| 1 | +----------------------------------------------------------------------------- |
| 2 | +-- | |
| 3 | +-- License : BSD-3-Clause |
| 4 | +-- Maintainer : Oleg Grenrus <oleg.grenrus@iki.fi> |
| 5 | +-- |
| 6 | +module GitHub.Data.Invitation where |
| 7 | + |
| 8 | +import GitHub.Data.Definitions |
| 9 | +import GitHub.Data.Id (Id) |
| 10 | +import GitHub.Data.Name (Name) |
| 11 | +import GitHub.Internal.Prelude |
| 12 | +import Prelude () |
| 13 | + |
| 14 | +data Invitation = Invitation |
| 15 | + { invitationId :: !(Id Invitation) |
| 16 | + -- TODO: technically either one should be, maybe both. use `these` ? |
| 17 | + , invitationLogin :: !(Maybe (Name User)) |
| 18 | + , invitationEmail :: !(Maybe Text) |
| 19 | + , invitationRole :: !InvitationRole |
| 20 | + , invitationCreatedAt :: !UTCTime |
| 21 | + , inviter :: !SimpleUser |
| 22 | + } |
| 23 | + deriving (Show, Data, Typeable, Eq, Ord, Generic) |
| 24 | + |
| 25 | +instance NFData Invitation where rnf = genericRnf |
| 26 | +instance Binary Invitation |
| 27 | + |
| 28 | +instance FromJSON Invitation where |
| 29 | + parseJSON = withObject "Invitation" $ \o -> Invitation |
| 30 | + <$> o .: "id" |
| 31 | + <*> o .:? "login" |
| 32 | + <*> o .:? "email" |
| 33 | + <*> o .: "role" |
| 34 | + <*> o .: "created_at" |
| 35 | + <*> o .: "inviter" |
| 36 | + |
| 37 | + |
| 38 | +data InvitationRole |
| 39 | + = InvitationRoleDirectMember |
| 40 | + | InvitationRoleAdmin |
| 41 | + | InvitationRoleBillingManager |
| 42 | + | InvitationRoleHiringManager |
| 43 | + | InvitationRoleReinstate |
| 44 | + deriving |
| 45 | + (Eq, Ord, Show, Enum, Bounded, Generic, Typeable, Data) |
| 46 | + |
| 47 | +instance NFData InvitationRole where rnf = genericRnf |
| 48 | +instance Binary InvitationRole |
| 49 | + |
| 50 | +instance FromJSON InvitationRole where |
| 51 | + parseJSON = withText "InvirationRole" $ \t -> case t of |
| 52 | + "direct_member" -> pure InvitationRoleDirectMember |
| 53 | + "admin" -> pure InvitationRoleAdmin |
| 54 | + "billing_manager" -> pure InvitationRoleBillingManager |
| 55 | + "hiring_manager" -> pure InvitationRoleHiringManager |
| 56 | + "reinstate" -> pure InvitationRoleReinstate |
| 57 | + _ -> fail $ "Invalid role " ++ show t |
0 commit comments