diff --git a/CHANGELOG.md b/CHANGELOG.md index e95d764..4f905dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,8 +8,17 @@ and this project adheres to the ## Unreleased +MSGraphAPI.ChangeNotifications.Subscription : + + + ## 0.6.0.0 +MSGraphAPI.Users.Group : +- Group +- getUserJoinedTeams +- getGroupsDriveItems + Depend on `validation-micro` rather than `validation-selective`. ## 0.5.0.0 diff --git a/ms-graph-api.cabal b/ms-graph-api.cabal index 7d1e385..d307377 100644 --- a/ms-graph-api.cabal +++ b/ms-graph-api.cabal @@ -18,7 +18,7 @@ tested-with: GHC == 9.2.7 library default-language: Haskell2010 hs-source-dirs: src - exposed-modules: + exposed-modules: MSGraphAPI.ChangeNotifications.Subscription MSGraphAPI.User MSGraphAPI.Users.User MSGraphAPI.Users.Group @@ -57,6 +57,7 @@ library DeriveGeneric DeriveFunctor DerivingStrategies + LambdaCase -- test-suite spec diff --git a/src/MSGraphAPI/ChangeNotifications/Subscription.hs b/src/MSGraphAPI/ChangeNotifications/Subscription.hs new file mode 100644 index 0000000..b332bf4 --- /dev/null +++ b/src/MSGraphAPI/ChangeNotifications/Subscription.hs @@ -0,0 +1,51 @@ +module MSGraphAPI.ChangeNotifications.Subscription where + +import Data.List.NonEmpty (NonEmpty) +import GHC.Generics (Generic(..)) + +-- aeson +import qualified Data.Aeson as A (ToJSON(..), FromJSON(..), eitherDecode, genericParseJSON, defaultOptions, Options(..), withObject, withText, (.:), (.:?), object, (.=)) +import qualified Data.Aeson.Encoding as A (text) +-- hoauth +import Network.OAuth.OAuth2.Internal (AccessToken(..)) +-- req +import Network.HTTP.Req (Req) +-- text +import Data.Text (Text, pack, unpack) +-- time +import Data.Time (LocalTime) + +import qualified MSGraphAPI.Internal.Common as MSG (Collection(..), get, post, aesonOptions) +import MSGraphAPI.Files.DriveItem (DriveItem) + +-- | A subscription allows a client app to receive change notifications about changes to data in Microsoft Graph. +-- +-- https://learn.microsoft.com/en-us/graph/api/resources/subscription?view=graph-rest-1.0 +data Subscription = Subscription { + cnsId :: Text + , cnsChangeType :: NonEmpty ChangeType + , cnsClientState :: Text + , cnsExpirationDateTime :: LocalTime + , cnsNotificationUrl :: Text -- ^ The URL of the endpoint that will receive the change notifications. This URL must make use of the HTTPS protocol. Any query string parameter included in the notificationUrl property will be included in the HTTP POST request when Microsoft Graph sends the change notifications. + , cnsResource :: Text -- ^ Specifies the resource that will be monitored for changes. Do not include the base URL (https://graph.microsoft.com/v1.0/) + } deriving (Eq, Show, Generic) +instance A.FromJSON Subscription where + parseJSON = A.genericParseJSON (MSG.aesonOptions "cns") + + +data ChangeType = CTCreated + | CTUpdated + | CTDeleted + deriving (Eq, Show, Generic) +instance A.FromJSON ChangeType where + parseJSON = A.withText "ChangeType" $ \t -> + case t of + "created" -> pure CTCreated + "updated" -> pure CTUpdated + "deleted" -> pure CTDeleted + x -> fail $ unwords ["ChangeType : unexpected value:", unpack x] +instance A.ToJSON ChangeType where + toEncoding = \case + CTCreated -> A.text "created" + CTUpdated -> A.text "updated" + CTDeleted -> A.text "deleted" diff --git a/src/MSGraphAPI/Users/Group.hs b/src/MSGraphAPI/Users/Group.hs index 3098006..d4b4bfc 100644 --- a/src/MSGraphAPI/Users/Group.hs +++ b/src/MSGraphAPI/Users/Group.hs @@ -17,7 +17,7 @@ import MSGraphAPI.Files.DriveItem (DriveItem) -- | Groups are collections of principals with shared access to resources in Microsoft services or in your app. Different principals such as users, other groups, devices, and applications can be part of groups. -- --- httpstea://learn.microsoft.com/en-us/graph/api/resources/groups-overview?view=graph-rest-1.0&tabs=http +-- https://learn.microsoft.com/en-us/graph/api/resources/groups-overview?view=graph-rest-1.0&tabs=http data Group = Group { gId :: Text , gDisplayName :: Text