Salesforce.com interface to directly access Salesforce.com

Dependencies:   HTTPClient-SSL MbedJSONValue

Dependents:   df-2014-salesforce-hrm-k64f

Fork of SalesforceInterface by Doug Anson

Revision:
0:518b1ca956fc
Child:
7:97ea5ef906f7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SalesforceInterface.h	Wed Sep 17 21:36:19 2014 +0000
@@ -0,0 +1,91 @@
+/* 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_INTERFACE_H_
+ #define _SALESFORCE_INTERFACE_H_
+ 
+ // ErrorHandler
+ #include "ErrorHandler.h"
+ 
+ // SSL-based HTTP support
+ #include "HTTPClient.h"
+ 
+ // JSON parsing support
+ #include "MbedJSONValue.h"
+ 
+ // verbose debugging
+ #if ENABLE_DEBUG_LOGGING
+    #define DEBUG(...) { this->logger()->logConsole(__VA_ARGS__); }
+ #else
+    #define DEBUG(...)
+ #endif 
+
+ 
+ // HTTP Verbs
+ typedef enum {
+     GET,
+     PUT,
+     POST,
+     DELETE,
+     NUM_VERBS
+ } HttpVerb;
+ 
+ // Supported input data types for PUT and POST (Defined by HTTPClient-SSL/data support...)
+ typedef enum {
+     JSON,              // ContentType: application/json
+     PLAIN_TEXT,        // ContentType: plain/text
+     FORM_MAPPED,       // ContentType: application/x-www-form-urlencoded
+     NUM_TYPES
+ } InputDataTypes;
+ 
+ // This class provides an interface into the REST-based Salesforce.com APIs
+ class SalesforceInterface {
+    private:
+        ErrorHandler    *m_logger;
+        HTTPClient      *m_http;
+        char            *m_username;
+        char            *m_password;
+        char            *m_client_id;
+        char            *m_client_secret;
+        bool             m_have_creds;
+        
+    public:
+        // construction/destruction
+        SalesforceInterface(ErrorHandler *logger,HTTPClient *http); 
+        virtual ~SalesforceInterface();
+        
+        // set Salesforce.com credentials
+        void setCredentials(char *username,char *password,char *client_id,char *client_secret);
+        
+        // get our OAUTH Token
+        char *getOauthToken(char *output_buffer,int output_buffer_length);
+        
+        // invoke REST calls into Salesforce.com
+        char *invoke(char *url,char *output_buffer,int output_buffer_len);                                                                               // defaults to GET
+        char *invoke(char *url,char *input_data,int input_data_len,char *output_buffer,int output_buffer_len);                                           // defaults to POST with JSON input data type                                                                              // defaults to GET
+        char *invoke(char *url,InputDataTypes input_type,char *input_data,int input_data_len,char *output_buffer,int output_buffer_len);                  // defaults to POST with variable input data type
+        char *invoke(char *url,InputDataTypes input_type,char *input_data,int input_data_len,char *output_buffer,int output_buffer_len,HttpVerb verb);    // full fidelity method
+        
+    private:
+        // convenience accessors
+        ErrorHandler *logger();
+        HTTPClient *http();
+        bool haveCreds();
+ };
+ 
+ #endif // _SALESFORCE_INTERFACE_H_
\ No newline at end of file