forked from microsoftgraph/msgraph-sdk-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.php
More file actions
172 lines (162 loc) · 4.18 KB
/
Graph.php
File metadata and controls
172 lines (162 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
/**
* Copyright (c) Microsoft Corporation. All Rights Reserved.
* Licensed under the MIT License. See License in the project root
* for license information.
*
* Graph File
* PHP version 7
*
* @category Library
* @package Microsoft.Graph
* @copyright 2016 Microsoft Corporation
* @license https://opensource.org/licenses/MIT MIT License
* @version GIT: 0.1.0
* @link https://graph.microsoft.io/
*/
namespace Microsoft\Graph;
use Microsoft\Graph\Core\GraphConstants;
use Microsoft\Graph\Http\GraphCollectionRequest;
use Microsoft\Graph\Http\GraphRequest;
/**
* Class Graph
*
* @category Library
* @package Microsoft.Graph
* @license https://opensource.org/licenses/MIT MIT License
* @link https://graph.microsoft.io/
*/
class Graph
{
/**
* The access_token provided after authenticating
* with Microsoft Graph (required)
*
* @var string
*/
private $_accessToken;
/**
* The api version to use ("v1.0", "beta")
* Default is "v1.0"
*
* @var string
*/
private $_apiVersion;
/**
* The base url to call
* Default is "https://graph.microsoft.com"
*
* @var string
*/
private $_baseUrl;
/**
* The port to use for proxy requests
* Null disables port forwarding
*
* @var string
*/
private $_proxyPort;
/**
* Creates a new Graph object, which is used to call the Graph API
*/
public function __construct()
{
$this->_apiVersion = GraphConstants::API_VERSION;
$this->_baseUrl = GraphConstants::REST_ENDPOINT;
}
/**
* Sets the Base URL to call (defaults to https://graph.microsoft.com)
*
* @param string $baseUrl The URL to call
*
* @return Graph object
*/
public function setBaseUrl($baseUrl)
{
$this->_baseUrl = $baseUrl;
return $this;
}
/**
* Sets the API version to use, e.g. "beta" (defaults to v1.0)
*
* @param string $apiVersion The API version to use
*
* @return Graph object
*/
public function setApiVersion($apiVersion)
{
$this->_apiVersion = $apiVersion;
return $this;
}
/**
* Sets the access token. A valid access token is required
* to run queries against Graph
*
* @param string $accessToken The user's access token, retrieved from
* MS auth
*
* @return Graph object
*/
public function setAccessToken($accessToken)
{
$this->_accessToken = $accessToken;
return $this;
}
/**
* Sets the proxy port. This allows you
* to use tools such as Fiddler to view
* requests and responses made with Guzzle
*
* @param string port The port number to use
*
* @return Graph object
*/
public function setProxyPort($port)
{
$this->_proxyPort = $port;
return $this;
}
/**
* Creates a new request object with the given Graph information
*
* @param string $requestType The HTTP method to use, e.g. "GET" or "POST"
* @param string $endpoint The Graph endpoint to call
*
* @return GraphRequest The request object, which can be used to
* make queries against Graph
* @throws Exception\GraphException
*/
public function createRequest($requestType, $endpoint)
{
return new GraphRequest(
$requestType,
$endpoint,
$this->_accessToken,
$this->_baseUrl,
$this->_apiVersion,
$this->_proxyPort
);
}
/**
* Creates a new collection request object with the given
* Graph information
*
* @param string $requestType The HTTP method to use, e.g. "GET" or "POST"
* @param string $endpoint The Graph endpoint to call
*
* @return GraphCollectionRequest The request object, which can be
* used to make queries against Graph
* @throws Exception\GraphException
*/
public function createCollectionRequest($requestType, $endpoint)
{
return new GraphCollectionRequest(
$requestType,
$endpoint,
$this->_accessToken,
$this->_baseUrl,
$this->_apiVersion,
$this->_proxyPort
);
}
}