Skip to content

Commit cf00f73

Browse files
added new traits
1 parent 6dafd4e commit cf00f73

File tree

4 files changed

+154
-20
lines changed

4 files changed

+154
-20
lines changed

src/Api/Contacts.php

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,34 @@ public function contacts($limit = 25, $offset = 50, $skip = 0)
1717

1818
$contacts = self::get('me/contacts?'.http_build_query($messageQueryParams));
1919

20-
$total = $contacts['@odata.count'];
21-
$previous = null;
22-
$next = null;
23-
if (isset($contacts['@odata.nextLink'])) {
24-
$first = explode('$skip=', $contacts['@odata.nextLink']);
25-
$skip = explode('&', $first[1]);
26-
$previous = $skip[0]-$offset;
27-
$next = $skip[0];
28-
29-
if ($previous < 0) {
30-
$previous = 0;
31-
}
32-
33-
if ($next == $total) {
34-
$next = null;
35-
}
36-
}
20+
$data = self::getPagination($contacts, $offset);
3721

3822
return [
3923
'contacts' => $contacts,
40-
'total' => $total,
41-
'previous' => $previous,
42-
'next' => $next,
24+
'total' => $data['total'],
25+
'previous' => $data['previous'],
26+
'next' => $data['next'],
4327
];
28+
29+
}
30+
31+
public function contactCreate($data)
32+
{
33+
return self::post("me/contacts", $data);
34+
}
35+
36+
public function contactGet($id)
37+
{
38+
return self::get("me/contacts/$id");
39+
}
40+
41+
public function contactUpdate($id, $data)
42+
{
43+
return self::patch("me/contacts/$id", $data);
44+
}
45+
46+
public function contactDelete($id)
47+
{
48+
return self::delete("me/contacts/$id");
4449
}
4550
}

src/Api/Drive.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
namespace DaveismynameLaravel\MsGraph\Api;
4+
5+
trait Drive {
6+
7+
public function drive($limit = 25, $skip = 0, $messageQueryParams = [])
8+
{
9+
$skip = request('next', $skip);
10+
11+
if ($messageQueryParams != []) {
12+
$messageQueryParams = [
13+
"\$skip" => $skip,
14+
"\$top" => $limit,
15+
"\$count" => "true",
16+
];
17+
}
18+
19+
$files = self::get('me/drive/root/children'.http_build_query($messageQueryParams));
20+
21+
$data = self::getPagination($files, $skip);
22+
23+
return [
24+
'files' => $files,
25+
'total' => $data['total'],
26+
'previous' => $data['previous'],
27+
'next' => $data['next'],
28+
];
29+
}
30+
31+
public function driveDownload($id)
32+
{
33+
$id = self::get("me/drive/items/$id");
34+
35+
return redirect()->away($id['@microsoft.graph.downloadUrl']);
36+
}
37+
38+
public function driveDelete($id)
39+
{
40+
return self::delete("me/drive/items/$id");
41+
}
42+
}

src/Api/ToDo.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace DaveismynameLaravel\MsGraph\Api;
4+
5+
trait ToDo {
6+
7+
public function tasks($limit = 25, $skip = 0, $messageQueryParams = [])
8+
{
9+
$skip = request('next', $skip);
10+
11+
if ($messageQueryParams != []) {
12+
$messageQueryParams = [
13+
"\filter" => "status eq 'notStarted'",
14+
"\$skip" => $skip,
15+
"\$top" => $limit,
16+
"\$count" => "true",
17+
];
18+
}
19+
20+
$tasks = self::get('me/messages?'.http_build_query($messageQueryParams));
21+
22+
$data = self::getPagination($tasks, $skip);
23+
24+
return [
25+
'tasks' => $tasks,
26+
'total' => $data['total'],
27+
'previous' => $data['previous'],
28+
'next' => $data['next'],
29+
];
30+
}
31+
32+
public function taskCreate($data)
33+
{
34+
return self::post("me/outlook/tasks", $data);
35+
}
36+
37+
public function taskGet($id)
38+
{
39+
return self::get("me/outlook/tasks/$id");
40+
}
41+
42+
public function taskUpdate($id, $data)
43+
{
44+
return self::patch("me/outlook/tasks/$id", $data);
45+
}
46+
47+
public function taskDelete($id)
48+
{
49+
return self::delete("me/outlook/tasks/$id");
50+
}
51+
}

src/MsGraph.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
use DaveismynameLaravel\MsGraph\Facades\MsGraph as Api;
1010
use DaveismynameLaravel\MsGraph\Api\Contacts;
11+
use DaveismynameLaravel\MsGraph\Api\Drive;
1112
use DaveismynameLaravel\MsGraph\Api\Emails;
13+
use DaveismynameLaravel\MsGraph\Api\ToDo;
1214
use DaveismynameLaravel\MsGraph\Models\MsGraphToken;
1315

1416
use League\OAuth2\Client\Provider\GenericProvider;
@@ -19,7 +21,9 @@
1921
class MsGraph
2022
{
2123
use Contacts;
24+
use Drive;
2225
use Emails;
26+
use ToDo;
2327

2428
/**
2529
* Set the base url that all API requests use
@@ -214,4 +218,36 @@ protected function guzzle($type, $request, $data = [], $id)
214218
}
215219
}
216220

221+
protected function getPagination($data, $offset = 0)
222+
{
223+
$total = null;
224+
$previous = null;
225+
$next = null;
226+
227+
if (isset($data['@odata.count'])) {
228+
$total = $data['@odata.count'];
229+
}
230+
231+
if (isset($data['@odata.nextLink'])) {
232+
$first = explode('$skip=', $data['@odata.nextLink']);
233+
$skip = explode('&', $first[1]);
234+
$previous = $skip[0]-$offset;
235+
$next = $skip[0];
236+
237+
if ($previous < 0) {
238+
$previous = 0;
239+
}
240+
241+
if ($next == $total) {
242+
$next = null;
243+
}
244+
}
245+
246+
return [
247+
'total' => $total,
248+
'previous' => $previous,
249+
'next' => $next
250+
];
251+
}
252+
217253
}

0 commit comments

Comments
 (0)