Salesforce.com interface to directly access Salesforce.com
Dependencies: HTTPClient-SSL MbedJSONValue
Dependents: df-2014-salesforce-hrm-k64f
Fork of SalesforceInterface by
Revision 15:89044c68ad36, committed 2014-09-23
- Comitter:
- ansond
- Date:
- Tue Sep 23 17:35:34 2014 +0000
- Parent:
- 14:3c8d11b48814
- Child:
- 16:3d160f224084
- Commit message:
- updates
Changed in this revision
SalesforceInterface.cpp | Show annotated file Show diff for this revision Revisions of this file |
SalesforceInterface.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/SalesforceInterface.cpp Tue Sep 23 17:31:36 2014 +0000 +++ b/SalesforceInterface.cpp Tue Sep 23 17:35:34 2014 +0000 @@ -11,7 +11,7 @@ * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * THE SOFTWARE IS PROVtokenED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, @@ -23,7 +23,7 @@ #define SF_OAUTH_REQUEST_BODY "grant_type=password&client_id=%s&client_secret=%s&username=%s&password=%s" #define SF_HTTP_AUTH_HEADER "Authorization: Bearer %s" - // search tokens for URLS in salesforce ID + // search tokens for URLS in salesforce token #define SF_URLS_START_TOKEN "\"urls\":" #define SF_URLS_STOP_TOKEN "}," @@ -138,13 +138,13 @@ return this->m_oauth_token.valid; } - // reset our salesforce ID and OAUTH tokens + // reset our salesforce token and OAUTH tokens void SalesforceInterface::resetSalesforceToken() { this->resetOauthToken(); RESET_BUFFER(this->m_salesforce_id); } - // do we have a valid salesforce.com ID? + // do we have a valid salesforce.com token? bool SalesforceInterface::haveSalesforceToken(bool fetch) { if (this->m_salesforce_id != NULL && strlen(this->m_salesforce_id) > 0) return true; if (fetch) { @@ -231,11 +231,11 @@ return NULL; } - // Salesforce.com: Get our ID + // Salesforce.com: Get our token char *SalesforceInterface::getSalesforceToken(bool fetch) { // proceed only if we have a valid OAUTH Token if (this->validOauthToken(fetch) == true) { - // pull the ID from salesforce + // pull the token from salesforce RESET_BUFFER(this->m_salesforce_id); char *id = this->invoke(this->oauth()->id.c_str(),this->m_salesforce_id,MAX_BUFFER_LENGTH); @@ -244,7 +244,7 @@ return id; } else { - // unable to get ID - no OAUTH token + // unable to get token - no OAUTH token this->logger()->log("Unable to get Salesforce Token: no valid OAUTH token."); } return NULL; @@ -252,7 +252,7 @@ // QUERY: Salesforce.com char *SalesforceInterface::query(char *query_str,char *output_buffer,int output_buffer_length) { - // first we have to ensure that we have valid salesforce ID + // first we have to ensure that we have valid salesforce token if (this->haveSalesforceToken()) { // get the query url ALLOC_BUFFER(url); @@ -278,12 +278,12 @@ } else { // unable to find the query URL... - this->logger()->log("query: error - unable to find query URL in salesforce ID..."); + this->logger()->log("query: error - unable to find query URL in salesforce token..."); } } else { - // dont have a valid salesforce ID - this->logger()->log("query: error - no valid salesforced ID was found..."); + // dont have a valid salesforce token + this->logger()->log("query: error - no valid salesforced token was found..."); } return NULL; } @@ -315,7 +315,7 @@ char *SalesforceInterface::createRecord(char *object_name,char *json_data,char *output_buffer,int output_buffer_length) { // parameter check if (object_name != NULL && strlen(object_name) > 0 && json_data != NULL && strlen(json_data) > 0 && output_buffer != NULL && output_buffer_length > 0) { - // first we have to ensure that we have valid salesforce ID + // first we have to ensure that we have valid salesforce token if (this->haveSalesforceToken()) { // get the sobjects url ALLOC_BUFFER(url); @@ -335,8 +335,8 @@ } } else { - // dont have a valid salesforce ID - this->logger()->log("createRecord: error - no valid salesforced ID was found..."); + // dont have a valid salesforce token + this->logger()->log("createRecord: error - no valid salesforced token was found..."); } } else { @@ -350,7 +350,7 @@ char *SalesforceInterface::readRecord(char *object_name,char *record_id,char *output_buffer,int output_buffer_length) { // parameter check if (object_name != NULL && strlen(object_name) > 0 && record_id != NULL && strlen(record_id) > 0 && output_buffer != NULL && output_buffer_length > 0) { - // first we have to ensure that we have valid salesforce ID + // first we have to ensure that we have valid salesforce token if (this->haveSalesforceToken()) { // get the sobjects url ALLOC_BUFFER(url); @@ -362,7 +362,7 @@ // add object name that we want to create a record in str_url += object_name; - // add the record ID + // add the record token str_url += "/"; str_url += record_id; @@ -374,8 +374,8 @@ } } else { - // dont have a valid salesforce ID - this->logger()->log("readRecord: error - no valid salesforced ID was found..."); + // dont have a valid salesforce token + this->logger()->log("readRecord: error - no valid salesforced token was found..."); } } else { @@ -389,7 +389,7 @@ bool SalesforceInterface::updateRecord(char *object_name,char *record_id,char *json_data) { // parameter check if (object_name != NULL && strlen(object_name) > 0 && json_data != NULL && strlen(json_data) > 0) { - // first we have to ensure that we have valid salesforce ID + // first we have to ensure that we have valid salesforce token if (this->haveSalesforceToken()) { // get the sobjects url ALLOC_BUFFER(url); @@ -401,7 +401,7 @@ // add object name that we want to create a record in str_url += object_name; - // add the record ID + // add the record token str_url += "/"; str_url += record_id; @@ -424,8 +424,8 @@ } } else { - // dont have a valid salesforce ID - this->logger()->log("updateRecord: error - no valid salesforced ID was found..."); + // dont have a valid salesforce token + this->logger()->log("updateRecord: error - no valid salesforced token was found..."); } } else { @@ -439,7 +439,7 @@ bool SalesforceInterface::deleteRecord(char *object_name,char *record_id) { // parameter check if (object_name != NULL && strlen(object_name) > 0 && record_id != NULL && strlen(record_id) > 0) { - // first we have to ensure that we have valid salesforce ID + // first we have to ensure that we have valid salesforce token if (this->haveSalesforceToken()) { // get the sobjects url ALLOC_BUFFER(url); @@ -451,7 +451,7 @@ // add object name that we want to create a record in str_url += object_name; - // add the record ID + // add the record token str_url += "/"; str_url += record_id; @@ -471,8 +471,8 @@ } } else { - // dont have a valid salesforce ID - this->logger()->log("deleteRecord: error - no valid salesforced ID was found..."); + // dont have a valid salesforce token + this->logger()->log("deleteRecord: error - no valid salesforced token was found..."); } } else { @@ -630,9 +630,9 @@ return NULL; } - // find the specific URL in our salesforce ID + // find the specific URL in our salesforce token char *SalesforceInterface::getSalesforceURL(char *key,char *url_buffer,int url_buffer_length) { - // due to MbedJSONValue limitations - we have to manually pull out the specific JSON from our salesforce ID + // due to MbedJSONValue limitations - we have to manually pull out the specific JSON from our salesforce token int start = (int)strstr(this->m_salesforce_id,SF_URLS_START_TOKEN); if (start >= 0) { start += strlen(SF_URLS_START_TOKEN); @@ -641,7 +641,7 @@ // calculate the length int length = stop - start + 1; - // copy over the "urls" json from the salesforce ID + // copy over the "urls" json from the salesforce token ALLOC_BUFFER(urls); int start_index = (start - (int)this->m_salesforce_id); for(int i=0;i<length;++i) urls[i] = this->m_salesforce_id[start_index+i];
--- a/SalesforceInterface.h Tue Sep 23 17:31:36 2014 +0000 +++ b/SalesforceInterface.h Tue Sep 23 17:35:34 2014 +0000 @@ -11,7 +11,7 @@ * The above copyright notice and this permission notice shall be included in all copies or * substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * THE SOFTWARE IS PROVtokenED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, @@ -120,12 +120,12 @@ * logger->log("\r\n\r\nGetting Salesforce Token..."); * logger->turnLEDPurple(); * - * // get the salesforce ID + * // get the salesforce token * char *id = sf->getSalesforceToken(); * if (id != NULL && strlen(id) > 0) - * logger->log("Saleforce ID: %s",id); + * logger->log("Saleforce token: %s",id); * else - * logger->log("Unable to get Saleforce ID"); + * logger->log("Unable to get Saleforce token"); * logger->turnLEDGreen(); * } * @@ -139,7 +139,7 @@ * else logger->log("query - NULL result"); * } * else { - * logger->log("Unable to perform query as we do not have our salesforce ID"); + * logger->log("Unable to perform query as we do not have our salesforce token"); * } * logger->turnLEDGreen(); * } @@ -161,7 +161,7 @@ * // display the result * char *result = (char *)response.serialize().c_str(); * if (result != NULL && strlen(result) > 0 && strcmp(result,"null") != 0) { - * // save off the ID if we succeeded + * // save off the token if we succeeded * logger->log("Create: result: %s",result); * logger->log("Create: http_code=%d",sf->httpResponseCode()); * RESET_SML_BUFFER(record_id); @@ -187,7 +187,7 @@ * // display the result * char *result = (char *)response.serialize().c_str(); * if (result != NULL && strlen(result) > 0 && strcmp(result,"null") != 0) { - * // save off the ID if we succeeded + * // save off the token if we succeeded * logger->log("Read: result: %s",result); * logger->log("Read: http_code=%d",sf->httpResponseCode()); * } @@ -292,7 +292,7 @@ * object_name = "Account"; // use the account object * 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 + * RESET_SML_BUFFER(record_id); // buffer for the record's token * * // Perform a Create * Test_create(&logger,sf); @@ -318,13 +318,13 @@ * // Perform a Delete * Test_delete(&logger,sf); * - * // reset the record ID buffer + * // reset the record token buffer * // RESET_SML_BUFFER(record_id); * * // Perform a Read - should error out * Test_read(&logger,sf); * - * // reset the record ID buffer + * // reset the record token buffer * RESET_SML_BUFFER(record_id); * * // *************** BEGIN TEST CASES ***************** @@ -391,14 +391,14 @@ void setCredentials(char *username,char *password,char *client_id,char *client_secret); /** - Get our salesforce.com ID - @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 + Get our salesforce.com token + @param fetch boolean that will direct the interface to fetch the token if not already done (default = true) + @return our salesforce token in JSON format or NULL if in error */ char *getSalesforceToken(bool fetch = true); /** - Force the interface to re-acquire the OAUTH token and salesforce ID + Force the interface to re-acquire the OAUTH token and salesforce token */ void resetSalesforceToken(); @@ -440,7 +440,7 @@ /** 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 + @param record_id salesforce.com token of the record instance to read @return MbedJSONValue structure with the results of the read operation in JSON format */ MbedJSONValue readRecord(char *object_name,char *record_id); @@ -448,7 +448,7 @@ /** 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_id salesforce.com token of the record instance to read @param record MbedJSONValue instance with updated data for the record @return true - success, false - failure */ @@ -457,7 +457,7 @@ /** 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 + @param record_id salesforce.com token of the record instance to delete @return true - success, false - failure */ bool deleteRecord(char *object_name,char *record_id); @@ -470,7 +470,7 @@ int httpResponseCode(); protected: - // do we have a valid salesforce ID and OAUTH token? + // do we have a valid salesforce token and OAUTH token? bool haveSalesforceToken(bool fetch = true); // CREATE: a record in Salesforce.com