Skip to content

Commit

Permalink
v 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Zocca committed Jun 23, 2023
1 parent 0bc0848 commit 82b910a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
8 changes: 5 additions & 3 deletions ms-graph-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ and this project adheres to the
## Unreleased


## 1.0.0.0

MSGraphAPI.ChangeNotifications.Subscription

## 0.7.0.0

MSGraphAPI.ChangeNotifications.Subscription:
- add createSubscription

*Breaking changes*

Moved the Network/* module hierarchy to the `ms-auth` package shared with `ms-azure-api`.


## 0.6.0.0

MSGraphAPI.Users.Group :
Expand Down
2 changes: 1 addition & 1 deletion ms-graph-api/ms-graph-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ build-type: Simple
extra-source-files: README.md
CHANGELOG.md
cabal-version: >=1.10
tested-with: GHC == 9.2.7
tested-with: GHC == 9.2.8

library
default-language: Haskell2010
Expand Down
24 changes: 23 additions & 1 deletion ms-graph-api/src/MSGraphAPI/ChangeNotifications/Subscription.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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 as A (ToJSON(..), FromJSON(..), eitherDecode, genericParseJSON, genericToEncoding, defaultOptions, Options(..), withObject, withText, (.:), (.:?), object, (.=))
import qualified Data.Aeson.Encoding as A (text)
-- hoauth
import Network.OAuth.OAuth2.Internal (AccessToken(..))
Expand All @@ -18,6 +18,10 @@ import Data.Time (LocalTime)
import qualified MSGraphAPI.Internal.Common as MSG (Collection(..), get, post, aesonOptions)
import MSGraphAPI.Files.DriveItem (DriveItem)

-- | Creating a subscription requires read scope to the resource. For example, to get change notifications on messages, your app needs the Mail.Read permission.
createSubscription :: (A.FromJSON b) => Subscription -> AccessToken -> Req b
createSubscription = MSG.post ["subscriptions"] mempty

-- | 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
Expand All @@ -28,10 +32,28 @@ data Subscription = Subscription {
, 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/)
, cnsLatestSupportedTLSVersion :: LatestTLSVer
} deriving (Eq, Show, Generic)
instance A.FromJSON Subscription where
parseJSON = A.genericParseJSON (MSG.aesonOptions "cns")
instance A.ToJSON Subscription where
toEncoding = A.genericToEncoding (MSG.aesonOptions "cns")

data LatestTLSVer = LTV10 | LTV11 | LTV12 | LTV13 deriving (Eq, Show, Generic)
instance A.FromJSON LatestTLSVer where
parseJSON = A.withText "LatestTLSVer" $ \t ->
case t of
"v1_0" -> pure LTV10
"v1_1" -> pure LTV11
"v1_2" -> pure LTV12
"v1_3" -> pure LTV13
x -> fail $ unwords ["LatestTLSVer : unexpected value:", unpack x]
instance A.ToJSON LatestTLSVer where
toEncoding = \case
LTV10 -> A.text "v1_0"
LTV11 -> A.text "v1_1"
LTV12 -> A.text "v1_2"
LTV13 -> A.text "v1_3"

data ChangeType = CTCreated
| CTUpdated
Expand Down

0 comments on commit 82b910a

Please sign in to comment.