Interface for invoking Salesforce.com REST calls over SSL with OAUTH authentication. This interface is designed to simplify the interaction between mbed devices and salesforce.com web services.
Dependencies: HTTPClient-SSL MbedJSONValue
Diff: SalesforceInterface.h
- Revision:
- 7:97ea5ef906f7
- Parent:
- 0:518b1ca956fc
- Child:
- 8:47db53cd5884
--- a/SalesforceInterface.h Fri Sep 19 22:07:44 2014 +0000 +++ b/SalesforceInterface.h Sun Sep 21 07:08:51 2014 +0000 @@ -34,7 +34,10 @@ #else #define DEBUG(...) #endif - + + // convenience macros + #define RESET_BUFFER(x) memset(x,0,MAX_BUFFER_LENGTH+1) + #define ALLOC_BUFFER(x) char x[MAX_BUFFER_LENGTH+1];RESET_BUFFER(x) // HTTP Verbs typedef enum { @@ -53,6 +56,17 @@ NUM_TYPES } InputDataTypes; + // OAUTH structure + typedef struct { + bool valid; + string id; + string issued_at; + string token_type; + string instance_url; + string signature; + string access_token; + } OauthToken; + // This class provides an interface into the REST-based Salesforce.com APIs class SalesforceInterface { private: @@ -63,6 +77,10 @@ char *m_client_id; char *m_client_secret; bool m_have_creds; + OauthToken m_oauth_token; + HTTPResult m_http_status; + int m_http_response_code; + char m_http_redirection_url[MAX_BUFFER_LENGTH+1]; public: // construction/destruction @@ -72,20 +90,32 @@ // set Salesforce.com credentials void setCredentials(char *username,char *password,char *client_id,char *client_secret); + // get our ID structure from Salesforce + char *getSalesforceID(char *output_buffer,int output_buffer_length); + + // invoke REST calls into Salesforce.com + char *invoke(const char *url,char *output_buffer,int output_buffer_len); // defaults to GET + char *invoke(const char *url,const char *input_data,const int input_data_len,char *output_buffer,int output_buffer_len); // defaults to POST with JSON input data type // defaults to GET + char *invoke(const char *url,const InputDataTypes input_type,const char *input_data,const int input_data_len,char *output_buffer,int output_buffer_len); // defaults to POST with variable input data type + char *invoke(const char *url,const InputDataTypes input_type,const char *input_data,const int input_data_len,char *output_buffer,int output_buffer_len,const HttpVerb verb); // full fidelity method + + private: // get our OAUTH Token + void checkAndGetOauthToken(); 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(); + OauthToken *oauth(); + HTTPResult httpStatus(); + int httpResponseCode(); + + // internal checkers bool haveCreds(); + void resetOauthToken(); + void fillOauthToken(char *token); + bool validOauthToken(); }; #endif // _SALESFORCE_INTERFACE_H_ \ No newline at end of file