Configuration
Before you get started with creating your Ruby application, you need to register your client and authenticate the app with Zoho.
Follow the below steps to configure the SDK.
Create an instance of the SDKLog::Log Logger Class to log exception and API information.
# # Create an instance of SDKLog::Log Class that takes two parameters # 1 -> Level of the log messages to be logged. Can be configured by typing Levels "::" and choose any level from the list displayed. # 2 -> Absolute file path, where messages need to be logged. # log = SDKLog::Log.initialize(Levels::INFO,"/Users/user_name/Documents/rubysdk_log.log")
Create an instance of UserSignature that identifies the current user.
#Create an UserSignature instance that takes user Email as parameter user_signature = UserSignature.new('abc@zohocorp.com')
Configure the API environment which decides the domain and the URL to make API calls.
#Configure the environment #which is of the pattern DC::Domain::Environment #Available Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter #Available Environments: PRODUCTION, DEVELOPER, SANDBOX environment = DC::USDataCenter::PRODUCTION
Create an instance of OAuthToken with the information that you get after registering your Zoho client.
#Create a Token instance #1 -> OAuth client id. #2 -> OAuth client secret. #3 -> REFRESH/GRANT token. #4 -> Token type(REFRESH/GRANT). #5 -> OAuth redirect URL.(optional) token = Authenticator::OAuthToken.new("clientId", "clientSecret", "REFRESH/GRANT token", TokenType::REFRESH/GRANT, "redirectURL") Token token = new OAuthToken("clientId", "clientSecret", "REFRESH/GRANT token", TokenType.REFRESH/GRANT, "redirectURL");
Create an instance of TokenStore to persist tokens used for authenticating all the requests.
#Create an instance of TokenStore. #1 -> DataBase host name. Default "localhost" #2 -> DataBase name. Default "zohooauth" #3 -> DataBase user name. Default "root" #4 -> DataBase password. Default "" #5 -> DataBase port number. Default "3306" tokenstore = Store::DBStore.new("hostName", "dataBaseName", "userName", "password", "portNumber") tokenstore = Store::FileStore.new("/Users/user_name/Documents/ruby_sdk_token.txt") tokenStore = CustomStore.new
Create an instance of SDKConfig containing the SDK configuration.
# auto_refresh_fields # if true - all the modules' fields will be auto-refreshed in the background, every hour. # if false - the fields will not be auto-refreshed in the background. The user can manually delete the file(s) or refresh the fields using methods from ModuleFieldsHandler (Util::ModuleFieldsHandler) # # pickListValidation # if true - value for any picklist field will be validated with the available values. # if false - value for any picklist field will not be validated, resulting in creation of a new value. # # open_timeout # Number of seconds to wait for the connection to open (default 60 seconds) # # read_timeout # Number of seconds to wait for one block to be read (via one read(2) call) (default 60 seconds) # # write_timeout # Number of seconds to wait for one block to be written (via one write(2) call) (default 60 seconds) # # keep_alive_timeout # Seconds to reuse the connection of the previous request(default 2 seconds) # sdk_config = SDKConfig::Builder.new.auto_refresh_fields(false).pick_list_validation(true).open_timeout(60).read_timeout(60).write_timeout(60).keep_alive_timeout(2).build
Set the absolute directory path to store user specific files containing module fields information in resourcePath.
resource_path = "/Users/user_name/Documents/rubysdk-application"
Create an instance of RequestProxy containing the proxy properties of the user.
request_proxy = RequestProxy.new("proxyHost", "proxyPort", "proxyUser", "password")
Initialize the SDK and make API calls.