Salesforce.com interface to directly access Salesforce.com
Dependencies: HTTPClient-SSL MbedJSONValue
Dependents: df-2014-salesforce-hrm-k64f
Fork of SalesforceInterface by
Diff: SalesforceInterface.cpp
- Revision:
- 15:89044c68ad36
- Parent:
- 14:3c8d11b48814
- Child:
- 16:3d160f224084
--- 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];