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
Revision 0:5953127f7c19, committed 2014-08-23
- Comitter:
- ansond
- Date:
- Sat Aug 23 20:17:12 2014 +0000
- Child:
- 1:5c876ee72cf0
- Commit message:
- initial checkin
Changed in this revision
| SalesForceCaseGenerator.cpp | Show annotated file Show diff for this revision Revisions of this file |
| SalesForceCaseGenerator.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SalesForceCaseGenerator.cpp Sat Aug 23 20:17:12 2014 +0000
@@ -0,0 +1,74 @@
+/* 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(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");
+ }
+ }
+
+ // 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;
+ }
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SalesForceCaseGenerator.h Sat Aug 23 20:17:12 2014 +0000
@@ -0,0 +1,44 @@
+/* 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.
+ */
+
+ #ifndef _SALESFORCE_CASE_GENERATOR_H_
+ #define _SALESFORCE_CASE_GENERATOR_H_
+
+ #include "HTTPSClient.h"
+ #include "Logger.h"
+
+ class SalesForceCaseGenerator {
+ private:
+ HTTPSClient m_https;
+ Logger *m_logger;
+ bool m_connected;
+
+ public:
+ SalesForceCaseGenerator(Logger *logger);
+ virtual ~SalesForceCaseGenerator();
+
+ // create a case (via APEX)
+ bool createCase(char *subject, char *description);
+
+ protected:
+
+ private:
+ bool contains(char *json,char *key,char *value);
+ };
+
+ #endif // _SALESFORCE_CASE_GENERATOR_H_
\ No newline at end of file
