Salesforce Case Generator for mbed

Revision:
12:8603f9ff1336
Parent:
11:57f6f0f286c0
Child:
13:1e06a3a4740d
--- a/SalesForceCaseGenerator.cpp	Sun Sep 21 07:28:37 2014 +0000
+++ b/SalesForceCaseGenerator.cpp	Wed Sep 24 18:52:45 2014 +0000
@@ -31,26 +31,33 @@
  }
  
  // create a case through APEX
- bool SalesForceCaseGenerator::createCase(char *subject,char *description) {
+ bool SalesForceCaseGenerator::createCase(char *subject,char *description,char *condition,int temperature,char *latitude,char *longitude) {
      bool success = false;
      
      // data buffer and result buffer
-     char data[MAX_BUFFER_LENGTH+1];
      char result[MAX_BUFFER_LENGTH+1];
-     memset(data,0,MAX_BUFFER_LENGTH+1);
      memset(result,0,MAX_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);
-    
+     // build the new Salesforce.com report 
+     MbedJSONValue report;
+     report["subject"]       = subject;
+     report["description"]   = description;
+     report["condition"]     = condition;
+     report["temperature"]   = temperature;
+     report["latitude"]      = latitude;
+     report["longitude"]     = longitude;
+        
      // covert to the HTTP data types
+     char data[MAX_BUFFER_LENGTH+1];
+     memset(data,0,MAX_BUFFER_LENGTH+1);
+     strcpy(data,report.serialize().c_str());
+     this->m_logger->log("Case JSON: %s",data);
      HTTPJson new_case(data,strlen(data)+1);
      HTTPText http_result(result,MAX_BUFFER_LENGTH);
         
-     //this->m_http.basicAuth("<username>", "<password>");
      this->m_http->setHeader(headers) ;
      this->m_http->setSSLversion(1) ; /* TLSv1.0 */
           
@@ -68,7 +75,7 @@
             this->m_logger->log("Case generation FAILED: %s",result);
      }
      else {
-        this->m_logger->log("Failed to post case (%d)",ret);
+        this->m_logger->log("Failed to post case (%d) (%s)",ret,result);
      }
      
      // return our status