Qore SalesforceRestClient Module Reference  1.1
 All Classes Namespaces Functions Variables Groups Pages
SalesforceRestClient.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file SalesforceRestClient.qm Qore user module for calling Salesforce.com REST services
3 
4 /* SalesforceRestClient.qm Copyright (C) 2016 - 2017 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 // this module requires Qore 0.8.13 or better
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 
146 namespace SalesforceRestClient {
151  const BulkJobQuery = "query";
153 
155  const BulkJobInsert = "insert";
156 
158  const BulkJobUpdate = "update";
159 
161  const BulkJobUpsert = "upsert";
162 
164  const BulkJobDelete = "delete";
166 
168 
181  );
182 
186  const BulkJobCsv = "CSV";
188 
190  const BulkJobJson = "JSON";
191 
193  const BulkJobXml = "XML";
194 
196  const BulkJobZipCsv = "ZIP_CSV";
197 
199  const BulkJobZipJson = "ZIP_JSON";
200 
202  const BulkJobZipXml = "ZIP_XML";
204 
206 
218  BulkJobZipCsv: "zip/csv",
219  BulkJobZipJson: "zip/json",
220  BulkJobZipXml: "zip/xml",
221  );
222 
224 
270 
271 public:
272  public :
274  const Defaults = (
275  "oauth_url_auth": "https://login.salesforce.com/services/oauth2/authorize",
276  "oauth_url_token": "https://login.salesforce.com/services/oauth2/token",
277  "oauth_url_revoke": "https://login.salesforce.com/services/oauth2/revoke",
278  "api": "auto",
279  );
280 
282  const DefaultSendEncoding = "gzip";
283 
285  const RequiredOptions = (
286  // the Salesforce.com "consumer key"
287  "client_id",
288  // the Salesforce.com "consumer secret"
289  "client_secret",
290  // the Salesforce.com username
291  "username",
292  // the Salesforce.com password
293  "password",
294  );
295 
297  const AsyncDataloadNs = "http://www.force.com/2009/06/asyncapi/dataload";
298 
301  "^attributes^": (
302  "xmlns": AsyncDataloadNs,
303  ),
304  );
305 
306 public:
307 
308  private :
311 
314 
317 
319  Mutex m();
320 
322  string token;
323 
325  string client_id;
326 
329 
331  string username;
332 
334  string password;
335 
337  string api;
338 
340  string api_used;
341 
344 
345 public:
346 
348 
381  constructor(*hash opts, *softbool do_not_connect) ;
382 
383 
385 
419  hash patch(string path, auto body, *reference<hash> info, *hash hdr);
420 
421 
423 
460  hash doRequest(string m, string path, auto body, *reference<hash> info, softbool decode_errors = True, *hash hdr);
461 
462 
464 
503  hash doBulkRequest(string m, string path, auto body, *reference<hash> info, softbool decode_errors = True, *hash hdr);
504 
505 
507 
543  hash bulkGet(string path, auto body, *reference<hash> info, *hash hdr);
544 
545 
547 
583  hash bulkPost(string path, auto body, *reference<hash> info, *hash hdr);
584 
585 
587 
616  hash bulkJobCreate(string operation, string object, string job_content_type, *reference<hash> info, *hash hdr);
617 
618 
620 
649  hash bulkJobAddBatch(string jobid, data batch_data, string job_content_type, *reference<hash> info, *hash hdr);
650 
651 
653 
676  hash bulkJobClose(string jobid, *reference<hash> info, *hash hdr);
677 
678 
680 
694  login(*reference<hash> info);
695 
696 
698 
717  logout(*reference<hash> info);
718 
719 
721  string getApi();
722 
723 
725  *string getToken();
726 
727 
729 
735  static string getBulkDate(date d);
736 
738  static string getGmtDate(date d);
739 
741 
742 private:
743  static hash getOptions(*hash opts);
744 public:
745 
746 
748 
751 private:
752  loginIntern(*reference<hash> info);
753 public:
754 
755  };
756 
758 
776 
777 public:
778  public :
780  const Options = RestConnection::Options + (
781  "api": True,
782  "client_id": True,
783  "client_secret": True,
784  );
785 
786  const OptionList = Options.keys();
787 
788 public:
789 
791 
798  constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh) ;
799 
800 
802 
808 private:
809  SalesforceRestClient getImpl(bool connect = True, *hash rtopts);
810 public:
811 
812 
814 
829  hash getOptions();
830 
831 
834 
835 
837  string getType();
838 
839 
841  static SalesforceRestConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh);
842  };
843 };
login(*reference< hash > info)
logs in to Salesforce.com with the credentials provided in the constructor()
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
creates the SalesforceRestConnection object
date date(date dt)
hash bulkJobCreate(string operation, string object, string job_content_type, *reference< hash > info, *hash hdr)
creates a Salesforce.com batch job and returns the job information as a hash
string oauth_url_revoke
Salesforce.com OAuth2 Revoke Token URL.
Definition: SalesforceRestClient.qm.dox.h:316
hash patch(string path, auto body, *reference< hash > info, *hash hdr)
sends an HTTP PATCH request to the Salesforce.com REST server and returns the response; performs an i...
const DefaultSendEncoding
default send encoding
Definition: SalesforceRestClient.qm.dox.h:282
Mutex m()
Mutex for token acquisition.
hash doBulkRequest(string m, string path, auto body, *reference< hash > info, softbool decode_errors=True, *hash hdr)
sends a Bulk API REST request to the Salesforce.com server using &quot;rawxml&quot; serialization and returns t...
const BulkJobCsv
Salesforce.com bulk job &quot;CSV&quot; content type.
Definition: SalesforceRestClient.qm.dox.h:187
const RequiredOptions
required options
Definition: SalesforceRestClient.qm.dox.h:285
this class provides the REST client API for communication with Salesforce.com
Definition: SalesforceRestClient.qm.dox.h:269
const True
const JobInfoAttributes
Salesforce.com XML jobInfo attributes.
Definition: SalesforceRestClient.qm.dox.h:300
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:214
static string getGmtDate(date d)
returns a date string in GMT for use in Salesforce.com requests
const BulkJobXml
Salesforce.com bulk job &quot;XML&quot; content type.
Definition: SalesforceRestClient.qm.dox.h:193
string getType()
returns &quot;rest&quot;
hash bulkPost(string path, auto body, *reference< hash > info, *hash hdr)
sends an HTTP POST request to the REST server using the Salesforce.com Bulk REST API and returns the ...
logout(*reference< hash > info)
logs out of Salesforce.com by revoking the access token
const Defaults
defaults for direct member values
Definition: SalesforceRestClient.qm.dox.h:274
const MimeTypeJson
hash doRequest(string m, string path, auto body, *reference< hash > info, softbool decode_errors=True, *hash hdr)
sends an HTTP request to the REST server and returns the response; performs an implicit login to Sale...
string client_id
Salesforce.com &quot;consumer key&quot;.
Definition: SalesforceRestClient.qm.dox.h:325
const BulkJobZipCsv
Salesforce.com bulk job &quot;ZIP_CSV&quot; content type.
Definition: SalesforceRestClient.qm.dox.h:196
const BulkJobOperations
a hash of Salesforce.com bulk job operations; keys are Salesforce.com Bulk REST API Job Operations ...
Definition: SalesforceRestClient.qm.dox.h:175
const BulkJobZipXml
Salesforce.com bulk job &quot;ZIP_XML&quot; content type.
Definition: SalesforceRestClient.qm.dox.h:202
SalesforceRestClient getImpl(bool connect=True, *hash rtopts)
returns a SalesforceRestClient::SalesforceRestClient object
hash bulkJobClose(string jobid, *reference< hash > info, *hash hdr)
sends a Bulk REST API job close POST request to the server and returns the deserialized result messag...
static SalesforceRestConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
static constructor
const BulkJobUpdate
Salesforce.com bulk job &quot;update&quot; operation.
Definition: SalesforceRestClient.qm.dox.h:158
*hash getDefaultOptions()
returns default options
string oauth_url_auth
Salesforce.com OAuth2 Authorization URL.
Definition: SalesforceRestClient.qm.dox.h:310
static string getBulkDate(date d)
returns a date string for use with Salesforce.com Bulk REST API requests
hash api_hash
hash of APIs retrieved from GET /services/data; keyed by API version string; values: &quot;label&quot;...
Definition: SalesforceRestClient.qm.dox.h:343
const BulkJobUpsert
Salesforce.com bulk job &quot;upsert&quot; operation.
Definition: SalesforceRestClient.qm.dox.h:161
const BulkJobDelete
Salesforce.com bulk job &quot;delete&quot; operation.
Definition: SalesforceRestClient.qm.dox.h:164
const BulkJobQuery
Salesforce.com bulk job &quot;query&quot; operation.
Definition: SalesforceRestClient.qm.dox.h:152
loginIntern(*reference< hash > info)
performs authentication and authorization with Salesforce.com using the OAuth2 authorization URL ...
*string getToken()
returns the access token
const BulkJobInsert
Salesforce.com bulk job &quot;insert&quot; operation.
Definition: SalesforceRestClient.qm.dox.h:155
const BulkJobJson
Salesforce.com bulk job &quot;JSON&quot; content type.
Definition: SalesforceRestClient.qm.dox.h:190
string username
Salesforce.com username.
Definition: SalesforceRestClient.qm.dox.h:331
const AsyncDataloadNs
Salesforce.com async dataload namespace.
Definition: SalesforceRestClient.qm.dox.h:297
string getApi()
returns the Salesforce.com REST API version currently in use
string token
Salesforce.com token.
Definition: SalesforceRestClient.qm.dox.h:322
static hash getOptions(*hash opts)
returns options for the RestClient::constructor()
class for Salesforce.com REST connections; returns SalesforceRestClient::SalesforceRestClient objects...
Definition: SalesforceRestClient.qm.dox.h:775
string client_secret
Salesforce.com &quot;consumer secret&quot;.
Definition: SalesforceRestClient.qm.dox.h:328
hash bulkJobAddBatch(string jobid, data batch_data, string job_content_type, *reference< hash > info, *hash hdr)
add a batch to a job using the Bulk REST API
const Options
SalesforceRestConnection object connection options.
Definition: SalesforceRestClient.qm.dox.h:780
hash bulkGet(string path, auto body, *reference< hash > info, *hash hdr)
sends an HTTP GET request to the REST server using the Salesforce.com Bulk REST API and returns the r...
hash hash(object obj)
string password
Salesforce.com password.
Definition: SalesforceRestClient.qm.dox.h:334
string api
Salesforce.com REST API version to be used (&quot;auto&quot; = latest version)
Definition: SalesforceRestClient.qm.dox.h:337
const BulkJobZipJson
Salesforce.com bulk job &quot;ZIP_JSON&quot; content type.
Definition: SalesforceRestClient.qm.dox.h:199
const MimeTypeXmlApp
const MimeTypeCsv
string api_used
Salesforce.com REST API version currently in use.
Definition: SalesforceRestClient.qm.dox.h:340
string oauth_url_token
Salesforce.com OAuth2 Get Token URL.
Definition: SalesforceRestClient.qm.dox.h:313