Wrapping zoho crm resources with class
Add this line to your application's Gemfile:
gem 'zoho-crm'
And then execute:
$ bundle
Or install it yourself as:
$ gem install zoho-crm
Create a config/zoho-crm.yml with a url and authtoken for each environment.
development:
url: 'https://crm.zoho.com/crm/private'
authtoken: <%= ENV["ZOHO_AUTH_TOKEN"] %>
Your model should include ZohoCrm::Model
to represent the resource, use the method custom_module_name
to define the resource name listed on Zoho CRM and the method property
to define the resource fields.
class MyLead
include ZohoCrm::Model
custom_module_name 'Leads'
property :first_name, as: 'First Name'
property :last_name, as: 'Last Name'
end
The as:
option on property should be used to map the field name on Zoho CRM resource.
So far, the record repository represents the following api methods:
The repository should include ZohoCrm::Repositories::Records
and associate your model using model
method.
class MyLeadRepository
include ZohoCrm::Repositories::Records
model MyLead
end
lead_repo = MyLeadRepository.new
lead = lead_repo.find(1)
lead = MyLead.new(first_name: 'Rocky', last_name: 'Balboa')
lead_repo = MyLeadRepository.new
lead_repo.create(lead)
lead_repo = MyLeadRepository.new
lead = lead_repo.find(1)
lead.first_name = "Sylvester"
lead.last_name = "Stallone"
lead_repo.update(lead)
lead = MyLead.new(first_name: 'Rocky', last_name: 'Balboa')
lead_repo = MyLeadRepository.new
lead_repo.save(lead)
lead.first_name = 'Sylvester'
lead.last_name = 'Stallone'
lead_repo.save(lead)
lead_repo = MyLeadRepository.new
leads = lead_repo.select(:first_name).order(:last_name, :desc).from(0).to(10).where(first_name: 'Rocky')
Note that Zoho has a limit by 200 records for request, so it's necessary to control the result range using those methods #from and #to.
- Fork it ( https://github.com/[my-github-username]/zoho-crm/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request