Qore CdsRestClient Module Reference 2.0
Loading...
Searching...
No Matches
CdsRestClient.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* CdsRestClient.qm Copyright (C) 2023 Qore Technologies, s.r.o.
5
6 Permission is hereby granted, free of charge, to any person obtaining a
7 copy of this software and associated documentation files (the "Software"),
8 to deal in the Software without restriction, including without limitation
9 the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 and/or sell copies of the Software, and to permit persons to whom the
11 Software is furnished to do so, subject to the following conditions:
12
13 The above copyright notice and this permission notice shall be included in
14 all copies or substantial portions of the Software.
15
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 DEALINGS IN THE SOFTWARE.
23*/
24
25// minimum qore version
26
27// require type definitions everywhere
28
29// enable all warnings
30
31// don't use "$" for vars, members, and methods, assume local variable scope
32
33// do not ignore argument errors
34
35
36
90namespace CdsRestClient {
92
104
105public:
107 const OAuth2BaseUrl = "https://login.microsoftonline.com/";
108
110 const OAuth2AuthUriPathSuffix = "/oauth2/v2.0/authorize";
111
113 const OAuth2TokenUriPathSuffix = "/oauth2/v2.0/token";
114
116 const DefaultApiVersion = "9.2";
117
119 const RequestUriPathPrefix = "/api/data/v";
120
122 const DefaultBusinessCentralBaseUri = "https://api.businesscentral.dynamics.com/";
123
125 const DefaultDynamicsPingMethod = "GET";
126
128 const DefaultDynamicsPingPath = "{api_uri_path}/systemusers?$top=1&$select=identityid";
129
131 const DefaultDynamicsPingHeaders = {
132 "Accept": MimeTypeJson,
133 };
134
136 const ApiProfiles = {
137 "none": {},
138 "dynamics": {
139 "oauth2_scopes": (
140 "offline_access",
141 "{url}.default",
142 ),
143 "ping_method": DefaultDynamicsPingMethod,
144 "ping_path": DefaultDynamicsPingPath,
145 "ping_headers": DefaultDynamicsPingHeaders,
146 },
147 "dynamics-business-central": {
148 "url": DefaultBusinessCentralBaseUri,
149 "oauth2_scopes": (
150 "offline_access",
151 "{url}.default",
152 ),
153 },
154 };
155
156private:
157 string api;
158 string tenant;
159 string uri_path_pfx;
160
161public:
162
164
193 constructor(hash<auto> opts, *softbool do_not_connect) ;
194
195
197 string getApi();
198
199
201 static string getString(hash<auto> opts, string key);
202
204 static raiseError(string fmt);
205
207 static hash<auto> getOptions(hash<auto> opts);
208
210protected:
211 hash<auto> sendAndDecodeResponse(*data body, string m, string path, hash<auto> hdr, *reference<hash<auto>> info, *softbool decode_errors);
212public:
213
214};
215
217
233
234public:
236 const ConnectionScheme = <ConnectionSchemeInfo>{
237 "cls": Class::forName("CdsRestConnection"),
238 "options": RestConnection::ConnectionScheme.options - (keys OAuth2DifferentOptionMap) + {
239 "api": <ConnectionOptionInfo>{
240 "type": "string",
241 "desc": "the API version for CDS",
242 "default_value": CdsRestClient::DefaultApiVersion,
243 },
244 "api_profile": <ConnectionOptionInfo>{
245 "type": "string",
246 "desc": "the API profile according to the CDS API in use; this option will set the REST "
247 "options if they are not already set (`oauth2_scopes`, `ping_body`, `ping_headers`, and "
248 "`ping_method`); valid "
249 "values:\n"
250 "- `none`: no options configured (default)\n"
251 "- `dynamics`: set options for the Dynamics 365 API",
252 "default_value": "none",
253 "allowed_values": (
254 <AllowedValueInfo>{
255 "desc": "No options are set",
256 "value": "none",
257 },
258 <AllowedValueInfo>{
259 "desc": "Set REST client options for the Dynamics 365 API",
260 "value": "dynamics",
261 },
262 /*
263 <AllowedValueInfo>{
264 "desc": "Set REST client options for the Dynamics 365 API",
265 "value": "dynamics-business-central",
266 },
267 */
268 ),
269 },
270 "client_id": RestConnection::ConnectionScheme.options.oauth2_client_id + <ConnectionOptionInfo>{
271 "desc": "the Microsoft Common Data Service OAuth2 client ID",
272 },
273 "client_secret": RestConnection::ConnectionScheme.options.oauth2_client_secret + <ConnectionOptionInfo>{
274 "desc": "the Microsoft Common Data Service OAuth2 client secret",
275 "sensitive": True,
276 },
277 "data": RestConnection::ConnectionScheme.options."data" + <ConnectionOptionInfo>{
278 "default_value": "json",
279 },
280 "oauth2_auth_url": RestConnection::ConnectionScheme.options.oauth2_auth_url + <ConnectionOptionInfo>{
281 "default_value": "auto",
282 },
283 "oauth2_grant_type": RestConnection::ConnectionScheme.options.oauth2_grant_type + <ConnectionOptionInfo>{
284 "default_value": "authorization_code",
285 },
286 "oauth2_token_url": RestConnection::ConnectionScheme.options.oauth2_token_url + <ConnectionOptionInfo>{
287 "default_value": "auto",
288 },
289 "tenant": <ConnectionOptionInfo>{
290 "type": "string",
291 "desc": "the tenant ID",
292 },
293 },
294 "required_options": "client_id,client_secret,tenant",
295 };
296
299
300
303 "oauth2_auto_refresh": "oauth2_auto_refresh",
304 "oauth2_auth_args": "oauth2_auth_args",
305 "oauth2_auth_url": "oauth2_auth_url",
306 "client_id": "oauth2_client_id",
307 "client_secret": "oauth2_client_secret",
308 "oauth2_redirect_url": "oauth2_redirect_url",
309 "oauth2_refresh_token": "oauth2_refresh_token",
310 "oauth2_scopes": "oauth2_scopes",
311 "oauth2_token_url": "oauth2_token_url",
312 "password": "password",
313 "username": "username",
314 };
315
317 const OAuth2StandardToCdsOptionMap = map {$1.value: $1.key}, OAuth2Options.pairIterator();
318
320 const OAuth2DifferentOptionMap = map {$1.value: $1.key}, OAuth2Options.pairIterator(), $1.key != $1.value;
321
323
333 constructor(string name, string description, string url, hash<auto> attributes = {}, hash<auto> options = {})
334 ;
335
336
338 string getType();
339
340
342
347
348
350
352 DataProvider::AbstractDataProvider getDataProvider();
353
354
356
363 string getAuthorizationCodeRequest(hash<AuthCodeInfo> info = <AuthCodeInfo>{});
364
365
367
369 string getOAuth2OptionName(string opt);
370
371
373
375 hash<auto> getOAuth2Options();
376
377
379 /* @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
380 is to return a full URL
381
382 @since %CdsRestClient 2.0
383 */
384 string getAuthUrl(*bool allow_relative);
385
386
388 /* @param allow_relative if @ref True then a relative URL (path only) can be returned; the default (@ref False)
389 is to return a full URL
390
391 @since %CdsRestClient 2.0
392 */
393 string getTokenUrl(*bool allow_relative);
394
395
397protected:
399public:
400
401
403protected:
405public:
406
407
409
414protected:
415 CdsRestClient getImpl(bool connect = True, *hash<auto> rtopts);
416public:
417
418
420protected:
421 hash<ConnectionSchemeInfo> getConnectionSchemeInfoImpl();
422public:
423
424
426protected:
427 static hash<auto> getOptions(string url, hash<auto> orig_opts);
428public:
429
430};
431};
string getApi()
returns the CDS REST API version currently in use
const DefaultApiVersion
Default API version.
Definition: CdsRestClient.qm.dox.h:116
constructor(hash< auto > opts, *softbool do_not_connect)
creates the object with the given options
hash< auto > sendAndDecodeResponse(*data body, string m, string path, hash< auto > hdr, *reference< hash< auto > > info, *softbool decode_errors)
sends the outgoing HTTP message and recodes the response to data
static string getString(hash< auto > opts, string key)
gets a string option
static hash< auto > getOptions(hash< auto > opts)
returns options for the CdsRestClient::CdsRestClient::constructor()
static raiseError(string fmt)
throws an exception due to an error
class for Microsoft Common Data Service REST connections; returns CdsRestClient objects
Definition: CdsRestClient.qm.dox.h:232
string getAuthorizationCodeRequest(hash< AuthCodeInfo > info=< AuthCodeInfo >{})
Returns a URI for an authorization code request.
string getAuthUrl(*bool allow_relative)
Returns the OAuth2 auth URL or throws an exception if not set.
setChildCapabilities()
Sets child data provider capabilities.
DataProvider::AbstractDataProvider getDataProvider()
returns a data provider object for this connection
hash< ConnectionSchemeInfo > getConnectionSchemeInfoImpl()
Returns the ConnectionSchemeInfo hash for this object.
const OAuth2StandardToCdsOptionMap
Maps standard option names to CDS REST option names.
Definition: CdsRestClient.qm.dox.h:317
const ConnectionScheme
Connection entry info.
Definition: CdsRestClient.qm.dox.h:236
const OAuth2Options
Maps CDS REST options to standard options.
Definition: CdsRestClient.qm.dox.h:302
const OAuth2AuthRequestOptions
options required to support the OAuth2 authorization code grant flow
Definition: CdsRestClient.qm.dox.h:298
constructor(string name, string description, string url, hash< auto > attributes={}, hash< auto > options={})
creates the CdsRestConnection object
const OAuth2DifferentOptionMap
Different OAuth2 option map; standard name => extern name.
Definition: CdsRestClient.qm.dox.h:320
bool hasDataProvider()
returns True as this connection returns a data provider with the getDataProvider() method
hash< auto > getOAuth2Options()
Returns OAuth2 options in a standard format.
CdsRestClient getImpl(bool connect=True, *hash< auto > rtopts)
returns a CdsRestClient object
static hash< auto > getOptions(string url, hash< auto > orig_opts)
returns options for GoogleRestConnection::constructor()
checkAuthCodeFeature()
Sets the auth code feature if supported.
string getOAuth2OptionName(string opt)
Returns the OAuth2 option name for this connection.
string getTokenUrl(*bool allow_relative)
Returns the OAuth2 token URL or throws an exception if not set.
string getType()
returns "cdsrest"
the CdsRestClient namespace contains all the objects in the CdsRestClient module
Definition: CdsRestClient.qm.dox.h:90