= rubyzoho {}[https://travis-ci.org/amalc/rubyzoho] {}[https://gemnasium.com/amalc/rubyzoho] {}[https://codeclimate.com/github/amalc/rubyzoho] {}[https://coveralls.io/r/amalc/rubyzoho] {}[http://badge.fury.io/rb/rubyzoho] {}[https://rubygems.org/gems/rubyzoho]
Abstracting Zoho's API into a set of Ruby classes, with reflection of Zoho's fields using a more familiar ActiveRecord lifecycle, but without ActiveRecord. Current focus is on Zoho CRM.
Release notes are at the \end of this page.
== Install gem install rubyzoho
== Configure
=== Rails
Put the following in an initializer (e.g.
require 'ruby_zoho'
RubyZoho.configure do |config|
config.api_key = '<< API Key from Zoho>>'
# config.crm_modules = ['Accounts', 'Contacts', 'Leads', 'Potentials'] # Defaults to free edition if not set
# config.crm_modules = ['Quotes', 'SalesOrders', 'Invoices'] # Depending on what kind of account you've got, adds to free edition modules
# config.ignore_fields_with_bad_names = true # Ignores field with special characters in the name (Release 1.8)
# Currently only Quotes are supported
end
You can reduce the number of API calls made during development and production by adding
config.cache_fields = true
to the initializer. You can also limit the number of modules in use, so if you're only using 'Leads' for instance, set the gem to only load field data from 'Leads' by setting
config.crm_modules = ['Leads']
and only meta data from 'Leads' will be loaded.
In Test or Continous Integration(CI) environments, one strategy is not to initialize the gem at all, so for example,
RubyZoho.configure do |config|
config.api_key = '<< API Key from Zoho>>'
config.crm_modules = ['Accounts']
config.cache_fields = true if Rails.env.development?
end unless Rails.env.test?
and wrap the code calling the API in a begin ... rescue block.
=== Ruby Make sure the following block is executed prior to making calls to the gem.
require 'ruby_zoho'
RubyZoho.configure do |config|
config.api_key = '<< API Key from Zoho>>'
# config.crm_modules = ['Accounts', 'Contacts', 'Leads', 'Potentials'] # Defaults to free edition if not set
# config.crm_modules = ['Quotes', 'SalesOrders', 'Invoices'] # Depending on what kind of account you've got, adds to free edition modules
# config.ignore_fields_with_bad_names = true # Ignores field with special characters in the name (Release 1.8)
# Currently only Quotes are suported
end
Please be aware that Zoho limits API calls. So running tests repeatedly will quickly exhaust your daily allowance. See below for some optimizations during development and testing.
== Use RubyZoho attempts to follow the ActiveRecord lifecycle, i.e. new, save, update and delete. See examples below. (N.B. Fields cannot have special characters in them.)
To get a list of supported attributes for a Zoho CRM contact:
require 'ruby_zoho'
c = RubyZoho::Crm::Contact.new
c.attr_writers # => List of updatable attributes
c.fields # => Array of all fields
Attributes are reflected from the current API instance of Zoho, dynamically on initialization of the API, when the RubyZoho.configure block is called. This includes custom fields.
Another example:
l = RubyZoho::Crm::Lead.new
l.attr_writers # => List of updatable attributes
l.fields # => Array of all fields
To retrieve an existing record:
l = RubyZoho::Crm::Lead.find_by_email('email@domain.com')
Returns one or more records matching the query. The findby
Equality is the only match currently supported.
To get a list of all accounts:
a = RubyZoho::Crm::Account.all
a.each do |account|
pp account.account_name
end
Or for all task subjects:
t = RubyZoho::Crm::Task.all
pp t.collect { |task| task.subject } # => ['Subject 1'], ['Subject 2'], ... ['Subject n']
Or for all quotes:
q = RubyZoho::Crm::Quote.all
q.each do |quote|
pp quote.subject
pp quote.quote_name
end
To get the first quote: q.first
Or the last one: q.last
Since the result is Enumerable: q.map { |m| m.last_name } works.
To sort a result set: r = RubyZoho::Crm::Contact.all sorted = r.sort {|a, b| a.last_name <=> b.last_name } pp sorted.collect { |c| c.last_name } # => ['Name 1', ['Name 2'], ... ['Name n']]
To find by ID, note well, ID is a string: leads = RubyZoho::Crm::Lead.all l = RubyZoho::Crm::Lead.find_by_leadid(leads.last.leadid)
To create a new record:
c = RubyZoho::Crm::Contact.new(
:first_name => 'First Name',
:last_name => 'Last Name',
:email => 'email@domain.com',
etc.
)
c.save
r = RubyZoho::Crm::Contact.find_by_email('email@domain.com')
r.first.contactid # => Has the newly created contact's ID
To add a contact to an existing account:
a = RubyZoho::Crm::Account.find_by_account_name('Very Big Account')
c = RubyZoho::Crm::Contact.new(
:first_name => 'First Name',
:last_name => 'Last Name',
:email => 'email@domain.com',
:account_name => a.first.account_name,
:accountid => a.first.accountid # accountid instead of account_id because of Zoho's convention
etc.
)
c.save
To update a record (Note, that the attribute is :id): l = RubyZoho::Crm::Lead.find_by_email('email@domain.com') RubyZoho::Crm::Lead.update( :id => l.first.leadid, :email => 'changed_email@domain.com' )
Custom fields are like any other field or method in Ruby: a = RubyZoho::Crm::Account.find_by_account_name('Very Big Account') pp a.custom_field # => 'Custom field content'
Or: c = RubyZoho::Crm::Contact.new( :first_name => 'First Name', :last_name => 'Last Name', :email => 'email@domain.com', :account_name => a.first.account_name, :accountid => a.first.accountid, # accountid instead of account_id because of Zoho's convention :custom_field_2 => 'Custom text' ) pp c.save # Reflects back the new Zoho record ID, and various create and modify times and users
To attach a file to a record (Tested for +Accounts+, +Contacts+, +Leads+, +Potentials+ and +Tasks+ only): l = RubyZoho::Crm::Lead.find_by_email('email@domain.com') l.attach_file(file_path, file_name) # Can only be attached to a pre-existing record
To grab any attachments from a record: attachments = RubyZoho.configuration.api.related_records('Contacts', 'contact_id', 'Attachments') RubyZoho.configuration.api.download_file('Contacts', attachments.first[:id])
Classes (Zoho modules) currently supported are: RubyZoho::Crm::Account RubyZoho::Crm::Contact RubyZoho::Crm::Lead RubyZoho::Crm::Potential RubyZoho::Crm::Task RubyZoho::Crm::Quote RubyZoho::Crm::User
== Error Handling Errors, i.e. situations where the Zoho API either returns an http code something other than 200 or where the Zoho API sends back an explicit error code which isn't in the set
['4422', '5000']
a standard Ruby +RuntimeError+ exception is raised with the Zoho's API message.
== Optimizations for Development and Testing Set config.cache_fields = true in the configuration block. This caches \module field lists and is useful during development and testing, to reduce total API calls during start up. Defaults to false. We do not recommend use of this in production. The gem will need write access to its own directory for this to work.
RubyZoho.configure do |config|
# Other stuff for initialization
config.cache_fields = true
end
== Idiosyncractic Behavior From freedictionary.com id·i·o·syn·cra·sy ( d - -s ng kr -s ). n. pl. id·i·o·syn·cra·sies.
The Zoho API is definitely opinionated. And we have yet to be able plumb the depths of its views. If it behaves unexpectedly, try the Zoho forums before opening an issue here. It just may be the way the API works...
An example of this is retrieving related records. You would think that since a Task can be related to an Account or a Potential etc. that you should be able to retrieve it by either the related \module's record id, which is stored with the Task. But no, can't be done.
== Bugs and Enhancements Please open an issue on GitHub. Or better yet, send in a pull request with the fix or enhancement!
=== Known Bugs or Issues
=== Roadmap (Ranked)
== Contributing to rubyzoho
== Acknowledgements Giant buckets of Gratitude to the giants, sung and unsung heroes who put together and support the Open Source movement, Linux, Ruby and Rails. We stand on the shoulders of giants. Thank you.
== Credits and Contributions Thanks to a growing and wonderful community! @aeldaly @fheemeyer @kjcpass @qume @richkettle @summera @swithik @tjsousa @wcgiles @benknowles
Drop me a line if I've left anybody out and my advance apologies.
== Trademarks Zoho, the Zoho suite and related applications are owned, trademarked and copyrighted by the Zoho Corporation Pvt. Ltd. This software is not associated in anyway with the Zoho Corporation Pvt. Ltd.
== Copyright Copyright (c) 2013 - 2015 amalc (\@\amalc). Released under the MIT license. See LICENSE.txt for further details.
= Releases == Release Candidates (Uses {Semantic Versioning}[http://semver.org/])
== Development [0.8.0]
[0.1.1 - 0.1.6] Alpha Releases