Skip to content

Commit

Permalink
add Files.Drive
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Zocca committed Jul 2, 2023
1 parent ce63e16 commit ec85173
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
9 changes: 7 additions & 2 deletions ms-graph-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion ms-graph-api/ms-graph-api.cabal
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
56 changes: 56 additions & 0 deletions ms-graph-api/src/MSGraphAPI/Files/Drive.hs
Original file line number Diff line number Diff line change
@@ -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"]
1 change: 1 addition & 0 deletions ms-graph-api/src/MSGraphAPI/Files/DriveItem.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
-- | Files.DriveItem
module MSGraphAPI.Files.DriveItem (
-- * list items
listRootChildrenMe
Expand Down

0 comments on commit ec85173

Please sign in to comment.