From ec85173159071eaabc33d809591229c8b1f0461e Mon Sep 17 00:00:00 2001 From: Marco Zocca Date: Sun, 2 Jul 2023 11:38:10 +0200 Subject: [PATCH] add Files.Drive --- ms-graph-api/CHANGELOG.md | 9 ++- ms-graph-api/ms-graph-api.cabal | 3 +- ms-graph-api/src/MSGraphAPI/Files/Drive.hs | 56 +++++++++++++++++++ .../src/MSGraphAPI/Files/DriveItem.hs | 1 + 4 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 ms-graph-api/src/MSGraphAPI/Files/Drive.hs diff --git a/ms-graph-api/CHANGELOG.md b/ms-graph-api/CHANGELOG.md index c89a277..48f2018 100644 --- a/ms-graph-api/CHANGELOG.md +++ b/ms-graph-api/CHANGELOG.md @@ -9,12 +9,17 @@ and this project adheres to the ## Unreleased +## 0.9.0.0 + +MSGraphAPI.Files.Drive -## 0.8.0.0 -MSGraphAPI.Files.DriveItem +## 0.8.0.0 +MSGraphAPI.Files.DriveItem : +- custom FromJSON instance using a sum type for the various types of drive item. Makes it convenient for users to pattern match on type. So far only File, Folder and Package drive item types are parsed further. +New MSGraphAPI module to re-expose internals ## 0.7.0.0 diff --git a/ms-graph-api/ms-graph-api.cabal b/ms-graph-api/ms-graph-api.cabal index be56972..d5b83e4 100644 --- a/ms-graph-api/ms-graph-api.cabal +++ b/ms-graph-api/ms-graph-api.cabal @@ -1,5 +1,5 @@ name: ms-graph-api -version: 0.8.0.0 +version: 0.9.0.0 synopsis: Microsoft Graph API description: Bindings to the Microsoft Graph API homepage: https://github.com/unfoldml/ms-graph-api @@ -24,6 +24,7 @@ library MSGraphAPI.Users.User MSGraphAPI.Users.Group MSGraphAPI.Drive + MSGraphAPI.Files.Drive MSGraphAPI.Files.DriveItem other-modules: MSGraphAPI.Internal.Common build-depends: base >= 4.7 && < 5 diff --git a/ms-graph-api/src/MSGraphAPI/Files/Drive.hs b/ms-graph-api/src/MSGraphAPI/Files/Drive.hs new file mode 100644 index 0000000..8f00f5e --- /dev/null +++ b/ms-graph-api/src/MSGraphAPI/Files/Drive.hs @@ -0,0 +1,56 @@ +module MSGraphAPI.Files.Drive ( + listDrivesMe + , listDrivesGroup + -- * types + , Drive(..) + ) where + +import Control.Applicative (Alternative(..)) +import Data.Int (Int32) +import GHC.Generics (Generic(..)) + +-- aeson +import qualified Data.Aeson as A (ToJSON(..), FromJSON(..), Value, genericParseJSON, (.:), (.:?), Object, withObject, Key) +import qualified Data.Aeson.Types as A (Parser) +-- bytestring +import qualified Data.ByteString.Lazy as LBS (ByteString) +-- hoauth +import Network.OAuth.OAuth2.Internal (AccessToken(..)) +-- req +import Network.HTTP.Req (Req) +-- text +import Data.Text (Text, pack, unpack) +-- time +import Data.Time (ZonedTime) + +import qualified MSGraphAPI.Internal.Common as MSG (get, getLbs, post, Collection, aesonOptions) + +-- | The top-level object that represents a user's OneDrive or a document library in SharePoint. +-- +-- OneDrive users will always have at least one drive available, their default drive. Users without a OneDrive license may not have a default drive available. +-- +-- https://learn.microsoft.com/en-us/graph/api/resources/drive?view=graph-rest-1.0 +data Drive = Drive { + dId :: Text + , dName :: Text + , dDescription :: Text + , dLastModifiedDateTime :: ZonedTime -- 2022-11-28T09:18:45Z + , dDriveType :: Text + } deriving (Show, Generic) +instance A.FromJSON Drive where + parseJSON = A.genericParseJSON (MSG.aesonOptions "d") +instance A.ToJSON Drive + +-- | List the current user's drives +-- +-- @GET \/me\/drives@ +listDrivesMe :: AccessToken -> Req (MSG.Collection Drive) +listDrivesMe = MSG.get ["me", "drives"] mempty + + +-- | To list the document libraries for a group, your app requests the drives relationship on the Group. +-- +-- @GET \/groups\/{groupId}\/drives@ +listDrivesGroup :: Text -- ^ group ID + -> AccessToken -> Req (MSG.Collection Drive) +listDrivesGroup gid = MSG.get ["groups", gid, "drives"] diff --git a/ms-graph-api/src/MSGraphAPI/Files/DriveItem.hs b/ms-graph-api/src/MSGraphAPI/Files/DriveItem.hs index b39b619..3c9c173 100644 --- a/ms-graph-api/src/MSGraphAPI/Files/DriveItem.hs +++ b/ms-graph-api/src/MSGraphAPI/Files/DriveItem.hs @@ -1,3 +1,4 @@ +-- | Files.DriveItem module MSGraphAPI.Files.DriveItem ( -- * list items listRootChildrenMe