Interface for invoking Salesforce.com REST calls over SSL with OAUTH authentication. This interface is designed to simplify the interaction between mbed devices and salesforce.com web services.
Dependencies: HTTPClient-SSL MbedJSONValue
Diff: SalesforceInterface.h
- Revision:
- 14:3c8d11b48814
- Parent:
- 13:3088dd4b4bef
- Child:
- 15:89044c68ad36
--- a/SalesforceInterface.h Tue Sep 23 16:56:25 2014 +0000 +++ b/SalesforceInterface.h Tue Sep 23 17:31:36 2014 +0000 @@ -112,16 +112,16 @@ * char *object_name = NULL; * char *account_name = NULL; * char *updated_account_name = NULL; - * DEFINE_SML_BUFFER(field_id); + * DEFINE_SML_BUFFER(record_id); * * // *************** Test Cases ************************ * - * void Test_getSalesforceID(ErrorHandler *logger,SalesforceInterface *sf) { - * logger->log("\r\n\r\nGetting Salesforce ID..."); + * void Test_getSalesforceToken(ErrorHandler *logger,SalesforceInterface *sf) { + * logger->log("\r\n\r\nGetting Salesforce Token..."); * logger->turnLEDPurple(); * * // get the salesforce ID - * char *id = sf->getSalesforceID(); + * char *id = sf->getSalesforceToken(); * if (id != NULL && strlen(id) > 0) * logger->log("Saleforce ID: %s",id); * else @@ -148,15 +148,15 @@ * logger->log("\r\n\r\nExecuting create()"); * logger->turnLEDPurple(); * - * // create a new field - * MbedJSONValue new_field; - * new_field["name"] = account_name; + * // create a new record + * MbedJSONValue new_record; + * new_record["name"] = account_name; * * // DEBUG - * logger->log("Create: new field: %s",new_field.serialize().c_str()); + * logger->log("Create: new record: %s",new_record.serialize().c_str()); * * // create... - * MbedJSONValue response = sf->createField(object_name,new_field); + * MbedJSONValue response = sf->createRecord(object_name,new_record); * * // display the result * char *result = (char *)response.serialize().c_str(); @@ -164,8 +164,8 @@ * // save off the ID if we succeeded * logger->log("Create: result: %s",result); * logger->log("Create: http_code=%d",sf->httpResponseCode()); - * RESET_SML_BUFFER(field_id); - * strcpy(field_id,(char *)response["id"].get<std::string>().c_str()); + * RESET_SML_BUFFER(record_id); + * strcpy(record_id,(char *)response["id"].get<std::string>().c_str()); * } * else { * // failure @@ -179,10 +179,10 @@ * logger->turnLEDPurple(); * * // DEBUG - * logger->log("Read: reading: %s from %s",field_id,object_name); + * logger->log("Read: reading: %s from %s",record_id,object_name); * * // read... - * MbedJSONValue response = sf->readField(object_name,field_id); + * MbedJSONValue response = sf->readRecord(object_name,record_id); * * // display the result * char *result = (char *)response.serialize().c_str(); @@ -203,15 +203,15 @@ * logger->log("\r\n\r\nExecuting update()"); * logger->turnLEDPurple(); * - * // update am existing field - assume "name" is the proper key for the field you wish to update... - * MbedJSONValue changed_field; - * changed_field["name"] = updated_account_name; + * // update am existing record - assume "name" is the proper key for the record you wish to update... + * MbedJSONValue changed_record; + * changed_record["name"] = updated_account_name; * * // DEBUG - * logger->log("Update: updated field: %s",changed_field.serialize().c_str()); + * logger->log("Update: updated record: %s",changed_record.serialize().c_str()); * * // update... - * bool updated = sf->updateField(object_name,field_id,changed_field); + * bool updated = sf->updateRecord(object_name,record_id,changed_record); * * // display the result * if (updated) { @@ -230,10 +230,10 @@ * logger->turnLEDPurple(); * * // DEBUG - * logger->log("Delete: deleting: %s from %s",field_id,object_name); + * logger->log("Delete: deleting: %s from %s",record_id,object_name); * * // delete... - * bool deleted = sf->deleteField(object_name,field_id); + * bool deleted = sf->deleteRecord(object_name,record_id); * * // display the result * if (deleted) { @@ -249,9 +249,9 @@ * } * * void Test_reset_auth(ErrorHandler *logger,SalesforceInterface *sf) { - * logger->log("\r\n\r\nForcing API to reset OAUTH token and Salesforce ID..."); + * logger->log("\r\n\r\nForcing API to reset OAUTH token and Salesforce Token..."); * logger->turnLEDPurple(); - * sf->resetSalesforceID(); + * sf->resetSalesforceToken(); * logger->turnLEDGreen(); * } * @@ -290,9 +290,9 @@ * * // configuration for the test cases * object_name = "Account"; // use the account object - * account_name = "ARM"; // add this field (name) - * updated_account_name = "ARM Holdings"; // update the existing field's name to this - * RESET_SML_BUFFER(field_id); // buffer for the field's ID + * account_name = "ARM"; // add this record (name) + * updated_account_name = "ARM Holdings"; // update the existing record's name to this + * RESET_SML_BUFFER(record_id); // buffer for the record's ID * * // Perform a Create * Test_create(&logger,sf); @@ -309,23 +309,23 @@ * // Perform a second Read to visually confirm the update above... * Test_read(&logger,sf); * - * // force the API to re-acquire the OAUTH token and Salesforce ID + * // force the API to re-acquire the OAUTH token and Salesforce Token * Test_reset_auth(&logger,sf); * - * // Perform a Read (should re-acquire the OAUTH token and Salesforce ID) + * // Perform a Read (should re-acquire the OAUTH token and Salesforce Token) * Test_read(&logger,sf); * * // Perform a Delete * Test_delete(&logger,sf); * - * // reset the field ID buffer - * // RESET_SML_BUFFER(field_id); + * // reset the record ID buffer + * // RESET_SML_BUFFER(record_id); * * // Perform a Read - should error out * Test_read(&logger,sf); * - * // reset the field ID buffer - * RESET_SML_BUFFER(field_id); + * // reset the record ID buffer + * RESET_SML_BUFFER(record_id); * * // *************** BEGIN TEST CASES ***************** * @@ -395,12 +395,12 @@ @param fetch boolean that will direct the interface to fetch the ID if not already done (default = true) @return our salesforce ID in JSON format or NULL if in error */ - char *getSalesforceID(bool fetch = true); + char *getSalesforceToken(bool fetch = true); /** Force the interface to re-acquire the OAUTH token and salesforce ID */ - void resetSalesforceID(); + void resetSalesforceToken(); /** Set our salesforce.com API version @@ -421,46 +421,46 @@ char *getSalesforceAPIVersion(); /** - Salesforce.com API SQL QUERY method to invoke ad-hoc SQL queries into salesforce.com - @param query_str character string with the SQL query to invoke + Salesforce.com API SOQL QUERY method to invoke ad-hoc SOQL queries into salesforce.com + @param query_str character string with the SOQL query to invoke @param output_buffer allocated result buffer to use @param output_buffer_length allocated result buffer length - @return result of the SQL query in JSON format or NULL if in error + @return result of the SOQL query in JSON format or NULL if in error */ char *query(char *query_str,char *output_buffer,int output_buffer_length); /** - Salesforce.com API field creation method to create a new field within a salesforce.com object - @param object_name name of the salesforce.com object to create the field in (i.e. "Account") - @param field MbedJSONValue json structure that the new field will be comprised with + Salesforce.com API record creation method to create a new record within a salesforce.com object + @param object_name name of the salesforce.com object to create the record in (i.e. "Account") + @param record MbedJSONValue json structure that the new record will be comprised with @return MbedJSONValue structure with the results of the creation operation in JSON format */ - MbedJSONValue createField(char *object_name,MbedJSONValue &field); + MbedJSONValue createRecord(char *object_name,MbedJSONValue &record); /** - Salesforce.com API field read method to read a field within a salesforce.com object - @param object_name name of the salesforce.com object to create the field in (i.e. "Account") - @param field_id salesforce.com ID of the field instance to read + Salesforce.com API record read method to read a record within a salesforce.com object + @param object_name name of the salesforce.com object to create the record in (i.e. "Account") + @param record_id salesforce.com ID of the record instance to read @return MbedJSONValue structure with the results of the read operation in JSON format */ - MbedJSONValue readField(char *object_name,char *field_id); + MbedJSONValue readRecord(char *object_name,char *record_id); /** - Salesforce.com API field update method to update a field within a salesforce.com object - @param object_name name of the salesforce.com object to create the field in (i.e. "Account") - @param field_id salesforce.com ID of the field instance to read - @param field MbedJSONValue instance with updated data for the field + Salesforce.com API record update method to update a record within a salesforce.com object + @param object_name name of the salesforce.com object to create the record in (i.e. "Account") + @param record_id salesforce.com ID of the record instance to read + @param record MbedJSONValue instance with updated data for the record @return true - success, false - failure */ - bool updateField(char *object_name,char *field_id,MbedJSONValue &field); + bool updateRecord(char *object_name,char *record_id,MbedJSONValue &record); /** - Salesforce.com API field delete method to delete a field within a salesforce.com object - @param object_name name of the salesforce.com object to create the field in (i.e. "Account") - @param field_id salesforce.com ID of the field instance to delete + Salesforce.com API record delete method to delete a record within a salesforce.com object + @param object_name name of the salesforce.com object to create the record in (i.e. "Account") + @param record_id salesforce.com ID of the record instance to delete @return true - success, false - failure */ - bool deleteField(char *object_name,char *field_id); + bool deleteRecord(char *object_name,char *record_id); /** Salesforce.com API invocation HTTP response code to aid in debugging error conditions @@ -471,16 +471,16 @@ protected: // do we have a valid salesforce ID and OAUTH token? - bool haveSalesforceID(bool fetch = true); + bool haveSalesforceToken(bool fetch = true); - // CREATE: a field in Salesforce.com - char *createField(char *object_name,char *json_data,char *output_buffer,int output_buffer_length); + // CREATE: a record in Salesforce.com + char *createRecord(char *object_name,char *json_data,char *output_buffer,int output_buffer_length); - // READ: a specific field in Salesforce.com - char *readField(char *object_name,char *field_id,char *output_buffer,int output_buffer_length); + // READ: a specific record in Salesforce.com + char *readRecord(char *object_name,char *record_id,char *output_buffer,int output_buffer_length); - // UPDATE: a specific field in Salesforce.com - bool updateField(char *object_name,char *field_id,char *json_data); + // UPDATE: a specific record in Salesforce.com + bool updateRecord(char *object_name,char *record_id,char *json_data); // raw invocation of REST calls into Salesforce.com char *invoke(const char *url,char *output_buffer,int output_buffer_length); // defaults to GET @@ -505,7 +505,7 @@ void fillOauthToken(char *token); bool validOauthToken(bool fetch = true); - // get the specified URL from our Salesforce ID + // get the specified URL from our Salesforce Token char *getSalesforceURL(char *key,char *url_buffer,int url_buffer_length); // simple char array replacement (modifies input string!)