Salesforce.com interface to directly access Salesforce.com
Dependencies: HTTPClient-SSL MbedJSONValue
Dependents: df-2014-salesforce-hrm-k64f
Fork of SalesforceInterface by
Diff: SalesforceInterface.h
- Revision:
- 9:a254fcd904be
- Parent:
- 8:47db53cd5884
- Child:
- 10:845ea6d00b65
--- a/SalesforceInterface.h Mon Sep 22 04:28:02 2014 +0000 +++ b/SalesforceInterface.h Tue Sep 23 05:40:18 2014 +0000 @@ -1,5 +1,7 @@ /* Copyright C2014 ARM, MIT License * + * Author: Doug Anson (doug.anson@arm.com) + * * 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, @@ -78,7 +80,7 @@ string access_token; } OauthToken; - // This class provides an interface into the REST-based Salesforce.com APIs + // SalesforceInterface provides an API into the REST-based Salesforce.com Force APIs class SalesforceInterface { private: ErrorHandler *m_logger; @@ -104,26 +106,56 @@ void setCredentials(char *username,char *password,char *client_id,char *client_secret); // get our ID structure from Salesforce - char *getSalesforceID(); - bool haveSalesforceID(); + char *getSalesforceID(bool fetch = true); + + // force the interface to re-acquire the OAUTH token and salesforce ID + void resetSalesforceID(); // set/get our salesforce API version void setSalesforceAPIVersion(int version); void setSalesforceAPIVersion(char *version); char *getSalesforceAPIVersion(); - // QUERY: into Salesforce.com + // SQL QUERY: into Salesforce.com char *query(char *query_str,char *output_buffer,int output_buffer_length); - + + // CREATE: a field in Salesforce.com + MbedJSONValue createField(char *object_name,MbedJSONValue &field); + + // READ: a specific field in Salesforce.com + MbedJSONValue readField(char *object_name,char *object_id); + + // UPDATE: a specific field in Salesforce.com + bool updateField(char *object_name,char *object_id,MbedJSONValue &field); + + // DELETE: a specific field in Salesforce.com + bool deleteField(char *object_name,char *object_id); + + // HTTP Error code access + int httpResponseCode(); + + protected: + // do we have a valid salesforce ID and OAUTH token? + bool haveSalesforceID(bool fetch = true); + + // CREATE: a field in Salesforce.com + char *createField(char *object_name,char *json_data,char *output_buffer,int output_buffer_length); + + // READ: a specific field in Salesforce.com + char *readField(char *object_name,char *object_id,char *output_buffer,int output_buffer_length); + + // UPDATE: a specific field in Salesforce.com + bool updateField(char *object_name,char *object_id,char *json_data); + // raw invocation of 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: + char *invoke(const char *url,char *output_buffer,int output_buffer_length); // defaults to GET + char *invoke(const char *url,char *output_buffer,int output_buffer_length,HttpVerb verb); // GET or DELETE with simple output + char *invoke(const char *url,const char *input_data,const int input_data_len,char *output_buffer,int output_buffer_length); // defaults to POST with JSON 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_length); // 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_length,const HttpVerb verb); // full fidelity method + // get our OAUTH Token - void checkAndGetOauthToken(); + void checkAndGetOauthToken(bool fetch = true); char *getOauthToken(char *output_buffer,int output_buffer_length); // convenience accessors @@ -131,17 +163,16 @@ HTTPClient *http(); OauthToken *oauth(); HTTPResult httpStatus(); - int httpResponseCode(); // internal checkers bool haveCreds(); void resetOauthToken(); void fillOauthToken(char *token); - bool validOauthToken(); + bool validOauthToken(bool fetch = true); // get the specified URL from our Salesforce ID char *getSalesforceURL(char *key,char *url_buffer,int url_buffer_length); - + // simple char array replacement (modifies input string!) void replace(char *str,char orig_char,char new_char);