Salesforce.com interface to directly access Salesforce.com

Dependencies:   HTTPClient-SSL MbedJSONValue

Dependents:   df-2014-salesforce-hrm-k64f

Fork of SalesforceInterface by Doug Anson

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SalesforceInterface.h Source File

SalesforceInterface.h

00001 /* Copyright C2014 ARM, MIT License
00002  *
00003  * Author: Doug Anson (doug.anson@arm.com)
00004  *
00005  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00006  * and associated documentation files the "Software", to deal in the Software without restriction,
00007  * including without limitation the rights to use, copy, modify, merge, publish, distribute,
00008  * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
00009  * furnished to do so, subject to the following conditions:
00010  *
00011  * The above copyright notice and this permission notice shall be included in all copies or
00012  * substantial portions of the Software.
00013  *
00014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00015  * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00016  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00017  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00018  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00019  */
00020  
00021  #ifndef _SALESFORCE_INTERFACE_H_
00022  #define _SALESFORCE_INTERFACE_H_
00023  
00024  // Logger
00025  #include "Logger.h"
00026  
00027  // SSL-based HTTP support
00028  #include "HTTPClient.h"
00029  
00030  // JSON parsing support
00031  #include "MbedJSONValue.h"
00032   
00033  // convenience macros
00034  #define  DEFINE_BUFFER(x)              char x[MAX_BUFFER_LENGTH+1]
00035  #define  RESET_BUFFER(x)               memset(x,0,MAX_BUFFER_LENGTH+1)
00036  #define  ALLOC_BUFFER(x)               DEFINE_BUFFER(x);RESET_BUFFER(x)
00037  
00038  #define  DEFINE_SML_BUFFER(x)          char x[MAX_SMALL_BUFFER_LENGTH+1]
00039  #define  RESET_SML_BUFFER(x)           memset(x,0,MAX_SMALL_BUFFER_LENGTH+1)
00040  #define  ALLOC_SML_BUFFER(x)           DEFINE_SML_BUFFER(x);RESET_SML_BUFFER(x)
00041  
00042  // Default salesforce API version (must be in XX.Y format and must be a string)
00043  #define SALESFORCE_API_VERSION_LENGTH  10
00044  #ifndef SALESFORCE_API_VERSION
00045     #define SALESFORCE_API_VERSION      "28.0"
00046  #endif
00047  
00048  // verbose debugging within SalesforceInterface
00049  #if ENABLE_DEBUG_LOGGING
00050     #define DEBUG(...)                  { LOG_CONSOLE(__VA_ARGS__); }
00051  #else
00052     #define DEBUG(...)                  { ; }
00053  #endif 
00054  
00055  // HTTP Verbs
00056  typedef enum {
00057      GET,
00058      PUT,
00059      POST,
00060      DELETE,
00061      NUM_VERBS
00062  } HttpVerb;
00063  
00064  // Supported input data types for PUT and POST (Defined by HTTPClient-SSL/data support...)
00065  typedef enum {
00066      JSON,              // ContentType: application/json
00067      PLAIN_TEXT,        // ContentType: plain/text
00068      FORM_MAPPED,       // ContentType: application/x-www-form-urlencoded
00069      NUM_TYPES
00070  } InputDataTypes;
00071  
00072  // OAUTH structure
00073  typedef struct {
00074      bool   valid;
00075      string id;
00076      string issued_at;
00077      string token_type;
00078      string instance_url;
00079      string signature;
00080      string access_token;
00081  } OauthToken;
00082  
00083  /**
00084  * Salesforce Interface 
00085  * SalesforceInterface provides a simple C++ API into the REST-based Salesforce.com APIs
00086  *
00087  * Example Project: http://mbed.org/users/ansond/code/df-2014-salesforce-testharness-k64f/ 
00088  *
00089  * @code
00090  
00091  #include "Definitions.h"       // definitions including platform specifics...
00092  #include "Logger.h"
00093  
00094  // include salesforce.com credentials
00095  #include "sf_creds.h"
00096  
00097  // our Serial port
00098  #include "BufferedSerial.h"
00099  BufferedSerial pc(USBTX, USBRX);
00100  
00101  // Ethernet
00102  #include "EthernetInterface.h"
00103  EthernetInterface ethernet;
00104  
00105  // HTTP 
00106  #include "HTTPClient.h"
00107  HTTPClient http;
00108  
00109  // Salesforce.com Interface
00110  #include "SalesforceInterface.h"
00111   
00112  // test case persistence
00113  char *object_name = NULL;
00114  char *account_name = NULL;
00115  char *updated_account_name = NULL;
00116  char *external_id_field_name = NULL;
00117  char *external_id_field_value = NULL;
00118  DEFINE_SML_BUFFER(record_id);
00119     
00120  // *************** Test Cases ************************
00121  
00122  void Test_getSalesforceToken(Logger *logger,SalesforceInterface *sf) {
00123      logger->log("\r\n\r\nGetting Salesforce Token...");
00124      logger->turnLEDPurple();
00125      
00126      // get the salesforce token     
00127      char *id = sf->getSalesforceToken();
00128      if (id != NULL && strlen(id) > 0)
00129          logger->log("Saleforce token: %s",id);
00130      else
00131          logger->log("Unable to get Saleforce token");
00132      logger->turnLEDGreen();
00133  }
00134  
00135  void Test_query(Logger *logger,SalesforceInterface *sf,char *query_str) {
00136      logger->log("\r\n\r\nExecuting test query: %s",query_str);
00137      logger->turnLEDPurple();
00138      if (query_str != NULL && strlen(query_str) > 0) { 
00139          ALLOC_BUFFER(response);
00140          char *answer = sf->query(query_str,response,MAX_BUFFER_LENGTH);
00141          if (answer != NULL) logger->log("query result: %s",answer);
00142          else logger->log("query - NULL result");
00143      }
00144      else {
00145         logger->log("Unable to perform query as we do not have our salesforce token");
00146      }
00147      logger->turnLEDGreen();
00148  }
00149  
00150  void Test_create(Logger *logger,SalesforceInterface *sf) {
00151      logger->log("\r\n\r\nExecuting create()");
00152      logger->turnLEDPurple();
00153      
00154      // create a new record
00155      MbedJSONValue new_record;
00156      new_record["name"] = account_name;
00157      
00158      // DEBUG
00159      logger->log("Create: new record: %s",new_record.serialize().c_str());
00160      
00161      // create...
00162      MbedJSONValue response = sf->createRecord(object_name,new_record);
00163      
00164      // display the result
00165      char *result = (char *)response.serialize().c_str();
00166      if (result != NULL && strlen(result) > 0 && strcmp(result,"null") != 0) {
00167         // save off the token if we succeeded
00168         logger->log("Create: result: %s",result);
00169         logger->log("Create: http_code=%d",sf->httpResponseCode());
00170         RESET_SML_BUFFER(record_id);
00171         strcpy(record_id,(char *)response["id"].get<std::string>().c_str());
00172      }
00173      else {
00174         // failure
00175         logger->log("Create: FAILED http_code=%d",sf->httpResponseCode());
00176      }
00177      logger->turnLEDGreen();
00178  }
00179  
00180  void Test_read(Logger *logger,SalesforceInterface *sf) {
00181      logger->log("\r\n\r\nExecuting read()");
00182      logger->turnLEDPurple();
00183           
00184      // DEBUG
00185      logger->log("Read: reading: %s from %s",record_id,object_name);
00186      
00187      // read...
00188      MbedJSONValue response = sf->readRecord(object_name,record_id);
00189      
00190      // display the result
00191      char *result = (char *)response.serialize().c_str();
00192      if (result != NULL && strlen(result) > 0 && strcmp(result,"null") != 0) {
00193         // save off the token if we succeeded
00194         logger->log("Read: result: %s",result);
00195         logger->log("Read: http_code=%d",sf->httpResponseCode());
00196      }
00197      else {
00198         // failure
00199         logger->log("Read: FAILED http_code=%d",sf->httpResponseCode());
00200      }
00201      
00202      logger->turnLEDGreen();
00203  }
00204  
00205  void Test_create_external_id(Logger *logger,SalesforceInterface *sf) {
00206      logger->log("\r\n\r\nExecuting create(ExternalID)");
00207      logger->turnLEDPurple();
00208      
00209      // create a new record
00210      MbedJSONValue new_record;
00211      new_record[external_id_field_name] = external_id_field_value;
00212      
00213      // DEBUG
00214      logger->log("create(ExternalID): new record: %s",new_record.serialize().c_str());
00215      
00216      // create...
00217      MbedJSONValue response = sf->createRecord(object_name,new_record);
00218      
00219      // display the result
00220      char *result = (char *)response.serialize().c_str();
00221      if (result != NULL && strlen(result) > 0 && strcmp(result,"null") != 0) {
00222         // save off the token if we succeeded
00223         logger->log("create(ExternalID): result: %s",result);
00224         logger->log("create(ExternalID): http_code=%d",sf->httpResponseCode());
00225         RESET_SML_BUFFER(record_id);
00226         strcpy(record_id,(char *)response["id"].get<std::string>().c_str());
00227      }
00228      else {
00229         // failure
00230         logger->log("create(ExternalID): FAILED http_code=%d",sf->httpResponseCode());
00231      }
00232      logger->turnLEDGreen();
00233  }
00234  
00235  void Test_read_by_external_id_and_value(Logger *logger,SalesforceInterface *sf) {
00236      logger->log("\r\n\r\nExecuting read(externalID)...");
00237      logger->turnLEDPurple();
00238           
00239      // DEBUG
00240      logger->log("read(externalID): reading: %s from %s with value %s",object_name,external_id_field_name,external_id_field_value);
00241      
00242      // read (external ID)...
00243      MbedJSONValue response = sf->readRecord(object_name,external_id_field_name,external_id_field_value);
00244      
00245      // display the result
00246      char *result = (char *)response.serialize().c_str();
00247      if (result != NULL && strlen(result) > 0 && strcmp(result,"null") != 0) {
00248         // save off the token if we succeeded
00249         logger->log("read(externalID): result: %s",result);
00250         logger->log("read(externalID): http_code=%d",sf->httpResponseCode());
00251      }
00252      else {
00253         // failure
00254         logger->log("read(externalID): FAILED http_code=%d",sf->httpResponseCode());
00255      }
00256      
00257      logger->turnLEDGreen();
00258  }
00259  
00260  void Test_update(Logger *logger,SalesforceInterface *sf) {
00261      logger->log("\r\n\r\nExecuting update()");
00262      logger->turnLEDPurple();
00263      
00264      // update am existing record - assume "name" is the proper key for the record you wish to update...
00265      MbedJSONValue changed_record;
00266      changed_record["name"] = updated_account_name;
00267      
00268      // DEBUG
00269      logger->log("Update: updated record: %s",changed_record.serialize().c_str());
00270      
00271      // update...
00272      bool updated = sf->updateRecord(object_name,record_id,changed_record);
00273      
00274      // display the result
00275      if (updated) {
00276         // SUCCESS
00277         logger->log("Update: successful! http_code=%d",sf->httpResponseCode());
00278      }
00279      else {
00280         // failure
00281         logger->log("Update: FAILED http_code=%d",sf->httpResponseCode());
00282      }
00283      logger->turnLEDGreen();
00284  }
00285  
00286  void Test_upsert_external_id(Logger *logger,SalesforceInterface *sf) {
00287      logger->log("\r\n\r\nExecuting upsert(ExternalID)");
00288      logger->turnLEDPurple();
00289      
00290      // update am existing record - assume "name" is the proper key for the record you wish to update...
00291      MbedJSONValue changed_record;
00292      changed_record["name"] = updated_account_name;
00293      
00294      // DEBUG
00295      logger->log("upsert(ExternalID): upserted record: %s",changed_record.serialize().c_str());
00296      
00297      // Upsert...
00298      bool updated = sf->upsertRecord(object_name,external_id_field_name,external_id_field_value,changed_record);
00299      
00300      // display the result
00301      if (updated) {
00302         // SUCCESS
00303         logger->log("upsert(ExternalID): successful! http_code=%d",sf->httpResponseCode());
00304      }
00305      else {
00306         // failure
00307         logger->log("upsert(ExternalID): FAILED http_code=%d",sf->httpResponseCode());
00308      }
00309      logger->turnLEDGreen();
00310  }
00311  
00312  void Test_delete(Logger *logger,SalesforceInterface *sf) {
00313      logger->log("\r\n\r\nExecuting delete()");
00314      logger->turnLEDPurple();
00315      
00316      // DEBUG
00317      logger->log("Delete: deleting: %s from %s",record_id,object_name);
00318      
00319      // delete...
00320      bool deleted = sf->deleteRecord(object_name,record_id);
00321      
00322      // display the result
00323      if (deleted) {
00324         // SUCCESS
00325         logger->log("Delete: successful! http_code=%d",sf->httpResponseCode());
00326      }
00327      else {
00328         // failure
00329         logger->log("Delete: FAILED http_code=%d",sf->httpResponseCode());
00330      }
00331      
00332      logger->turnLEDGreen();
00333  }
00334  
00335  void Test_reset_auth(Logger *logger,SalesforceInterface *sf) {
00336      logger->log("\r\n\r\nForcing API to reset OAUTH token and Salesforce Token...");
00337      logger->turnLEDPurple();
00338      sf->resetSalesforceToken();
00339      logger->turnLEDGreen();
00340  }
00341  
00342  // *************** Test Cases ************************
00343  
00344  // Main Task...
00345  void mainTask(void const *v) {
00346         
00347     // create our object instances 
00348     Logger logger(&pc,NULL);    
00349     SalesforceInterface *sf = NULL;
00350     
00351     // announce
00352     logger.log("\r\n\r\nARM Salesforce Interface Testharness v%s",APP_VERSION);
00353     logger.turnLEDBlue();
00354     
00355     // initialize Ethernet
00356     logger.log("Initializing Ethernet...");
00357     ethernet.init();
00358     
00359     // get a DHCP address and bring the network interface up
00360     logger.log("Getting IP Address...");
00361     logger.turnLEDOrange();
00362     if (ethernet.connect() == 0) {
00363         // log our IP address (DHCP)
00364         logger.log("IP Address: %s",ethernet.getIPAddress());
00365         
00366         // allocate the Salesforce.com interface
00367         logger.log("Allocating Saleforce.com interface...");
00368         sf = new SalesforceInterface(&http,&logger);
00369         
00370         // set our Salesforce.com credentials
00371         sf->setCredentials(username,password,client_id,client_secret);
00372         
00373         // *************** BEGIN TEST CASES *****************        
00374 
00375         // configuration for the test cases        
00376         object_name             = "Account";       // use the account object
00377         account_name            = "ARM";           // add this record (name)
00378         updated_account_name    = "ARM Holdings";  // update the existing record's name to this
00379         external_id_field_name  = "Device__c";     // External ID field name
00380         external_id_field_value = "ABC123";        // External ID field value
00381         RESET_SML_BUFFER(record_id);               // buffer for the record's token
00382         
00383         // Perform a Create
00384         Test_create(&logger,sf);
00385                 
00386         // Perform a Read
00387         Test_read(&logger,sf);
00388         
00389         // Perform a Query
00390         Test_query(&logger,sf,"SELECT Id,Name FROM Account LIMIT 5");
00391         
00392         // Perform an Update
00393         Test_update(&logger,sf);
00394                 
00395         // Perform a second Read to visually confirm the update above...
00396         Test_read(&logger,sf);
00397         
00398         // Perform a Create (External ID)
00399         Test_create_external_id(&logger,sf);
00400         
00401         // Perform an Upsert
00402         Test_upsert_external_id(&logger,sf);
00403         
00404         // Perform a read of the external ID'ed specified by a given value
00405         Test_read_by_external_id_and_value(&logger,sf);
00406         
00407         // force the API to re-acquire the OAUTH token and Salesforce Token 
00408         Test_reset_auth(&logger,sf);
00409         
00410         // Perform a Read (should re-acquire the OAUTH token and Salesforce Token)
00411         Test_read(&logger,sf);
00412         
00413         // Perform a Delete
00414         Test_delete(&logger,sf);
00415                 
00416         // reset the record token buffer
00417         // RESET_SML_BUFFER(record_id);
00418         
00419         // Perform a Read - should error out
00420         Test_read(&logger,sf);
00421                         
00422         // reset the record token buffer
00423         RESET_SML_BUFFER(record_id);
00424         
00425         // *************** BEGIN TEST CASES *****************      
00426         
00427         // entering main loop
00428         logger.log("All tests complete...\r\nExiting...");
00429         logger.turnLEDBlue();
00430         exit(0);
00431      }
00432      else {
00433          logger.log("No Network... Exiting...");
00434          logger.turnLEDRed();
00435          exit(1);
00436      }     
00437   }
00438   
00439   // main entry
00440   int main() {
00441      Thread workerTask(mainTask, NULL, osPriorityNormal, STACK_SIZE);
00442      while (true) {
00443         Thread::wait(10*WAIT_TIME_MS);
00444      }
00445   }
00446 
00447  * @endcode
00448  *
00449  */       
00450  class SalesforceInterface {
00451     private:
00452         Logger          *m_logger;
00453         bool             m_logger_internal;
00454         HTTPClient      *m_http;
00455         char            *m_username;
00456         char            *m_password;
00457         char            *m_client_id;
00458         char            *m_client_secret;
00459         bool             m_have_creds;
00460         OauthToken       m_oauth_token;
00461         HTTPResult       m_http_status;
00462         int              m_http_response_code;
00463         char             m_http_redirection_url[MAX_BUFFER_LENGTH+1];
00464         char             m_salesforce_id[MAX_BUFFER_LENGTH+1];
00465         char             m_salesforce_api[SALESFORCE_API_VERSION_LENGTH];
00466         char             m_error_buffer[MAX_SMALL_BUFFER_LENGTH+1];
00467         
00468     public:
00469         /**
00470         Default constructor
00471         @param http HTTPClient instance
00472         @param pc optional RawSerial for debugging output. If NULL, there will be no debugging output 
00473         */
00474         SalesforceInterface(HTTPClient *http,RawSerial *pc = NULL); 
00475 
00476         /**
00477         Alternative constructor
00478         @param http HTTPClient instance
00479         @param logger optional Logger instance (See Logger for more info). If NULL, there will be no debugging output 
00480         */
00481         SalesforceInterface(HTTPClient *http,Logger *logger = NULL); 
00482         
00483         /**
00484         Default destructor
00485         */
00486         virtual ~SalesforceInterface();
00487         
00488         /**
00489         Establish salesforce.com credentials
00490         @param username salesforce.com account user name
00491         @param password salesforce.com account password. The password must be of the form [password][security token]
00492         @param client_id salesforce.com connected application "customer key" value
00493         @param client_secret salesforce.com connected application client secret value
00494         */
00495         void setCredentials(char *username,char *password,char *client_id,char *client_secret);
00496         
00497         /**
00498         Get our salesforce.com token
00499         @param fetch boolean that will direct the interface to fetch the token if not already done (default = true)
00500         @return our salesforce token in JSON format or NULL if in error
00501         */
00502         char *getSalesforceToken(bool fetch = true);
00503         
00504         /**
00505         Force the interface to re-acquire the OAUTH token and salesforce token
00506         */
00507         void resetSalesforceToken();
00508         
00509         /**
00510         Set our salesforce.com API version
00511         @param version integer value (positive)
00512         */
00513         void setSalesforceAPIVersion(int version);
00514         
00515         /**
00516         Set our salesforce.com API version
00517         @param version string value (format "X.Y")
00518         */
00519         void setSalesforceAPIVersion(char *version);
00520         
00521         /**
00522         Get our salesforce.com API version
00523         @return string containing our salesforce.com API version or NULL if in error
00524         */
00525         char *getSalesforceAPIVersion();
00526         
00527         /**
00528         Salesforce.com API SOQL QUERY method to invoke ad-hoc SOQL queries into salesforce.com
00529         @param query_str character string with the SOQL query to invoke
00530         @param output_buffer allocated result buffer to use
00531         @param output_buffer_length allocated result buffer length
00532         @return result of the SOQL query in JSON format or NULL if in error
00533         */
00534         char *query(char *query_str,char *output_buffer,int output_buffer_length);
00535  
00536         /**
00537         Salesforce.com API record creation method to create a new record within a salesforce.com object
00538         @param object_name name of the salesforce.com object to create the record in (i.e. "Account")
00539         @param record MbedJSONValue json structure that the new record will be comprised with 
00540         @return MbedJSONValue structure with the results of the creation operation in JSON format
00541         */
00542         MbedJSONValue createRecord(char *object_name,MbedJSONValue &record);
00543         
00544         /**
00545         Salesforce.com API record read method to read a record within a salesforce.com object
00546         @param object_name name of the salesforce.com object to read the record in (i.e. "Account")
00547         @param record_id salesforce.com id of the record instance to read 
00548         @param record_value salesforce.com id value of the record instance to read (for external ID usage - default is NULL for non-external IDs)
00549         @return MbedJSONValue structure with the results of the read operation in JSON format
00550         */
00551         MbedJSONValue readRecord(char *object_name,char *record_id,char *record_value = NULL);
00552         
00553         /**
00554         Salesforce.com API record update method to update a record within a salesforce.com object
00555         @param object_name name of the salesforce.com object to update the record in (i.e. "Account")
00556         @param record_id salesforce.com id of the record instance to read 
00557         @param record MbedJSONValue instance with updated data for the record
00558         @return true - success, false - failure
00559         */
00560         bool updateRecord(char *object_name,char *record_id,MbedJSONValue &record);
00561         
00562         /**
00563         Salesforce.com API record upsert (update/insert) method to update a record within a salesforce.com object for External IDs
00564         @param object_name name of the salesforce.com External object to upsert the record in (i.e. "FooBar_c")
00565         @param external_id_field_name salesforce.com id of the External record instance to upsert 
00566         @param external_id_field_value salesforce.com id value of the External record instance to upsert 
00567         @param record MbedJSONValue instance with updated data for the record
00568         @return true - success, false - failure
00569         */
00570         bool upsertRecord(char *object_name,char *external_id_field_name,char *external_id_field_value,MbedJSONValue &record);
00571         
00572         /**
00573         Salesforce.com API record delete method to delete a record within a salesforce.com object
00574         @param object_name name of the salesforce.com object to delete the record in (i.e. "Account")
00575         @param record_id salesforce.com id of the record instance to delete 
00576         @return true - success, false - failure
00577         */
00578         bool deleteRecord(char *object_name,char *record_id);
00579         
00580         /**
00581         Salesforce.com API invocation HTTP response code to aid in debugging error conditions
00582         @return http response code
00583         */
00584         // HTTP Error code access
00585         int httpResponseCode();
00586         
00587         /**
00588         Retrieve the last executed update, upsert, or delete response error detail
00589         @return http response code from last update, upsert, or delete operation
00590         */
00591         MbedJSONValue getLastError();
00592                       
00593  protected: 
00594         // do we have a valid salesforce token and OAUTH token?
00595         bool haveSalesforceToken(bool fetch = true);
00596 
00597         // CREATE: a record in Salesforce.com
00598         char *createRecord(char *object_name,char *json_data,char *output_buffer,int output_buffer_length);
00599         
00600         // READ: a specific record in Salesforce.com
00601         char *readRecord(char *object_name,char *record_id,char *record_value,char *output_buffer,int output_buffer_length);
00602         
00603         // UPDATE: a specific record in Salesforce.com
00604         bool updateRecord(char *object_name,char *record_id,char *json_data,char *output_buffer,int output_buffer_length);
00605         
00606         // UPSERT: update/insert a specific External record in Salesforce.com
00607         bool upsertRecord(char *object_name,char *external_id_field_name,char *external_id_field_value,char *json_data,char *output_buffer,int output_buffer_length);
00608                             
00609         // DELETE: delete a specific record in Salesforce.com
00610         bool deleteRecord(char *object_name,char *record_id,char *output_buffer,int output_buffer_length);
00611         
00612         // raw invocation of REST calls into Salesforce.com
00613         char *invoke(const char *url,char *output_buffer,int output_buffer_length);                                                                                                        // defaults to GET
00614         char *invoke(const char *url,char *output_buffer,int output_buffer_length,HttpVerb verb);                                                                                          // GET or DELETE with simple output
00615         char *invoke(const char *url,const char *input_data,const int input_data_len,char *output_buffer,int output_buffer_length);                                                        // defaults to POST with JSON input data type
00616         char *invoke(const char *url,const InputDataTypes input_type,const char *input_data,const int input_data_len,char *output_buffer,int output_buffer_length);                        // defaults to POST with variable input data type
00617         char *invoke(const char *url,const InputDataTypes input_type,const char *input_data,const int input_data_len,char *output_buffer,int output_buffer_length,const HttpVerb verb);    // full fidelity method
00618       
00619         // get our OAUTH Token
00620         void checkAndGetOauthToken(bool fetch = true);
00621         char *getOauthToken(char *output_buffer,int output_buffer_length);
00622      
00623         // convenience accessors
00624         Logger *logger();
00625         HTTPClient *http();
00626         OauthToken *oauth();
00627         HTTPResult httpStatus();
00628         
00629         // internal checkers
00630         bool haveCreds();
00631         void resetOauthToken();
00632         void fillOauthToken(char *token);
00633         bool validOauthToken(bool fetch = true);
00634         
00635         // get the specified URL from our Salesforce Token
00636         char *getSalesforceURL(char *key,char *url_buffer,int url_buffer_length);
00637        
00638         // simple char array replacement (modifies input string!)
00639         void replace(char *str,char orig_char,char new_char);
00640         
00641         // needed to replace substrings within std::string
00642         void replace(string& line, string& oldString, string& newString);
00643         
00644         // validate that http status is in the "n" range
00645         bool httpResponseCodeInRange(int n);
00646         
00647         // min() method
00648         int min(int value1,int value2);
00649         
00650         // look for a specific key value pair in a json message
00651         bool contains(char *json,char *key,char *value);
00652         
00653         // initialize
00654         void init(HTTPClient *http,Logger *logger,bool logger_internal);
00655  };
00656  
00657  #endif // _SALESFORCE_INTERFACE_H_