Show: |
MSGraphClient
Created by programaths on 17.03.23.
Signature
global with sharing class MSGraphClient
MSGraphClient Methods
createFolder(userId, driveId, parentId, name)
Create folder "name" in drive identified by "driveId" with parent identified by "parentId"
Signature
global CollabMSGraphClient.SaveFileResponse createFolder(String userId, String driveId, String parentId, String name)
Parameters
userId
Type:
String
user ID
driveId
Type:
String
drive ID
parentId
Type:
String
parent ID
name
Type:
String
folder name
Returns
created folder
Example
createMock(stubProvider)
the unit test stub which implements the mock methods
Signature
global static MSGraphClient createMock(StubProvider stubProvider)
Parameters
stubProvider
Type:
StubProvider
use the default Stub from COLLABORATION Butler "new MSGraphClient.MSGraphClientStub()". Or create your own Stub for each method you want to use.
Returns
Mock
Example
ensurePath(userId, driveId, path)
Ensures that the given path exists in the specified drive. If any folder in the path doesn't exist, this method attempts to create it.
Signature
global Boolean ensurePath(String userId, String driveId, String path)
Parameters
userId
Type:
String
The user ID for which the path should be ensured.
driveId
Type:
String
The drive ID in which the path should be ensured.
path
Type:
String
The path to be ensured, with each folder separated by a forward slash (/).
Returns
true if the path exists or has been successfully created, false otherwise.
Example
getDriveItemByPath(userId, driveId, path)
Retrieve drive item in drive "driveId" at path <var>path</var>
Signature
global CollabMSGraphClient.GetDriveResponse getDriveItemByPath(String userId, String driveId, String path)
Parameters
userId
Type:
String
User Id
driveId
Type:
String
drive ID
path
Type:
String
path
Returns
drive item at path <var>path</var>. See: GetDriveResponse
Example
getSiteDrive(userId, libraryUrl)
Get drive from URL, tacking into account sites and libraries.
Signature
global CollabMSGraphClient.GetDriveResponse getSiteDrive(String userId, String libraryUrl)
Parameters
userId
Type:
String
user Id
libraryUrl
Type:
String
site/library URL
Returns
corresponding drive: GetDriveResponse
Example
renameFolder(userId, url, isLibrary, basePath, sourceName, targetName)
Change the name of folder in a SharePoint Library
Signature
global static CollabMSGraphClient.SaveFileResponse renameFolder(String userId,String url, Boolean isLibrary, String basePath, String sourceName,String targetName)
Parameters
userId
Type:
String
User ID
url
URR
isLibrary
Type:
Boolean
Is <var>url</var> pointing to a Library ?
basePath
Type:
String
Path to folder containing the driveItem to rename
sourceName
Type:
String
driveItem source name
targetName
driveItem desired name
Returns
changed driveItem, the id field contains the list item id
Example
sanitizeFileName(dirtyFilename)
General cleanup of characters SharePoint cannot deal with
Signature
global String sanitizeFileName(String dirtyFilename)
Parameters
dirtyFilename
Type:
String
Filename without the path
Returns
clean URL
Example
sanitizeFolderName(dirtyFolderName)
General cleanup of characters SharePoint cannot deal with
Signature
global String sanitizeFolderName(String dirtyFolderName)
Parameters
dirtyFolderName
Type:
String
Folder name not the entire path
Returns
clean URL
sanitizeFolderPath(dirtyFolderPath)
General cleanup of characters SharePoint cannot deal with
Signature
global String sanitizeFolderPath(String dirtyFolderPath)
Parameters
dirtyFolderPath
Type:
String
Url path of the folder without filename (use{@link CollabMSGraphClient.sanitizeFileName})
Returns
clean URL
Example
saveFileById(userId, driveId, parentId, fileName, fileContent)
Save file in a site drive using IDs
Signature
global CollabMSGraphClient.SaveFileResponse saveFileById(String userId, String driveId, String parentId, String fileName, Blob fileContent)
Parameters
userId
Type:
String
user ID
driveId
Type:
String
drive ID
parentId
Type:
String
parent ID
fileName
Type:
String
file name
fileContent
Type:
Blob
file content
Returns
saved file
MSGraphClient.MSGraphClientStub
Default mock returning only succesful responses. The below will show how the Stub behaves and which values are returned so they can be used in testing and asserting.
Signature
global class MSGraphClientStub implements StubProvider
Example
|