Salesforce Case Generator for mbed

Revision:
1:5c876ee72cf0
Parent:
0:5953127f7c19
Child:
2:670837d3e248
--- a/SalesForceCaseGenerator.cpp	Sat Aug 23 20:17:12 2014 +0000
+++ b/SalesForceCaseGenerator.cpp	Wed Aug 27 05:39:58 2014 +0000
@@ -23,35 +23,39 @@
  // constructor
  SalesForceCaseGenerator::SalesForceCaseGenerator(Logger *logger) {
      this->m_logger = logger;
-     this->m_connected = this->m_https.connect(MY_SF_HOST);
  }
  
  // destructor
  SalesForceCaseGenerator::~SalesForceCaseGenerator() {
-     if (this->m_connected == true) this->m_https.disconnect();
-     this->m_connected = false;
  }
  
  // create a case through APEX
  bool SalesForceCaseGenerator::createCase(char *subject,char *description) {
      bool success = false;
      
-     // proceed only if connected
-     if (this->m_connected == true) {
-        HTTPHeader hdr;
-        char buffer[BUFFER_LENGTH+1];
-        memset(buffer,0,BUFFER_LENGTH+1);
-        int n = this->m_https.get(MY_APEX_CASE_RESOURCE, &hdr, buffer, BUFFER_LENGTH);
-        if(n > 0 && hdr.getStatus() == HTTP_OK) {
-            success = this->contains(buffer,"status","ok");
-            if (success) 
-                this->m_logger->log("Case generated successfully");
-            else 
-                this->m_logger->log("Case generation FAILED: %s",buffer);
-        }
-        else {
-            this->m_logger->log("Failed to send get request");
-        }
+     // 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);
+     
+     // create the case
+     sprintf(data,"{ \"subject\":\"%s\", \"description\":\"%s\" }", subject, description);
+     
+     // Create the inbound and outbound buffers
+     HTTPText http_data(data,strlen(data)+1);
+     HTTPText http_result(result,BUFFER_LENGTH);
+     
+     // POST the case and check the response
+     if (this->m_http.post(DF_CASE_GEN_URL,http_data,&http_result) == 0) {
+        success = this->contains(result,"status","ok");
+        if (success) 
+            this->m_logger->log("Case generated successfully");
+        else 
+            this->m_logger->log("Case generation FAILED: %s",data);
+     }
+     else {
+        this->m_logger->log("Failed to send get request");
      }
      
      // return our status