Skip to content

Commit 5ec8ef5

Browse files
committed
changed files to support passing the prefix to the paths such as me or groups/$groupId defaults to me
1 parent 2e0cfa2 commit 5ec8ef5

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

src/Resources/Files.php

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,65 +7,65 @@
77

88
class Files extends MsGraph
99
{
10-
public function getFiles($path = null, $order = 'asc')
10+
public function getFiles($path = null, $type = 'me')
1111
{
12-
$path = $path === null ? "me/drive/root/children?\$orderby=name%20$order" : "me/drive/root:".$this->forceStartingSlash($path).':/children?\$orderby=name%20$order';
12+
$path = $path === null ? $type.'/drive/root/children?$orderby=name%20asc' : $type.'/drive/root:'.$this->forceStartingSlash($path).':/children';
1313
return MsGraph::get($path);
1414
}
1515

16-
public function getDrive()
16+
public function getDrive($type = 'me')
1717
{
18-
return MsGraph::get('me/drive');
18+
return MsGraph::get($type.'/drive');
1919
}
2020

21-
public function getDrives()
21+
public function getDrives($type = 'me')
2222
{
23-
return MsGraph::get('me/drives');
23+
return MsGraph::get($type.'/drives');
2424
}
2525

26-
public function search($term)
26+
public function search($term, $type = 'me')
2727
{
28-
return MsGraph::get("me/drive/root/search(q='$term')");
28+
return MsGraph::get($type."/drive/root/search(q='$term')");
2929
}
3030

31-
public function downloadFile($id)
31+
public function downloadFile($id, $type = 'me')
3232
{
33-
$id = MsGraph::get("me/drive/items/$id");
33+
$id = MsGraph::get($type."/drive/items/$id");
3434

3535
return redirect()->away($id['@microsoft.graph.downloadUrl']);
3636
}
3737

38-
public function deleteFile($id)
38+
public function deleteFile($id, $type = 'me')
3939
{
40-
return MsGraph::delete("me/drive/items/$id");
40+
return MsGraph::delete($type."/drive/items/$id");
4141
}
4242

43-
public function createFolder($name, $path = null)
43+
public function createFolder($name, $path, $type = 'me')
4444
{
45-
$path = $path === null ? 'me/drive/root/children' : 'me/drive/root:'.$this->forceStartingSlash($path).':/children';
45+
$path = $path === null ? $type.'/drive/root/children' : $type.'/drive/root:'.$this->forceStartingSlash($path).':/children';
4646
return MsGraph::post($path, [
4747
'name' => $name,
4848
'folder' => new \stdClass(),
4949
"@microsoft.graph.conflictBehavior" => "rename"
5050
]);
5151
}
5252

53-
public function getItem($id)
53+
public function getItem($id, $type = 'me')
5454
{
55-
return MsGraph::get("me/drive/items/$id");
55+
return MsGraph::get($type."/drive/items/$id");
5656
}
5757

58-
public function rename($name, $id)
58+
public function rename($name, $id, $type = 'me')
5959
{
60-
$path = "me/drive/items/$id";
60+
$path = $type."/drive/items/$id";
6161
return MsGraph::patch($path, [
6262
'name' => $name
6363
]);
6464
}
6565

66-
public function upload($name, $uploadPath, $path = null)
66+
public function upload($name, $uploadPath, $path = null, $type = 'me')
6767
{
68-
$uploadSession = $this->createUploadSession($name, $path);
68+
$uploadSession = $this->createUploadSession($name, $path, $type);
6969
$uploadUrl = $uploadSession['uploadUrl'];
7070

7171
$fragSize = 320 * 1024;
@@ -97,19 +97,20 @@ public function upload($name, $uploadPath, $path = null)
9797
];
9898

9999
$client = new Client;
100-
$client->put($uploadUrl, [
100+
$response = $client->put($uploadUrl, [
101101
'headers' => $headers,
102102
'body' => $data,
103103
]);
104104

105105
$bytesRemaining = $bytesRemaining - $chunkSize;
106106
$i++;
107107
}
108+
108109
}
109110

110-
protected function createUploadSession($name, $path = null)
111+
protected function createUploadSession($name, $path = null, $type = 'me')
111112
{
112-
$path = $path === null ? "me/drive/root:/$name:/createUploadSession" : "me/drive/root:".$this->forceStartingSlash($path)."/$name:/createUploadSession";
113+
$path = $path === null ? $type."/drive/root:/$name:/createUploadSession" : $type."/drive/root:".$this->forceStartingSlash($path)."/$name:/createUploadSession";
113114

114115
return MsGraph::post($path, [
115116
'item' => [

0 commit comments

Comments
 (0)