Qore SalesforceRestClient Module Reference 2.0
Loading...
Searching...
No Matches
SalesforceRestClient.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* SalesforceRestClient.qm Copyright (C) 2016 - 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
183const BulkJobQuery = "query";
184
186const BulkJobInsert = "insert";
187
189const BulkJobUpdate = "update";
190
192const BulkJobUpsert = "upsert";
193
195const BulkJobDelete = "delete";
197
199
207 BulkJobQuery: True,
208 BulkJobInsert: True,
209 BulkJobUpdate: True,
210 BulkJobUpsert: True,
211 BulkJobDelete: True,
212};
213
218const BulkJobCsv = "CSV";
219
221const BulkJobJson = "JSON";
222
224const BulkJobXml = "XML";
225
227const BulkJobZipCsv = "ZIP_CSV";
228
230const BulkJobZipJson = "ZIP_JSON";
231
233const BulkJobZipXml = "ZIP_XML";
235
237
246 BulkJobCsv: MimeTypeCsv,
247 BulkJobJson: MimeTypeJson,
248 BulkJobXml: MimeTypeXmlApp,
249 BulkJobZipCsv: "zip/csv",
250 BulkJobZipJson: "zip/json",
251 BulkJobZipXml: "zip/xml",
252};
253
255
301
302public:
304 const Defaults = {
305 "oauth_url_auth": "https://login.salesforce.com/services/oauth2/authorize",
306 "oauth_url_token": "https://login.salesforce.com/services/oauth2/token",
307 "oauth_url_revoke": "https://login.salesforce.com/services/oauth2/revoke",
308 "api": "auto",
309 "oauth2_grant_type": "password",
310 };
311
313 const DefaultSendEncoding = "gzip";
314
316 const RequiredOptions = ...;
317
318
320 const AsyncDataloadNs = "http://www.force.com/2009/06/asyncapi/dataload";
321
323 const JobInfoAttributes = {
324 "^attributes^": {
325 "xmlns": AsyncDataloadNs,
326 },
327 };
328
329protected:
332
335
338
340 Mutex m();
341
343 string client_id;
344
347
349 string api;
350
352 string api_used;
353
356
358 hash<string, hash<auto>> api_hash;
359
360public:
361
363
421 constructor(*hash<auto> opts, *softbool do_not_connect) ;
422
423
425
465 hash<auto> patch(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
466
467
469
512 hash<auto> doRequest(string m, string path, auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
513
514
516
561 hash<auto> doBulkRequest(string m, string path, auto body, *reference<hash<auto>> info, softbool decode_errors = True, *hash<auto> hdr);
562
563
565
607 hash<auto> bulkGet(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
608
609
611
653 hash<auto> bulkPost(string path, auto body, *reference<hash<auto>> info, *hash<auto> hdr);
654
655
657
688 hash<auto> bulkJobCreate(string operation, string object, string job_content_type, *reference<hash<auto>> info, *hash<auto> hdr);
689
690
692
723 hash<auto> bulkJobAddBatch(string jobid, data batch_data, string job_content_type, *reference<hash<auto>> info, *hash<auto> hdr);
724
725
727
752 hash<auto> bulkJobClose(string jobid, *reference<hash<auto>> info, *hash<auto> hdr);
753
754
756
772 login(*reference<hash<auto>> info);
773
774
776
797 logout(*reference<hash<auto>> info);
798
799
801 *string getApi();
802
803
805 *hash<string, hash<auto>> getApis();
806
807
809
811 checkClientOptions(hash<auto> opts);
812
813
815 processApis(*list<auto> apis);
816
817
820
821
823
829 static string getBulkDate(date d);
830
832 static string getGmtDate(date d);
833
835
837protected:
839public:
840
841
843
845protected:
846 setOAuth2LoginInfo(hash<auto> h);
847public:
848
849
851protected:
852 static hash getOptions(*hash<auto> opts);
853public:
854
855
857protected:
858 checkLogin(*reference<hash<auto>> info);
859public:
860
861
863protected:
864 hash<auto> loginIntern(*reference<hash> info);
865public:
866
867
869
871protected:
872 *hash<auto> getUpdateOptionsAfterLogin(hash<auto> h);
873public:
874
875
877
879protected:
880 *hash<auto> getOAuth2AuthHeaders();
881public:
882
883};
884
886
902
903public:
905 const ConnectionScheme = <ConnectionSchemeInfo>{
906 "cls": Class::forName("SalesforceRestConnection"),
907 "options": RestConnection::ConnectionScheme.options - (keys OAuth2DifferentOptionMap) + {
908 "api": <ConnectionOptionInfo>{
909 "type": "string",
910 "desc": "the Salesforce API to use; use `auto` (the default) to use the latest API version",
911 "default_value": SalesforceRestClient::Defaults.api,
912 },
913 "client_id": RestConnection::ConnectionScheme.options.oauth2_client_id + <ConnectionOptionInfo>{
914 "desc": "The OAuth2 client_id and also the Salesforce \"consumer key\" for the Connected App",
915 },
916 "client_secret": RestConnection::ConnectionScheme.options.oauth2_client_secret + <ConnectionOptionInfo>{
917 "desc": "The OAuth2 client_secret and also the Salesforce \"consumer secret\" for the Connected "
918 "App",
919 "sensitive": True,
920 },
921 "data": RestConnection::ConnectionScheme.options."data" + <ConnectionOptionInfo>{
922 "default_value": "json",
923 },
924 "instance_url": <ConnectionOptionInfo>{
925 "type": "string",
926 "desc": "the Salesforce.com instance URL returned in the OAuth2 login process",
927 },
928 "oauth_url_auth": RestConnection::ConnectionScheme.options.oauth2_auth_url + <ConnectionOptionInfo>{
929 "default_value": SalesforceRestClient::Defaults.oauth_url_auth,
930 },
931 "oauth_url_token": RestConnection::ConnectionScheme.options.oauth2_token_url + <ConnectionOptionInfo>{
932 "default_value": SalesforceRestClient::Defaults.oauth_url_token,
933 },
934 "oauth_url_revoke": <ConnectionOptionInfo>{
935 "type": "string",
936 "desc": "the OAuth logout / revoke token URL",
937 "default_value": SalesforceRestClient::Defaults.oauth_url_revoke,
938 },
939 "oauth2_grant_type": RestConnection::ConnectionScheme.options.oauth2_grant_type
940 + <ConnectionOptionInfo>{
941 "default_value": SalesforceRestClient::Defaults.oauth2_grant_type,
942 },
943 "oauth2_scopes": RestConnection::ConnectionScheme.options.oauth2_scopes
944 + <ConnectionOptionInfo>{
945 "default_value": SalesforceRestClient::Defaults.oauth2_scopes,
946 },
947 "password": RestConnection::ConnectionScheme.options."password" + <ConnectionOptionInfo>{
948 "desc": "the Salesforce.com password (will override any password in the URL)",
949 "sensitive": True,
950 },
951 "ping_method": RestConnection::ConnectionScheme.options."ping_method" + <ConnectionOptionInfo>{
952 "default_value": "GET",
953 },
954 "ping_path": RestConnection::ConnectionScheme.options."ping_path" + <ConnectionOptionInfo>{
955 "default_value": "/services/data",
956 },
957 "username": RestConnection::ConnectionScheme.options."username" + <ConnectionOptionInfo>{
958 "desc": "the Salesforce.com username (will override any username in the URL)",
959 },
960 },
961 // FIXME: username and password are currently optional for backwards compatibility with URL auth options
962 "required_options": "client_id,client_secret",
963 };
964
967
968
971 "oauth2_auto_refresh": "oauth2_auto_refresh",
972 "oauth2_auth_args": "oauth2_auth_args",
973 "oauth_url_auth": "oauth2_auth_url",
974 "client_id": "oauth2_client_id",
975 "client_secret": "oauth2_client_secret",
976 "oauth2_redirect_url": "oauth2_redirect_url",
977 "oauth2_refresh_token": "oauth2_refresh_token",
978 "oauth2_scopes": "oauth2_scopes",
979 "oauth_url_token": "oauth2_token_url",
980 "password": "password",
981 "username": "username",
982 };
983
985 const OAuth2StandardToSalesforceOptionMap = map {$1.value: $1.key}, OAuth2Options.pairIterator();
986
988 const OAuth2DifferentOptionMap = map {$1.value: $1.key}, OAuth2Options.pairIterator(), $1.key != $1.value;
989
991
999 constructor(string name, string description, string url, hash<auto> attributes = {}, hash<auto> options = {})
1000 ;
1001
1002
1004 string getType();
1005
1006
1008
1013
1014
1016
1021
1022
1024
1026 string getOAuth2OptionName(string opt);
1027
1028
1030
1032 hash<auto> getOAuth2Options();
1033
1034
1036protected:
1037 *hash<auto> processOAuth2TokenResponseImpl(hash<auto> resp);
1038public:
1039
1040
1042protected:
1044public:
1045
1046
1048protected:
1050public:
1051
1052
1054
1059protected:
1060 SalesforceRestClient getImpl(bool connect = True, *hash<auto> rtopts);
1061public:
1062
1063
1065protected:
1066 hash<ConnectionSchemeInfo> getConnectionSchemeInfoImpl();
1067public:
1068
1069
1071
1077
1078};
1079
1081
1084
1085public:
1086protected:
1088 const SPS_GET_APIS = "get-apis";
1089
1090public:
1091
1092 constructor(RestClient rc, hash<auto> real_opts) : RestPingPollOperation(rc, real_opts + {
1093 "url": real_opts.instance_url ?? real_opts.url,
1094 }) {
1095 }
1096
1097protected:
1098 checkOtherStates();
1099public:
1100
1101
1102protected:
1103 gotOAuth2LoginInfo(hash<auto> h);
1104public:
1105
1106
1107protected:
1108 doStartGetApis();
1109public:
1110
1111};
1112};
*hash< auto > getUpdateOptionsAfterLogin(hash< auto > h)
Returns options to update after an OAuth2 login.
constructor(*hash< auto > opts, *softbool do_not_connect)
creates the object with the given options
setOAuth2LoginInfo(hash< auto > h)
Sets options from the OAuth2 login response on the local object.
static string getBulkDate(date d)
returns a date string for use with Salesforce.com Bulk REST API requests
checkLogin(*reference< hash< auto > > info)
Checks if a login is necessary; if so, then the login is performed.
hash< auto > bulkJobAddBatch(string jobid, data batch_data, string job_content_type, *reference< hash< auto > > info, *hash< auto > hdr)
add a batch to a job using the Bulk REST API
login(*reference< hash< auto > > info)
logs in to Salesforce.com with the credentials provided in the constructor()
*hash< auto > getOAuth2AuthHeaders()
Returns headers to use with OAuth2 authorization / token requests.
*string getApi()
returns the Salesforce.com REST API version currently in use
static hash getOptions(*hash< auto > opts)
returns options for the RestClient::constructor()
static string getGmtDate(date d)
returns a date string in GMT for use in Salesforce.com requests
string oauth_url_revoke
Salesforce.com OAuth2 Revoke Token URL.
Definition: SalesforceRestClient.qm.dox.h:337
processApis(*list< auto > apis)
Process the API response from Salesforce and set / verify the client's API level.
string api_used
Salesforce.com REST API version currently in use.
Definition: SalesforceRestClient.qm.dox.h:352
setVerifyApi()
Sets / verifies the api level and sets the application URL accordingly.
logout(*reference< hash< auto > > info)
logs out of Salesforce.com by revoking the access token
hash< auto > bulkGet(string path, auto body, *reference< hash< auto > > info, *hash< auto > hdr)
sends an HTTP GET request to the REST server using the Salesforce.com Bulk REST API and returns the r...
checkClientOptions(hash< auto > opts)
verifies that the options passed match the configured options
hash< string, hash< auto > > api_hash
hash of APIs retrieved from GET /services/data; keyed by API version string; values: "label",...
Definition: SalesforceRestClient.qm.dox.h:358
string client_secret
Salesforce.com "consumer secret".
Definition: SalesforceRestClient.qm.dox.h:346
string client_id
Salesforce.com "consumer key".
Definition: SalesforceRestClient.qm.dox.h:343
hash< auto > bulkPost(string path, auto body, *reference< hash< auto > > info, *hash< auto > hdr)
sends an HTTP POST request to the REST server using the Salesforce.com Bulk REST API and returns the ...
hash< auto > doBulkRequest(string m, string path, auto body, *reference< hash< auto > > info, softbool decode_errors=True, *hash< auto > hdr)
sends a Bulk API REST request to the Salesforce.com server using "rawxml" serialization and returns t...
Mutex m()
Mutex for token acquisition.
const Defaults
defaults for direct member values
Definition: SalesforceRestClient.qm.dox.h:304
string oauth_url_auth
Salesforce.com OAuth2 Authorization URL.
Definition: SalesforceRestClient.qm.dox.h:331
string api
Salesforce.com REST API version to be used ("auto" = latest version)
Definition: SalesforceRestClient.qm.dox.h:349
hash< auto > bulkJobClose(string jobid, *reference< hash< auto > > info, *hash< auto > hdr)
sends a Bulk REST API job close POST request to the server and returns the deserialized result messag...
hash< auto > patch(string path, auto body, *reference< hash< auto > > info, *hash< auto > hdr)
sends an HTTP PATCH request to the Salesforce.com REST server and returns the response; performs an i...
setApi()
Checks the API and sets the final URL.
hash< auto > loginIntern(*reference< hash > info)
performs authentication and authorization with Salesforce.com using the OAuth2 authorization URL
hash< auto > bulkJobCreate(string operation, string object, string job_content_type, *reference< hash< auto > > info, *hash< auto > hdr)
creates a Salesforce.com batch job and returns the job information as a hash
hash< auto > doRequest(string m, string path, auto body, *reference< hash< auto > > info, softbool decode_errors=True, *hash< auto > hdr)
sends an HTTP request to the REST server and returns the response; performs an implicit login to Sale...
string instance_url
The instance URL.
Definition: SalesforceRestClient.qm.dox.h:355
string oauth_url_token
Salesforce.com OAuth2 Get Token URL.
Definition: SalesforceRestClient.qm.dox.h:334
*hash< string, hash< auto > > getApis()
Return available APIs as a hash.
class for Salesforce.com REST connections; returns SalesforceRestClient::SalesforceRestClient objects
Definition: SalesforceRestClient.qm.dox.h:901
SalesforceRestClient getImpl(bool connect=True, *hash< auto > rtopts)
returns a SalesforceRestClient::SalesforceRestClient object
const OAuth2Options
Maps Salesforce REST options to standard options.
Definition: SalesforceRestClient.qm.dox.h:970
const OAuth2AuthRequestOptions
options required to support the OAuth2 authorization code grant flow
Definition: SalesforceRestClient.qm.dox.h:966
constructor(string name, string description, string url, hash< auto > attributes={}, hash< auto > options={})
creates the SalesforceRestConnection connection object
hash< ConnectionSchemeInfo > getConnectionSchemeInfoImpl()
Returns the ConnectionSchemeInfo hash for this object.
Qore::AbstractPollOperation startPollConnect()
Called to start a non-blocking polling ping operation on the remote REST server.
hash< auto > getOAuth2Options()
Returns OAuth2 options in a standard format.
const ConnectionScheme
Connection entry info.
Definition: SalesforceRestClient.qm.dox.h:905
const OAuth2DifferentOptionMap
Different OAuth2 option map; standard name => extern name.
Definition: SalesforceRestClient.qm.dox.h:988
setChildCapabilities()
Sets child data provider capabilities.
*hash< auto > processOAuth2TokenResponseImpl(hash< auto > resp)
Processes OAuth2 login responses and returns updated options.
bool hasDataProvider()
returns True as this connection returns a data provider with the getDataProvider() method
checkAuthCodeFeature()
Sets the auth code feature if supported.
const OAuth2StandardToSalesforceOptionMap
Maps standard option names to Salesforce REST option names.
Definition: SalesforceRestClient.qm.dox.h:985
DataProvider::AbstractDataProvider getDataProvider()
returns a data provider object for this connection
string getOAuth2OptionName(string opt)
Returns the OAuth2 option name for this connection.
REST ping polling I/O class with OAuth2 authentication.
Definition: SalesforceRestClient.qm.dox.h:1083
const SPS_GET_APIS
Get available APIs.
Definition: SalesforceRestClient.qm.dox.h:1088
const BulkJobZipCsv
Salesforce.com bulk job "ZIP_CSV" content type.
Definition: SalesforceRestClient.qm.dox.h:227
const BulkJobCsv
Definition: SalesforceRestClient.qm.dox.h:218
const BulkJobXml
Salesforce.com bulk job "XML" content type.
Definition: SalesforceRestClient.qm.dox.h:224
const BulkJobJson
Salesforce.com bulk job "JSON" content type.
Definition: SalesforceRestClient.qm.dox.h:221
const BulkJobZipJson
Salesforce.com bulk job "ZIP_JSON" content type.
Definition: SalesforceRestClient.qm.dox.h:230
const BulkJobZipXml
Salesforce.com bulk job "ZIP_XML" content type.
Definition: SalesforceRestClient.qm.dox.h:233
const BulkJobQuery
Definition: SalesforceRestClient.qm.dox.h:183
const BulkJobUpsert
Salesforce.com bulk job "upsert" operation.
Definition: SalesforceRestClient.qm.dox.h:192
const BulkJobDelete
Salesforce.com bulk job "delete" operation.
Definition: SalesforceRestClient.qm.dox.h:195
const BulkJobInsert
Salesforce.com bulk job "insert" operation.
Definition: SalesforceRestClient.qm.dox.h:186
const BulkJobUpdate
Salesforce.com bulk job "update" operation.
Definition: SalesforceRestClient.qm.dox.h:189
the SalesforceRestClient namespace contains all the objects in the SalesforceRestClient module
Definition: SalesforceRestClient.qm.dox.h:178
const BulkJobContentTypes
a hash of Salesforce.com bulk job content types; keys are Salesforce.com Bulk REST API Job Content Ty...
Definition: SalesforceRestClient.qm.dox.h:245
const BulkJobOperations
a hash of Salesforce.com bulk job operations; keys are Salesforce.com Bulk REST API Job Operations
Definition: SalesforceRestClient.qm.dox.h:206