rubyzoho 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +1 -1
- data/Gemfile +9 -7
- data/README.rdoc +9 -2
- data/VERSION +1 -1
- data/lib/ruby_zoho.rb +36 -2
- data/lib/zoho_api.rb +17 -6
- data/rubyzoho-0.0.3.gem +0 -0
- data/rubyzoho-0.0.4.gem +0 -0
- data/rubyzoho.gemspec +4 -1
- data/spec/ruby_zoho_spec.rb +22 -0
- data/spec/zoho_api_spec.rb +19 -1
- metadata +4 -1
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,16 +1,18 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
5
|
-
|
6
|
-
# Add dependencies to develop your gem here.
|
7
|
-
# Include everything needed to run rake, tests, features, etc.
|
8
2
|
|
9
3
|
gem 'httparty'
|
10
4
|
gem 'roxml'
|
11
5
|
|
12
6
|
|
13
|
-
group :
|
7
|
+
group :test do
|
8
|
+
gem 'cucumber'
|
9
|
+
gem 'rspec', ">= 2.12.0"
|
10
|
+
gem "shoulda", ">= 0"
|
11
|
+
gem 'xml-simple'
|
12
|
+
gem 'simplecov', :require => false, :group => :test
|
13
|
+
end
|
14
|
+
|
15
|
+
group :development do
|
14
16
|
gem "bundler"
|
15
17
|
gem 'cucumber'
|
16
18
|
gem "jeweler", "~> 1.8.4"
|
data/README.rdoc
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
Travis CI - YRI 1.9.x
|
2
|
-
|
3
1
|
{<img src="https://travis-ci.org/amalc/rubyzoho.png?branch=master" alt="Build Status" />}[https://travis-ci.org/amalc/rubyzoho]
|
4
2
|
|
5
3
|
= rubyzoho
|
@@ -15,6 +13,8 @@ Put the following in an initializer (e.g. zoho.rb):
|
|
15
13
|
|
16
14
|
RubyZoho.configure do |config|
|
17
15
|
config.api_key = '<< API Key from Zoho>>'
|
16
|
+
# config.crm_modules = ['Accounts', 'Contacts', 'Leads', 'Potentials'] # Defaults to free edition if not set
|
17
|
+
# config.crm_modules = ['Accounts', 'Contacts', 'Leads', 'Potentials', 'Quotes', 'SalesOrders', 'Invoices'] # Depending on what kind of account you've got
|
18
18
|
end
|
19
19
|
|
20
20
|
Please be aware that Zoho limits API calls. So running tests repeatedly will quickly exhaust
|
@@ -115,6 +115,13 @@ To add a contact to an existing account:
|
|
115
115
|
)
|
116
116
|
c.save
|
117
117
|
|
118
|
+
To update a record:
|
119
|
+
l = RubyZoho::Crm::Lead.find_by_email('email@domain.com')
|
120
|
+
RubyZoho::Crm::Lead.update(
|
121
|
+
:id => l.first.leadid,
|
122
|
+
:email => 'changed_email@domain.com'
|
123
|
+
)
|
124
|
+
|
118
125
|
|
119
126
|
Objects currently supported are:
|
120
127
|
RubyZoho::Crm::Account
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
data/lib/ruby_zoho.rb
CHANGED
@@ -5,11 +5,12 @@ require 'api_utils'
|
|
5
5
|
module RubyZoho
|
6
6
|
|
7
7
|
class Configuration
|
8
|
-
attr_accessor :api, :api_key
|
8
|
+
attr_accessor :api, :api_key, :crm_modules
|
9
9
|
|
10
10
|
def initialize
|
11
11
|
self.api_key = nil
|
12
12
|
self.api = nil
|
13
|
+
self.crm_modules = nil
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
@@ -20,7 +21,8 @@ module RubyZoho
|
|
20
21
|
def self.configure
|
21
22
|
self.configuration ||= Configuration.new
|
22
23
|
yield(configuration) if block_given?
|
23
|
-
self.configuration.
|
24
|
+
self.configuration.crm_modules ||= ['Accounts', 'Contacts', 'Leads', 'Potentials']
|
25
|
+
self.configuration.api = ZohoApi::Crm.new(self.configuration.api_key, self.configuration.crm_modules)
|
24
26
|
end
|
25
27
|
|
26
28
|
|
@@ -108,6 +110,13 @@ module RubyZoho
|
|
108
110
|
nil
|
109
111
|
end
|
110
112
|
|
113
|
+
def self.update(object_attribute_hash)
|
114
|
+
raise(RuntimeError, 'No ID found', object_attribute_hash) if object_attribute_hash[:id].nil?
|
115
|
+
id = object_attribute_hash[:id]
|
116
|
+
object_attribute_hash.delete(:id)
|
117
|
+
RubyZoho.configuration.api.update_record(Crm.module_name, id, object_attribute_hash)
|
118
|
+
end
|
119
|
+
|
111
120
|
|
112
121
|
class Account < RubyZoho::Crm
|
113
122
|
include RubyZoho
|
@@ -128,6 +137,11 @@ module RubyZoho
|
|
128
137
|
Crm.module_name = 'Accounts'
|
129
138
|
super
|
130
139
|
end
|
140
|
+
|
141
|
+
def self.method_missing(meth, *args, &block)
|
142
|
+
Crm.module_name = 'Accounts'
|
143
|
+
super
|
144
|
+
end
|
131
145
|
end
|
132
146
|
|
133
147
|
|
@@ -146,6 +160,11 @@ module RubyZoho
|
|
146
160
|
super
|
147
161
|
end
|
148
162
|
|
163
|
+
def self.method_missing(meth, *args, &block)
|
164
|
+
Crm.module_name = 'Contacts'
|
165
|
+
super
|
166
|
+
end
|
167
|
+
|
149
168
|
def self.delete(id)
|
150
169
|
Crm.module_name = 'Contacts'
|
151
170
|
super
|
@@ -172,6 +191,11 @@ module RubyZoho
|
|
172
191
|
Crm.module_name = 'Leads'
|
173
192
|
super
|
174
193
|
end
|
194
|
+
|
195
|
+
def self.method_missing(meth, *args, &block)
|
196
|
+
Crm.module_name = 'Leads'
|
197
|
+
super
|
198
|
+
end
|
175
199
|
end
|
176
200
|
|
177
201
|
class Potential < RubyZoho::Crm
|
@@ -193,6 +217,11 @@ module RubyZoho
|
|
193
217
|
Crm.module_name = 'Potentials'
|
194
218
|
super
|
195
219
|
end
|
220
|
+
|
221
|
+
def self.method_missing(meth, *args, &block)
|
222
|
+
Crm.module_name = 'Potentials'
|
223
|
+
super
|
224
|
+
end
|
196
225
|
end
|
197
226
|
|
198
227
|
class Quote < RubyZoho::Crm
|
@@ -214,6 +243,11 @@ module RubyZoho
|
|
214
243
|
Crm.module_name = 'Quotes'
|
215
244
|
super
|
216
245
|
end
|
246
|
+
|
247
|
+
def self.method_missing(meth, *args, &block)
|
248
|
+
Crm.module_name = 'Quotes'
|
249
|
+
super
|
250
|
+
end
|
217
251
|
end
|
218
252
|
|
219
253
|
end
|
data/lib/zoho_api.rb
CHANGED
@@ -19,8 +19,9 @@ module ZohoApi
|
|
19
19
|
|
20
20
|
attr_reader :auth_token, :module_fields
|
21
21
|
|
22
|
-
def initialize(auth_token)
|
22
|
+
def initialize(auth_token, modules)
|
23
23
|
@auth_token = auth_token
|
24
|
+
@modules = modules
|
24
25
|
@module_fields = reflect_module_fields
|
25
26
|
end
|
26
27
|
|
@@ -106,12 +107,8 @@ module ZohoApi
|
|
106
107
|
to_hash(x)
|
107
108
|
end
|
108
109
|
|
109
|
-
def self.module_names
|
110
|
-
%w{Leads Accounts Contacts Potentials Quotes Invoices SalesOrders}
|
111
|
-
end
|
112
|
-
|
113
110
|
def reflect_module_fields
|
114
|
-
module_names =
|
111
|
+
module_names = @modules
|
115
112
|
module_fields = {}
|
116
113
|
module_names.each { |n| module_fields.merge!({ ApiUtils.string_to_symbol(n) => fields(n) }) }
|
117
114
|
module_fields
|
@@ -141,6 +138,20 @@ module ZohoApi
|
|
141
138
|
r
|
142
139
|
end
|
143
140
|
|
141
|
+
def update_record(module_name, id, fields_values_hash)
|
142
|
+
x = REXML::Document.new
|
143
|
+
contacts = x.add_element module_name
|
144
|
+
row = contacts.add_element 'row', { 'no' => '1'}
|
145
|
+
fields_values_hash.each_pair { |k, v| add_field(row, ApiUtils.symbol_to_string(k), v) }
|
146
|
+
r = self.class.post(create_url(module_name, 'updateRecords'),
|
147
|
+
:query => { :newFormat => 1, :authtoken => @auth_token,
|
148
|
+
:scope => 'crmapi', :id => id,
|
149
|
+
:xmlData => x },
|
150
|
+
:headers => { 'Content-length' => '0' })
|
151
|
+
raise('Updating record failed', RuntimeError, r.response.body.to_s) unless r.response.code == '200'
|
152
|
+
r.response.code
|
153
|
+
end
|
154
|
+
|
144
155
|
end
|
145
156
|
|
146
157
|
end
|
data/rubyzoho-0.0.3.gem
ADDED
Binary file
|
data/rubyzoho-0.0.4.gem
ADDED
Binary file
|
data/rubyzoho.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "rubyzoho"
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["amalc"]
|
@@ -30,6 +30,9 @@ Gem::Specification.new do |s|
|
|
30
30
|
"lib/api_utils.rb",
|
31
31
|
"lib/ruby_zoho.rb",
|
32
32
|
"lib/zoho_api.rb",
|
33
|
+
"rubyzoho-0.0.3.gem",
|
34
|
+
"rubyzoho-0.0.4.gem",
|
35
|
+
"rubyzoho-0.1.0.gem",
|
33
36
|
"rubyzoho.gemspec",
|
34
37
|
"spec/api_utils_spec.rb",
|
35
38
|
"spec/fixtures/sample.pdf",
|
data/spec/ruby_zoho_spec.rb
CHANGED
@@ -12,7 +12,12 @@ describe RubyZoho::Crm do
|
|
12
12
|
RubyZoho.configure do |config|
|
13
13
|
#config.api_key = params['auth_token']
|
14
14
|
config.api_key = '62cedfe9427caef8afb9ea3b5bf68154'
|
15
|
+
config.crm_modules = ['Accounts', 'Contacts', 'Leads', 'Potentials', 'Quotes']
|
15
16
|
end
|
17
|
+
r = RubyZoho::Crm::Contact.find_by_last_name('Smithereens')
|
18
|
+
r.each { |m| RubyZoho::Crm::Contact.delete(m.contactid) } unless r.nil?
|
19
|
+
r = RubyZoho::Crm::Contact.find_by_email('raj@portra.com')
|
20
|
+
r.each { |c| RubyZoho::Crm::Contact.delete(c.contactid) } unless r.nil?
|
16
21
|
end
|
17
22
|
|
18
23
|
it 'should add accessors using a list of names' do
|
@@ -150,4 +155,21 @@ describe RubyZoho::Crm do
|
|
150
155
|
r.each { |c| RubyZoho::Crm::Potential.delete(c.potentialid) }
|
151
156
|
end
|
152
157
|
|
158
|
+
it 'should update a lead record' do
|
159
|
+
l = RubyZoho::Crm::Lead.new(
|
160
|
+
:first_name => 'Raj',
|
161
|
+
:last_name => 'Portra',
|
162
|
+
:email => 'raj@portra.com')
|
163
|
+
l.save
|
164
|
+
r = RubyZoho::Crm::Lead.find_by_email('raj@portra.com')
|
165
|
+
RubyZoho::Crm::Lead.update(
|
166
|
+
:id => r.first.leadid,
|
167
|
+
:email => 'changed_raj@portra.com'
|
168
|
+
)
|
169
|
+
r_changed = RubyZoho::Crm::Lead.find_by_email('changed_raj@portra.com')
|
170
|
+
r.first.leadid.should eq(r_changed.first.leadid)
|
171
|
+
r_changed.should_not eq(nil)
|
172
|
+
r.each { |c| RubyZoho::Crm::Lead.delete(c.leadid) }
|
173
|
+
end
|
174
|
+
|
153
175
|
end
|
data/spec/zoho_api_spec.rb
CHANGED
@@ -25,7 +25,8 @@ describe ZohoApi do
|
|
25
25
|
#params = YAML.load(File.open(config_file))
|
26
26
|
#@zoho = ZohoApi::Crm.new(params['auth_token'])
|
27
27
|
@sample_pdf = File.join(base_path, 'sample.pdf')
|
28
|
-
|
28
|
+
modules = ['Accounts', 'Contacts', 'Leads', 'Potentials', 'Quotes']
|
29
|
+
@zoho = ZohoApi::Crm.new('62cedfe9427caef8afb9ea3b5bf68154', modules)
|
29
30
|
end
|
30
31
|
|
31
32
|
it 'should add a new contact' do
|
@@ -105,4 +106,21 @@ describe ZohoApi do
|
|
105
106
|
r.count.should be > 1
|
106
107
|
end
|
107
108
|
|
109
|
+
it 'should update a contact' do
|
110
|
+
h = { :first_name => 'Robert',
|
111
|
+
:last_name => 'Smith',
|
112
|
+
:email => 'rsmith@smithereens.com',
|
113
|
+
:department => 'Waste Collection and Management',
|
114
|
+
:phone => '13452129087',
|
115
|
+
:mobile => '12341238790'
|
116
|
+
}
|
117
|
+
@zoho.add_record('Contacts', h)
|
118
|
+
contact = @zoho.find_records('Contacts', :email, '=', h[:email])
|
119
|
+
h_changed = { :email => 'robert.smith@smithereens.com' }
|
120
|
+
@zoho.update_record('Contacts', contact[0][:contactid], h_changed)
|
121
|
+
changed_contact = @zoho.find_records('Contacts', :email, '=', h_changed[:email])
|
122
|
+
changed_contact[0][:email].should eq(h_changed[:email])
|
123
|
+
@zoho.delete_record('Contacts', contact[0][:contactid])
|
124
|
+
end
|
125
|
+
|
108
126
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyzoho
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -208,6 +208,9 @@ files:
|
|
208
208
|
- lib/api_utils.rb
|
209
209
|
- lib/ruby_zoho.rb
|
210
210
|
- lib/zoho_api.rb
|
211
|
+
- rubyzoho-0.0.3.gem
|
212
|
+
- rubyzoho-0.0.4.gem
|
213
|
+
- rubyzoho-0.1.0.gem
|
211
214
|
- rubyzoho.gemspec
|
212
215
|
- spec/api_utils_spec.rb
|
213
216
|
- spec/fixtures/sample.pdf
|