ms-graph-api-0.6.0.0: src/MSGraphAPI/Files/DriveItem.hs
module MSGraphAPI.Files.DriveItem where
import GHC.Generics (Generic(..))
-- aeson
import qualified Data.Aeson as A (ToJSON(..), FromJSON(..), genericParseJSON)
-- 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 (LocalTime)
import qualified MSGraphAPI.Internal.Common as MSG (get, getLbs, post, Collection, aesonOptions)
data DriveItem = DriveItem {
diId :: Text
, diName :: Text
, diLastModifiedDateTime :: LocalTime
} deriving (Eq, Ord, Show, Generic)
instance A.FromJSON DriveItem where
parseJSON = A.genericParseJSON (MSG.aesonOptions "di")
-- | download a complete file from user's directory
--
-- @GET \/me\/drive\/items\/{item-id}\/content@
--
-- https://learn.microsoft.com/en-us/graph/api/driveitem-get-content?view=graph-rest-1.0&tabs=http#request
downloadFileMe :: Text -- ^ item ID
-> AccessToken -> Req LBS.ByteString
downloadFileMe itemId = MSG.getLbs ["me", "drive", "items", itemId, "content"] mempty
-- | download a file from a drive
--
-- @GET \/drives\/{drive-id}\/items\/{item-id}\/content@
--
-- https://learn.microsoft.com/en-us/graph/api/driveitem-get-content?view=graph-rest-1.0&tabs=http#request
downloadFile :: Text -- ^ drive ID
-> Text -- ^ file ID
-> AccessToken -> Req LBS.ByteString
downloadFile did itemId = MSG.getLbs ["drives", did, "items", itemId, "content"] mempty