Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SalesforceCaseGenerator by
SalesForceCaseGenerator.cpp
- Committer:
- ansond
- Date:
- 2014-08-28
- Revision:
- 6:175744b497e2
- Parent:
- 5:09d5df94e8ae
- Child:
- 8:fa2c457b0cc9
File content as of revision 6:175744b497e2:
/* Copyright C2014 ARM, MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
* and associated documentation files the "Software", to deal in the Software without restriction,
* including without limitation the rights to use, copy, modify, merge, publish, distribute,
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* 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
* 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,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include "Definitions.h"
#include "SalesForceCaseGenerator.h"
#include "MbedJSONValue.h"
// constructor
SalesForceCaseGenerator::SalesForceCaseGenerator(ErrorHandler *logger) {
this->m_logger = logger;
}
// destructor
SalesForceCaseGenerator::~SalesForceCaseGenerator() {
}
// create a case through APEX
bool SalesForceCaseGenerator::createCase(char *subject,char *description) {
bool success = false;
// data buffer and result buffer
char data[BUFFER_LENGTH+1];
char result[BUFFER_LENGTH+1];
memset(data,0,BUFFER_LENGTH+1);
memset(result,0,BUFFER_LENGTH+1);
// set addl header information
char headers[] = "User-Agent: curl/7.33.0\nAccept: */*\n" ;
// build the new SF case
sprintf(data,"{\"subject\":\"%s\",\"description\":\"%s\"}",subject,description);
// covert to the HTTP data types
HTTPJson new_case(data,strlen(data)+1);
HTTPText http_result(result,BUFFER_LENGTH);
//this->m_http.basicAuth("<username>", "<password>");
this->m_http.setHeader(headers) ;
this->m_http.setSSLversion(1) ; /* TLSv1.0 */
// POST the case and check the response
this->m_logger->log("Posting new Case...");
int ret = this->m_http.post(DF_CASE_GEN_URL,new_case,&http_result);
if (!ret) {
this->m_logger->log("Parsing Reply...");
success = this->contains(result,"status","ok");
if (success)
this->m_logger->log("Case generation SUCCESS");
else
this->m_logger->log("Case generation FAILED");
}
else {
this->m_logger->log("Failed to post case");
}
// return our status
return success;
}
// look for a specific key value pair in a json message
bool SalesForceCaseGenerator::contains(char *json,char *key,char *value) {
bool has_it = false;
if (json != NULL && key != NULL && value != NULL) {
// parse the json and look for a specific <key,value> pair...
MbedJSONValue parsed;
parse(parsed,json);
char *answer = (char *)parsed[key].get<std::string>().c_str();
if (strcmp(answer,value) == 0) has_it = true;
}
return has_it;
}
