-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Marco Zocca
committed
Jun 18, 2023
1 parent
43f4bd0
commit ab2b2ec
Showing
6 changed files
with
147 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,35 @@ | ||
module MSGraphAPI.User where | ||
|
||
import GHC.Generics (Generic(..)) | ||
|
||
import Data.List (sort, sortBy, stripPrefix, uncons) | ||
import Data.Maybe (listToMaybe, fromMaybe) | ||
-- import Data.Ord (comparing) | ||
import Data.Char (toLower) | ||
import Data.String (IsString(..)) | ||
import Data.Word (Word) | ||
|
||
-- aeson | ||
import qualified Data.Aeson as A (ToJSON(..), FromJSON(..), genericParseJSON, defaultOptions, Options(..), withObject, withText, (.:), (.:?), object, (.=), Key, Value, camelTo2) | ||
import qualified Data.Aeson.Types as A (Parser, Object) | ||
-- import qualified Data.Aeson.KeyMap as AKV (KeyMap, lookup) | ||
-- containers | ||
-- import qualified Data.Map as M (Map, empty, insert, lookup) | ||
-- 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 (ZonedTime, zonedTimeToLocalTime) | ||
|
||
import qualified MSGraphAPI.Internal.Common as MSG (get, post, aesonOptions) | ||
|
||
-- | Get user information | ||
-- | ||
-- @GET \/users\/{user-id}@ | ||
-- | ||
-- https://learn.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=http#request | ||
get :: Text -- ^ user id | ||
-> AccessToken -> Req User | ||
get uid = MSG.get ["users", uid] mempty | ||
|
||
-- | Get information on signed-in user | ||
-- | ||
-- Calling the \/me endpoint requires a signed-in user and therefore a delegated permission. Application permissions are not supported when using the \/me endpoint. | ||
-- | ||
-- @GET \/me@ | ||
-- | ||
-- https://learn.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=http#request-1 | ||
getMe :: AccessToken -> Req User | ||
getMe = MSG.get ["me"] mempty | ||
|
||
|
||
data User = User { | ||
uId :: Text | ||
, uUserPrincipalName :: Text | ||
, uDisplayName :: Text | ||
} deriving (Eq, Ord, Show, Generic) | ||
instance A.FromJSON User where | ||
parseJSON = A.genericParseJSON (MSG.aesonOptions "u") | ||
|
||
|
||
-- import Data.List (sort, sortBy, stripPrefix, uncons) | ||
-- import Data.Maybe (listToMaybe, fromMaybe) | ||
-- -- import Data.Ord (comparing) | ||
-- import Data.Char (toLower) | ||
-- import Data.String (IsString(..)) | ||
-- import Data.Word (Word) | ||
|
||
-- -- aeson | ||
-- import qualified Data.Aeson as A (ToJSON(..), FromJSON(..), genericParseJSON, defaultOptions, Options(..), withObject, withText, (.:), (.:?), object, (.=), Key, Value, camelTo2) | ||
-- import qualified Data.Aeson.Types as A (Parser, Object) | ||
-- -- import qualified Data.Aeson.KeyMap as AKV (KeyMap, lookup) | ||
-- -- containers | ||
-- -- import qualified Data.Map as M (Map, empty, insert, lookup) | ||
-- -- 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 (ZonedTime, zonedTimeToLocalTime) | ||
|
||
-- import qualified MSGraphAPI.Internal.Common as MSG (get, post, aesonOptions) | ||
-- -- import MSGraphAPI.Users.User (User) | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
-- | User | ||
module MSGraphAPI.Users.Group where | ||
|
||
import GHC.Generics (Generic(..)) | ||
|
||
-- aeson | ||
import qualified Data.Aeson as A (ToJSON(..), FromJSON(..), eitherDecode, genericParseJSON, defaultOptions, Options(..), withObject, withText, (.:), (.:?), object, (.=)) | ||
-- hoauth | ||
import Network.OAuth.OAuth2.Internal (AccessToken(..)) | ||
-- req | ||
import Network.HTTP.Req (Req) | ||
-- text | ||
import Data.Text (Text, pack, unpack) | ||
|
||
import qualified MSGraphAPI.Internal.Common as MSG (Collection(..), get, post, aesonOptions) | ||
import MSGraphAPI.Files.DriveItem (DriveItem) | ||
|
||
-- | 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. | ||
-- | ||
-- httpstea://learn.microsoft.com/en-us/graph/api/resources/groups-overview?view=graph-rest-1.0&tabs=http | ||
data Group = Group { | ||
gId :: Text | ||
, gDisplayName :: Text | ||
, gDescription :: Text | ||
} deriving (Eq, Ord, Show, Generic) | ||
instance A.FromJSON Group where | ||
parseJSON = A.genericParseJSON (MSG.aesonOptions "g") | ||
|
||
-- | Get the teams in Microsoft Teams that the user is a direct member of. | ||
-- | ||
-- @GET \/users\/{id | user-principal-name}\/joinedTeams@ | ||
-- | ||
-- https://learn.microsoft.com/en-us/graph/api/user-list-joinedteams?view=graph-rest-1.0&tabs=http | ||
getUserJoinedTeams :: Text -- ^ User ID | ||
-> AccessToken -> Req (MSG.Collection Group) | ||
getUserJoinedTeams uid = MSG.get ["users", uid, "joinedTeams"] mempty | ||
|
||
-- | Get the 'DriveItem's in the 'Group' storage, starting from the root item | ||
-- | ||
-- @GET \/groups\/{group-id}\/drive\/root\/children@ | ||
-- | ||
-- https://learn.microsoft.com/en-us/graph/api/driveitem-list-children?view=graph-rest-1.0&tabs=http | ||
getGroupsDriveItems :: Text -- ^ Group ID | ||
-> AccessToken -> Req (MSG.Collection DriveItem) | ||
getGroupsDriveItems gid = MSG.get ["groups", gid, "drive", "root", "children"] mempty | ||
|
||
|
||
-- data X = X { xName :: Text } deriving (Eq, Ord, Show, Generic) | ||
-- instance A.FromJSON X where | ||
-- parseJSON = A.genericParseJSON (MSG.aesonOptions "x") | ||
|
||
-- pt0 :: Either String (MSG.Collection DriveItem) | ||
-- pt0 = A.eitherDecode t0 | ||
-- where | ||
-- t0 = "{\r\n \"value\": [\r\n {\"name\": \"myfile.jpg\" },\r\n {\"name\": \"Documents\" },\r\n {\"name\": \"Photos\" },\r\n {\"name\": \"my sheet(1).xlsx\"}\r\n ]\r\n}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
-- | User | ||
module MSGraphAPI.Users.User where | ||
|
||
import GHC.Generics (Generic(..)) | ||
|
||
-- aeson | ||
import qualified Data.Aeson as A (ToJSON(..), FromJSON(..), genericParseJSON, defaultOptions, Options(..), withObject, withText, (.:), (.:?), object, (.=)) | ||
-- hoauth | ||
import Network.OAuth.OAuth2.Internal (AccessToken(..)) | ||
-- req | ||
import Network.HTTP.Req (Req) | ||
-- text | ||
import Data.Text (Text, pack, unpack) | ||
|
||
import qualified MSGraphAPI.Internal.Common as MSG (get, post, aesonOptions) | ||
|
||
|
||
data User = User { | ||
uId :: Text | ||
, uUserPrincipalName :: Text | ||
, uDisplayName :: Text | ||
} deriving (Eq, Ord, Show, Generic) | ||
instance A.FromJSON User where | ||
parseJSON = A.genericParseJSON (MSG.aesonOptions "u") | ||
|
||
|
||
-- | Get user information | ||
-- | ||
-- @GET \/users\/{user-id}@ | ||
-- | ||
-- https://learn.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=http#request | ||
get :: Text -- ^ user id | ||
-> AccessToken -> Req User | ||
get uid = MSG.get ["users", uid] mempty | ||
|
||
-- | Get information on signed-in user | ||
-- | ||
-- Calling the \/me endpoint requires a signed-in user and therefore a delegated permission. Application permissions are not supported when using the \/me endpoint. | ||
-- | ||
-- @GET \/me@ | ||
-- | ||
-- https://learn.microsoft.com/en-us/graph/api/user-get?view=graph-rest-1.0&tabs=http#request-1 | ||
getMe :: AccessToken -> Req User | ||
getMe = MSG.get ["me"] mempty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters