Ruby SDK Samples - Rest Client Operations
Authentication Operations
Get Access token from Grant token
client = ZCRMSDK::OAuthClient::ZohoOAuth.get_client_instance
grant_token = 'grant_token'
client.generate_access_token(grant_token)
Get Access token from Refresh token
client = ZCRMSDK::OAuthClient::ZohoOAuth.get_client_instance
refresh_token = 'refresh_token'
client.generate_access_token_from_refresh_token(refresh_token)
Other Rest Client Operations
Get Organization Details
require 'ZCRMSDK'
# THIS CLASS SHOWS THE EXAMPLES
class Test
def initialize
config_details = { 'client_id' => 'client_id', 'client_secret' => 'client_secret', 'redirect_uri' => 'redirect_uri', 'api_base_url' => 'api_base_url', 'api_version' => 'v2', 'current_user_email' => 'user_identifier', 'application_log_file_path' => "path/to/filename.log" ,'log_in_console' => 'true' }
ZCRMSDK::RestClient::ZCRMRestClient.init(config_details)
end
def get_organization_details
rest = ZCRMSDK::RestClient::ZCRMRestClient.get_instance
api_res = rest.get_organization_details
org_ins = api_res.data
print org_ins.company_name
print "\n"
print org_ins.org_id
print "\n"
print org_ins.alias_aka
print "\n"
print org_ins.primary_zuid
print "\n"
print org_ins.zgid
print "\n"
print org_ins.primary_email
print "\n"
print org_ins.website
print "\n"
print org_ins.mobile
print "\n"
print org_ins.phone
print "\n"
print org_ins.employee_count
print "\n"
print org_ins.description
print "\n"
print org_ins.time_zone
print "\n"
print org_ins.iso_code
print "\n"
print org_ins.currency_locale
print "\n"
print org_ins.currency_symbol
print "\n"
print org_ins.street
print "\n"
print org_ins.state
print "\n"
print org_ins.city
print "\n"
print org_ins.country
print "\n"
print org_ins.zip_code
print "\n"
print org_ins.country_code
print "\n"
print org_ins.fax
print "\n"
print org_ins.mc_status
print "\n"
print org_ins.is_gapps_enabled
print "\n"
print org_ins.paid_expiry
print "\n"
print org_ins.trial_type
print "\n"
print org_ins.trial_expiry
print "\n"
print org_ins.is_paid_account
print "\n"
print org_ins.paid_type
print "\n"
print org_ins.currency
print "\n"
print org_ins.zia_portal_id
print "\n"
print org_ins.privacy_settings
print "\n"
print org_ins.photo_id
print "\n"
print org_ins.users_license_purchased
end
obj = Test.new
obj.get_organization_details
Get All Modules
require 'ZCRMSDK'
# THIS CLASS SHOWS THE EXAMPLES
class Test
def initialize
config_details = { 'client_id' => 'client_id', 'client_secret' => 'client_secret', 'redirect_uri' => 'redirect_uri', 'api_base_url' => 'api_base_url', 'api_version' => 'v2', 'current_user_email' => 'user_identifier', 'application_log_file_path' => "path/to/filename.log" ,'log_in_console' => 'true' }
ZCRMSDK::RestClient::ZCRMRestClient.init(config_details)
end
def get_all_modules
rest = ZCRMSDK::RestClient::ZCRMRestClient.get_instance
api_res = rest.get_all_modules
module_ins_arr = api_res.data
module_ins_arr.each do |module_ins|
print module_ins.api_name
print "\n"
print module_ins.is_convertable
print "\n"
print module_ins.is_creatable
print "\n"
print module_ins.is_editable
print "\n"
print module_ins.is_deletable
print "\n"
print module_ins.web_link
print "\n"
print module_ins.singular_label
print "\n"
print module_ins.plural_label
print "\n"
modified_by = module_ins.modified_by
unless modified_by.nil?
print modified_by.id
print "\n"
print modified_by.name
print "\n"
end
print module_ins.modified_time
print "\n"
print module_ins.is_viewable
print "\n"
print module_ins.is_api_supported
print "\n"
print module_ins.is_custom_module
print "\n"
print module_ins.is_scoring_supported
print "\n"
print module_ins.id
print "\n"
print module_ins.module_name
print "\n"
print module_ins.business_card_field_limit
print "\n"
profiles = module_ins.profiles
profiles.each do |profile|
print profile.id
print "\n"
print profile.name
end
print "\n"
print module_ins.is_global_search_supported
print "\n"
print module_ins.sequence_number
print "\n"
print module_ins.is_filter_status
print "\n"
print module_ins.is_presence_sub_menu
print "\n"
print module_ins.arguments
print "\n"
print module_ins.generated_type
print "\n"
print module_ins.is_quick_create
print "\n"
print module_ins.is_kanban_view_supported
print "\n"
print module_ins.is_filter_supported
print "\n"
parent_module = module_ins.parent_module
unless parent_module.nil?
print parent_module.id
print "\n"
print parent_module.api_name
print "\n"
end
print module_ins.is_feeds_required
print "\n"
print module_ins.is_email_template_support
print "\n"
print module_ins.is_webform_supported
print "\n"
print module_ins.visibility
end
rescue ZCRMSDK::Utility::ZCRMException => e
print e.status_code
print e.error_message
print e.exception_code
print e.error_details
print e.error_content
end
obj = Test.new
obj.get_all_modules
Get Module Data
require 'ZCRMSDK'
# THIS CLASS SHOWS THE EXAMPLES
class Test
def initialize
config_details = { 'client_id' => 'client_id', 'client_secret' => 'client_secret', 'redirect_uri' => 'redirect_uri', 'api_base_url' => 'api_base_url', 'api_version' => 'v2', 'current_user_email' => 'user_identifier', 'application_log_file_path' => "path/to/filename.log" ,'log_in_console' => 'true' }
ZCRMSDK::RestClient::ZCRMRestClient.init(config_details)
end
def get_module
rest = ZCRMSDK::RestClient::ZCRMRestClient.get_instance
module_api_name = 'Leads'
api_res = rest.get_module(module_api_name)
module_ins = api_res.data
print module_ins.api_name
print "\n"
print module_ins.is_convertable
print "\n"
print module_ins.is_creatable
print "\n"
print module_ins.is_editable
print "\n"
print module_ins.is_deletable
print "\n"
print module_ins.web_link
print "\n"
print module_ins.singular_label
print "\n"
print module_ins.plural_label
print "\n"
modified_by = module_ins.modified_by
unless modified_by.nil?
print modified_by.id
print "\n"
print modified_by.name
print "\n"
end
print module_ins.modified_time
print "\n"
print module_ins.is_viewable
print "\n"
print module_ins.is_api_supported
print "\n"
print module_ins.is_custom_module
print "\n"
print module_ins.is_scoring_supported
print "\n"
print module_ins.id
print "\n"
print module_ins.module_name
print "\n"
print module_ins.business_card_field_limit
print "\n"
print module_ins.business_card_fields
print "\n"
profiles = module_ins.profiles
profiles.each do |profile|
print profile.id
print "\n"
print profile.name
end
print "\n"
print module_ins.display_field_name
print "\n "
print module_ins.related_lists
print "\n "
rel_list_prop = module_ins.related_list_properties
print rel_list_prop.sort_by
print "\n"
print rel_list_prop.sort_order
print "\n"
print rel_list_prop.fields
print "\n"
print module_ins.properties
print "\n"
print module_ins.per_page
print "\n"
print module_ins.search_layout_fields
print "\n"
print module_ins.default_territory_name
print "\n"
print module_ins.default_territory_id
print "\n"
print module_ins.default_custom_view_id
print "\n"
cv_ins = module_ins.default_custom_view
print cv_ins.id
print "\n"
print cv_ins.module_api_name
print "\n"
print cv_ins.display_value
print "\n"
print cv_ins.is_default
print "\n"
print cv_ins.name
print "\n"
print cv_ins.system_name
print "\n"
print cv_ins.is_system_defined
print "\n"
print cv_ins.shared_details
print "\n"
print cv_ins.sort_by
print "\n"
print cv_ins.category
print "\n"
print cv_ins.fields
print "\n"
print cv_ins.favorite
print "\n "
print cv_ins.sort_order
print "\n"
print cv_ins.criteria_condition
print "\n"
cv_criteria = cv_ins.criteria
print "\n "
print cv_criteria.comparator
print "\n"
print cv_criteria.field
print "\n"
print cv_criteria.value
print "\n"
print cv_criteria.group # may contain more objects
print "\n"
print cv_criteria.group_operator
print "\n"
print cv_criteria.pattern
print "\n"
print cv_criteria.index
print "\n"
print cv_criteria.criteria
print "\n"
print cv_ins.categories
print "\n"
print cv_ins.is_off_line
print "\n"
print module_ins.is_global_search_supported
print "\n"
print module_ins.sequence_number
print "\n"
print module_ins.is_kanban_view
print "\n"
print module_ins.is_filter_status
print "\n"
print module_ins.is_presence_sub_menu
print "\n"
print module_ins.arguments
print "\n"
print module_ins.generated_type
print "\n"
print module_ins.is_quick_create
print "\n"
print module_ins.is_kanban_view_supported
print "\n"
print module_ins.is_filter_supported
print "\n"
parent_module = module_ins.parent_module
unless parent_module.nil?
print parent_module.id
print "\n"
print parent_module.api_name
print "\n"
end
print module_ins.is_feeds_required
print "\n"
print module_ins.is_email_template_support
print "\n"
print module_ins.is_webform_supported
print "\n"
print module_ins.visibility
rescue ZCRMSDK::Utility::ZCRMException => e
print e.status_code
print e.error_message
print e.exception_code
print e.error_details
print e.error_content
end
obj = Test.new
obj.get_module
Get Current User
require 'ZCRMSDK'
# THIS CLASS SHOWS THE EXAMPLES
class Test
def initialize
config_details = { 'client_id' => 'client_id', 'client_secret' => 'client_secret', 'redirect_uri' => 'redirect_uri', 'api_base_url' => 'api_base_url', 'api_version' => 'v2', 'current_user_email' => 'user_identifier', 'application_log_file_path' => "path/to/filename.log" ,'log_in_console' => 'true' }
ZCRMSDK::RestClient::ZCRMRestClient.init(config_details)
end
def get_current_user
rest = ZCRMSDK::RestClient::ZCRMRestClient.get_instance
api_res = rest.get_current_user
user_instances = api_res.data
user_instance = user_instances[0]
print user_instance.id
print "\n"
print user_instance.is_microsoft
print "\n"
print user_instance.signature
print "\n"
print user_instance.country
print "\n"
role = user_instance.role
print "\n"
print role.id
print "\n"
print role.name
print "\n"
customize_info = user_instance.customize_info
print customize_info
unless customize_info.nil?
print customize_info.notes_desc
print "\n"
print customize_info.is_to_show_right_panel
print "\n"
print customize_info.is_bc_view
print "\n"
print customize_info.is_to_show_home
print "\n"
print customize_info.is_to_show_detail_view
print "\n"
print customize_info.unpin_recent_item
end
print "\n"
print user_instance.city
print "\n"
print user_instance.name_format
print "\n"
print user_instance.language
print "\n"
print user_instance.locale
print "\n"
print user_instance.is_personal_account
print "\n"
print user_instance.default_tab_group
print "\n"
print user_instance.street
print "\n"
print user_instance.alias_aka
print "\n"
theme = user_instance.theme
unless theme.nil?
print theme.normal_tab_font_color
print "\n"
print theme.normal_tab_background
print "\n"
print theme.selected_tab_font_color
print "\n"
print theme.selected_tab_background
print "\n"
print theme.new_background
print "\n"
print theme.background
print "\n"
print theme.screen
print "\n"
print theme.type
end
print "\n"
print user_instance.state
print "\n"
print user_instance.country_locale
print "\n"
print user_instance.fax
print "\n"
print user_instance.first_name
print "\n"
print user_instance.email
print "\n"
print user_instance.zip
print "\n"
print user_instance.decimal_separator
print "\n"
print user_instance.website
print "\n"
print user_instance.time_format
print "\n"
profile = user_instance.profile
print "\n"
print profile.id
print "\n"
print profile.name
print "\n"
print user_instance.mobile
print "\n"
print user_instance.last_name
print "\n"
print user_instance.time_zone
print "\n"
print user_instance.zuid
print "\n"
print user_instance.is_confirm
print "\n"
print user_instance.full_name
print "\n"
print user_instance.phone
print "\n"
print user_instance.dob
print "\n"
print user_instance.date_format
print "\n"
print user_instance.status
print "\n"
creator = user_instance.created_by
print "\n"
print creator.id
print "\n"
print creator.name
print "\n"
modifier = user_instance.modified_by
print "\n"
print modifier.id
print "\n"
print modifier.name
print "\n"
print user_instance.territories
print "\n"
reporting_to = user_instance.reporting_to
print "\n"
unless reporting_to.nil?
print reporting_to.id
print "\n"
print reporting_to.name
print "\n"
end
print user_instance.is_online
print "\n"
print user_instance.currency
print "\n"
print user_instance.created_time
print "\n"
print user_instance.modified_time
print "\n"
end
obj = Test.new
obj.get_current_user