Skip to content

Commit 40659c0

Browse files
author
Marco Zocca
committed
adding Subscription
1 parent ab2b2ec commit 40659c0

File tree

4 files changed

+63
-2
lines changed

4 files changed

+63
-2
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ and this project adheres to the
88

99
## Unreleased
1010

11+
MSGraphAPI.ChangeNotifications.Subscription :
12+
13+
14+
1115
## 0.6.0.0
1216

17+
MSGraphAPI.Users.Group :
18+
- Group
19+
- getUserJoinedTeams
20+
- getGroupsDriveItems
21+
1322
Depend on `validation-micro` rather than `validation-selective`.
1423

1524
## 0.5.0.0

ms-graph-api.cabal

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ tested-with: GHC == 9.2.7
1818
library
1919
default-language: Haskell2010
2020
hs-source-dirs: src
21-
exposed-modules:
21+
exposed-modules: MSGraphAPI.ChangeNotifications.Subscription
2222
MSGraphAPI.User
2323
MSGraphAPI.Users.User
2424
MSGraphAPI.Users.Group
@@ -57,6 +57,7 @@ library
5757
DeriveGeneric
5858
DeriveFunctor
5959
DerivingStrategies
60+
LambdaCase
6061

6162

6263
-- test-suite spec
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
module MSGraphAPI.ChangeNotifications.Subscription where
2+
3+
import Data.List.NonEmpty (NonEmpty)
4+
import GHC.Generics (Generic(..))
5+
6+
-- aeson
7+
import qualified Data.Aeson as A (ToJSON(..), FromJSON(..), eitherDecode, genericParseJSON, defaultOptions, Options(..), withObject, withText, (.:), (.:?), object, (.=))
8+
import qualified Data.Aeson.Encoding as A (text)
9+
-- hoauth
10+
import Network.OAuth.OAuth2.Internal (AccessToken(..))
11+
-- req
12+
import Network.HTTP.Req (Req)
13+
-- text
14+
import Data.Text (Text, pack, unpack)
15+
-- time
16+
import Data.Time (LocalTime)
17+
18+
import qualified MSGraphAPI.Internal.Common as MSG (Collection(..), get, post, aesonOptions)
19+
import MSGraphAPI.Files.DriveItem (DriveItem)
20+
21+
-- | A subscription allows a client app to receive change notifications about changes to data in Microsoft Graph.
22+
--
23+
-- https://learn.microsoft.com/en-us/graph/api/resources/subscription?view=graph-rest-1.0
24+
data Subscription = Subscription {
25+
cnsId :: Text
26+
, cnsChangeType :: NonEmpty ChangeType
27+
, cnsClientState :: Text
28+
, cnsExpirationDateTime :: LocalTime
29+
, 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.
30+
, cnsResource :: Text -- ^ Specifies the resource that will be monitored for changes. Do not include the base URL (https://graph.microsoft.com/v1.0/)
31+
} deriving (Eq, Show, Generic)
32+
instance A.FromJSON Subscription where
33+
parseJSON = A.genericParseJSON (MSG.aesonOptions "cns")
34+
35+
36+
data ChangeType = CTCreated
37+
| CTUpdated
38+
| CTDeleted
39+
deriving (Eq, Show, Generic)
40+
instance A.FromJSON ChangeType where
41+
parseJSON = A.withText "ChangeType" $ \t ->
42+
case t of
43+
"created" -> pure CTCreated
44+
"updated" -> pure CTUpdated
45+
"deleted" -> pure CTDeleted
46+
x -> fail $ unwords ["ChangeType : unexpected value:", unpack x]
47+
instance A.ToJSON ChangeType where
48+
toEncoding = \case
49+
CTCreated -> A.text "created"
50+
CTUpdated -> A.text "updated"
51+
CTDeleted -> A.text "deleted"

src/MSGraphAPI/Users/Group.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import MSGraphAPI.Files.DriveItem (DriveItem)
1717

1818
-- | 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.
1919
--
20-
-- httpstea://learn.microsoft.com/en-us/graph/api/resources/groups-overview?view=graph-rest-1.0&tabs=http
20+
-- https://learn.microsoft.com/en-us/graph/api/resources/groups-overview?view=graph-rest-1.0&tabs=http
2121
data Group = Group {
2222
gId :: Text
2323
, gDisplayName :: Text

0 commit comments

Comments
 (0)