Skip to content

Commit 57851ad

Browse files
initial commit
0 parents  commit 57851ad

File tree

13 files changed

+525
-0
lines changed

13 files changed

+525
-0
lines changed

changelog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
3+
All notable changes to `MsGraph` will be documented in this file.
4+
5+
## Version 1.0
6+
7+
### Added
8+
- Everything

composer.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "daveismynamelaravel/msgraph",
3+
"description": "A Laravel Microsoft Graph API package",
4+
"license": "MIT",
5+
"authors": [
6+
{
7+
"name": "David Carr",
8+
"email": "dave@daveismyname.com",
9+
"homepage": "https://daveismyname.blog"
10+
}
11+
],
12+
"homepage": "https://github.com/daveismynamelaravel/box",
13+
"keywords": ["Laravel", "MsGraph", "Graph"],
14+
"require": {
15+
"illuminate/support": "~5",
16+
"league/oauth2-client": "^1.4",
17+
"guzzlehttp/guzzle": "^6",
18+
},
19+
"require-dev": {
20+
"phpunit/phpunit": "~6.0",
21+
"orchestra/testbench": "~3.0"
22+
},
23+
"autoload": {
24+
"psr-4": {
25+
"DaveismynameLaravel\\MsGraph\\": "src/"
26+
}
27+
},
28+
"extra": {
29+
"laravel": {
30+
"providers": [
31+
"DaveismynameLaravel\\MsGraph\\MsGraphServiceProvider"
32+
],
33+
"aliases": {
34+
"MsGraph": "DaveismynameLaravel\\MsGraph\\Facades\\MsGraph"
35+
}
36+
}
37+
}
38+
}

config/msgraph.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
return [
4+
'clientId' => env('MSGRAPH_CLIENT_ID'),
5+
'clientSecret' => env('MSGRAPH_SECRET_ID'),
6+
'redirectUri' => url('msgraph/oauth'),
7+
'msgraphLandingUri' => url('msgraph'),
8+
'urlAuthorize' => 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
9+
'urlAccessToken' => 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
10+
'scopes' => 'offline_access openid calendars.readwrite contacts.readwrite files.readwrite mail.readwrite mail.send tasks.readwrite mailboxsettings.readwrite user.readwrite',
11+
'preferTimezone' => env('MSGRAPH_PREFER_TIMEZONE', 'outlook.timezone="Europe/London"'),
12+
];

contributing.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Contributing
2+
3+
Contributions are welcome and will be fully credited.
4+
5+
Contributions are accepted via Pull Requests on [Github](https://github.com/daveismynamelaravel/box).
6+
7+
# Things you could do
8+
If you want to contribute but do not know where to start, this list provides some starting points.
9+
- Set up TravisCI, StyleCI, ScrutinizerCI
10+
- Write a comprehensive ReadMe
11+
12+
## Pull Requests
13+
14+
- **Document any change in behaviour** - Make sure the `readme.md` and any other relevant documentation are kept up-to-date.
15+
16+
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
17+
18+
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
19+
20+
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
21+
22+
23+
**Happy coding**!

license.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# The license
2+
3+
The MIT License (MIT)
4+
5+
Copyright (c) 2018 Daveismyname
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.

readme.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Box
2+
3+
A Laravel package for working with Microsoft Graph API, this includes authentication use Oauth2.
4+
5+
## Installation
6+
7+
Via Composer
8+
9+
``` bash
10+
$ composer require daveismynamelaravel/msgraph
11+
```
12+
13+
TO Document:
14+
* run migration,
15+
* Publish config
16+
* Edit config
17+
* Add ENV variables
18+
19+
## Usage
20+
21+
A routes example:
22+
23+
```
24+
use DaveismynameLaravel\MsGraph\Facades\MsGraph;
25+
26+
Route::group(['middleware' => ['web', 'auth']], function(){
27+
Route::get('msgraph', function(){
28+
29+
if (!is_string(MsGraph::getAccessToken())) {
30+
return redirect('msgraph/oauth');
31+
} else {
32+
//box folders and file list
33+
return MsGraph::folders();
34+
}
35+
});
36+
37+
Route::get('msgraph/oauth', function(){
38+
return MsGraph::connect();
39+
});
40+
});
41+
```
42+
43+
## Change log
44+
45+
Please see the [changelog](changelog.md) for more information on what has changed recently.
46+
47+
48+
## Contributing
49+
50+
Please see [contributing.md](contributing.md) for details and a todolist.
51+
52+
## Security
53+
54+
If you discover any security related issues, please email author email instead of using the issue tracker.
55+
56+
## Credits
57+
58+
- [David Carr][dave@daveismyname.com]
59+
60+
## License
61+
62+
license. Please see the [license file](license.md) for more information.

src/Api/Contacts.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace DaveismynameLaravel\MsGraph\Api;
4+
5+
trait Contacts {
6+
7+
public function contacts($limit = 25, $offset = 0, $skip = 0)
8+
{
9+
//$limit = 25;
10+
//$offset = 50;
11+
$skip = request('next', $skip);
12+
13+
$messageQueryParams = array (
14+
"\$orderby" => "displayName",
15+
"\$skip" => $skip,
16+
"\$top" => $limit,
17+
"\$count" => "true",
18+
);
19+
20+
$contacts = self::get('me/contacts?'.http_build_query($messageQueryParams));
21+
22+
$total = $contacts['@odata.count'];
23+
$previous = null;
24+
$next = null;
25+
if (isset($contacts['@odata.nextLink'])) {
26+
$first = explode('$skip=', $contacts['@odata.nextLink']);
27+
$skip = explode('&', $first[1]);
28+
$previous = $skip[0]-$offset;
29+
$next = $skip[0];
30+
31+
if ($previous < 0) {
32+
$previous = 0;
33+
}
34+
35+
if ($next == $total) {
36+
$next = null;
37+
}
38+
}
39+
40+
return [
41+
'contacts' => $contacts,
42+
'total' => $total,
43+
'previous' => $previous,
44+
'next' => $next,
45+
];
46+
}
47+
}

src/Facades/MsGraph.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace DaveismynameLaravel\MsGraph\Facades;
4+
5+
use Illuminate\Support\Facades\Facade;
6+
7+
class MsGraph extends Facade
8+
{
9+
/**
10+
* Get the registered name of the component.
11+
*
12+
* @return string
13+
*/
14+
protected static function getFacadeAccessor()
15+
{
16+
return 'msgraph';
17+
}
18+
}

src/Models/MsGraphToken.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace DaveismynameLaravel\MsGraph\Models;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
7+
class MsGraphToken extends Model
8+
{
9+
protected $guarded = [];
10+
}

0 commit comments

Comments
 (0)