Skip to content

Commit

Permalink
adding Subscription
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Zocca committed Jun 19, 2023
1 parent ab2b2ec commit 40659c0
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 2 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion ms-graph-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -57,6 +57,7 @@ library
DeriveGeneric
DeriveFunctor
DerivingStrategies
LambdaCase


-- test-suite spec
Expand Down
51 changes: 51 additions & 0 deletions src/MSGraphAPI/ChangeNotifications/Subscription.hs
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion src/MSGraphAPI/Users/Group.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 40659c0

Please sign in to comment.