rubyzoho 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/.travis.yml +1 -1
- data/Gemfile +2 -3
- data/README.rdoc +20 -15
- data/Rakefile +0 -15
- data/lib/crud_methods.rb +3 -7
- data/lib/zoho_api.rb +35 -34
- data/lib/zoho_api_finders.rb +1 -0
- data/rubyzoho.gemspec +34 -99
- data/spec/ruby_zoho_spec.rb +320 -219
- data/spec/spec_helper.rb +5 -8
- data/spec/zoho_api_spec.rb +231 -172
- metadata +41 -56
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
data/spec/spec_helper.rb
CHANGED
@@ -1,23 +1,19 @@
|
|
1
1
|
require 'simplecov'
|
2
2
|
require 'coveralls'
|
3
|
+
require 'vcr'
|
3
4
|
|
4
5
|
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
5
6
|
SimpleCov.start do
|
6
7
|
add_filter 'app/secrets'
|
7
|
-
|
8
|
+
end
|
8
9
|
|
9
10
|
Coveralls.wear!
|
10
11
|
|
11
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
12
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
13
|
-
# Require this file using `require "spec_helper"` to ensure that it is only
|
14
|
-
# loaded once.
|
15
|
-
#
|
16
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
12
|
RSpec.configure do |config|
|
18
|
-
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
# config.treat_symbols_as_metadata_keys_with_true_values = true
|
19
14
|
config.run_all_when_everything_filtered = true
|
20
15
|
config.filter_run :focus
|
16
|
+
config.expect_with(:rspec) { |c| c.syntax = :should }
|
21
17
|
|
22
18
|
# Run specs in random order to surface order dependencies. If you find an
|
23
19
|
# order dependency and want to debug it, you can fix the order by providing
|
@@ -25,3 +21,4 @@ RSpec.configure do |config|
|
|
25
21
|
# --seed 1234
|
26
22
|
config.order = 'random'
|
27
23
|
end
|
24
|
+
|
data/spec/zoho_api_spec.rb
CHANGED
@@ -5,276 +5,335 @@ require 'spec_helper'
|
|
5
5
|
require 'zoho_api'
|
6
6
|
require 'xmlsimple'
|
7
7
|
require 'yaml'
|
8
|
-
|
8
|
+
require 'vcr'
|
9
|
+
|
10
|
+
VCR.configure do |c|
|
11
|
+
c.cassette_library_dir = 'spec/vcr'
|
12
|
+
c.hook_into :webmock
|
13
|
+
# c.default_cassette_options = {:record => :all}
|
14
|
+
# c.debug_logger = File.open('log/vcr_debug.log', 'w')
|
15
|
+
end
|
9
16
|
|
10
17
|
describe ZohoApi do
|
11
18
|
|
12
19
|
def add_dummy_contact
|
13
|
-
|
14
|
-
|
15
|
-
|
20
|
+
VCR.use_cassette 'api_response/add_dummy_contact' do
|
21
|
+
c = {:first_name => 'BobDifficultToMatch', :last_name => 'SmithDifficultToMatch',
|
22
|
+
:email => 'bob@smith.com'}
|
23
|
+
@zoho.add_record('Contacts', c)
|
24
|
+
end
|
16
25
|
end
|
17
26
|
|
18
27
|
def delete_dummy_contact
|
19
|
-
|
20
|
-
|
21
|
-
|
28
|
+
VCR.use_cassette 'api_response/delete_dummy_contact' do
|
29
|
+
c = @zoho.find_records(
|
30
|
+
'Contacts', :email, '=', 'bob@smith.com')
|
31
|
+
@zoho.delete_record('Contacts', c[0][:contactid]) unless c == []
|
32
|
+
end
|
22
33
|
end
|
23
34
|
|
24
35
|
def init_api(api_key, base_path, modules)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
36
|
+
zoho = nil
|
37
|
+
VCR.use_cassette 'api_response/init_api' do
|
38
|
+
ignore_fields = true
|
39
|
+
if File.exists?(File.join(base_path, 'fields.snapshot'))
|
40
|
+
#noinspection RubyResolve
|
41
|
+
fields = YAML.load(File.read(File.join(base_path, 'fields.snapshot')))
|
42
|
+
zoho = ZohoApi::Crm.new(api_key, modules, ignore_fields, fields)
|
43
|
+
else
|
44
|
+
zoho = ZohoApi::Crm.new(api_key, modules, ignore_fields)
|
45
|
+
fields = zoho.module_fields
|
46
|
+
File.open(File.join(base_path, 'fields.snapshot'), 'wb') { |file| file.write(fields.to_yaml) }
|
47
|
+
end
|
34
48
|
end
|
35
49
|
zoho
|
36
50
|
end
|
37
51
|
|
38
52
|
before(:all) do
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
}
|
55
|
-
contacts = @zoho.find_records('Contacts', :email, '=', @h_smith[:email])
|
56
|
-
contacts.each { |c| @zoho.delete_record('Contacts', c[:contactid]) } unless contacts.nil?
|
53
|
+
VCR.use_cassette('api_response/initialization') do
|
54
|
+
base_path = File.join(File.dirname(__FILE__), 'fixtures')
|
55
|
+
@sample_pdf = File.join(base_path, 'sample.pdf')
|
56
|
+
modules = %w(Accounts Contacts Events Leads Tasks Potentials)
|
57
|
+
@zoho = init_api(ENV['ZOHO_API_KEY'].strip, base_path, modules)
|
58
|
+
@h_smith = {:first_name => 'Robert',
|
59
|
+
:last_name => 'Smith',
|
60
|
+
:email => 'rsmith@smithereens.com',
|
61
|
+
:department => 'Waste Collection and Management',
|
62
|
+
:phone => '13452129087',
|
63
|
+
:mobile => '12341238790'
|
64
|
+
}
|
65
|
+
contacts = @zoho.find_records('Contacts', :email, '=', @h_smith[:email])
|
66
|
+
contacts.each { |c| @zoho.delete_record('Contacts', c[:contactid]) } unless contacts.nil?
|
67
|
+
end
|
57
68
|
end
|
58
69
|
|
59
70
|
it 'should add a new contact' do
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
71
|
+
VCR.use_cassette 'api_response/add_contact' do
|
72
|
+
@zoho.add_record('Contacts', @h_smith)
|
73
|
+
contacts = @zoho.find_records('Contacts', :email, '=', @h_smith[:email])
|
74
|
+
@zoho.delete_record('Contacts', contacts[0][:contactid])
|
75
|
+
contacts.should_not eq(nil)
|
76
|
+
# contacts.count.should eq(1)
|
77
|
+
end
|
65
78
|
end
|
66
79
|
|
67
80
|
it 'should add a new event' do
|
68
81
|
pending
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
+
VCR.use_cassette 'api_response/add_event' do
|
83
|
+
@zoho.fields_from_api('Events')
|
84
|
+
@zoho.fields_from_record('Events')
|
85
|
+
@zoho.some('Events')
|
86
|
+
h = {:subject => 'Test Event',
|
87
|
+
:start_datetime => '2014-02-16 16:00:00',
|
88
|
+
:end_datetime => '2014-02-16 18:00:00'
|
89
|
+
}
|
90
|
+
@zoho.add_record('Events', h)
|
91
|
+
events = @zoho.some('Events')
|
92
|
+
events
|
93
|
+
#@zoho.delete_record('Contacts', contacts[0][:contactid])
|
94
|
+
events.should_not eq(nil)
|
95
|
+
events.count.should eq(1)
|
96
|
+
end
|
82
97
|
end
|
83
98
|
|
84
99
|
it 'should attach a file to a contact record' do
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
100
|
+
VCR.use_cassette 'api_response/add_file_to_contact' do
|
101
|
+
@zoho.add_record('Contacts', @h_smith)
|
102
|
+
contacts = @zoho.find_records('Contacts', :email, '=', @h_smith[:email])
|
103
|
+
@zoho.attach_file('Contacts', contacts[0][:contactid], @sample_pdf, File.basename(@sample_pdf))
|
104
|
+
@zoho.delete_record('Contacts', contacts[0][:contactid])
|
105
|
+
end
|
89
106
|
end
|
90
107
|
|
91
108
|
it 'should attach a file to a potential record' do
|
92
109
|
pending
|
93
|
-
|
94
|
-
|
110
|
+
VCR.use_cassette 'api_response/add_file_to_potential' do
|
111
|
+
potential = @zoho.first('Potentials').first
|
112
|
+
@zoho.attach_file('Potentials', potential[:potentialid], @sample_pdf, File.basename(@sample_pdf))
|
113
|
+
true.should eq(false)
|
114
|
+
end
|
95
115
|
end
|
96
116
|
|
97
117
|
it 'should delete a contact record with id' do
|
98
|
-
|
99
|
-
|
100
|
-
|
118
|
+
VCR.use_cassette 'api_response/delete_contact_with_id' do
|
119
|
+
add_dummy_contact
|
120
|
+
c = @zoho.find_records('Contacts', :email, '=', 'bob@smith.com')
|
121
|
+
@zoho.delete_record('Contacts', c[0][:contactid])
|
122
|
+
end
|
101
123
|
end
|
102
124
|
|
103
125
|
it 'should find by module and field for columns' do
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
126
|
+
VCR.use_cassette 'api_response/find_by_module_and_field' do
|
127
|
+
add_dummy_contact
|
128
|
+
r = @zoho.find_records('Contacts', :email, '=', 'bob@smith.com')
|
129
|
+
r[0][:email].should eq('bob@smith.com')
|
130
|
+
delete_dummy_contact
|
131
|
+
end
|
108
132
|
end
|
109
133
|
|
110
134
|
it 'should find by module and id' do
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
135
|
+
VCR.use_cassette 'api_response/find_by_module_and_id' do
|
136
|
+
add_dummy_contact
|
137
|
+
r = @zoho.find_records('Contacts', :email, '=', 'bob@smith.com')
|
138
|
+
r[0][:email].should eq('bob@smith.com')
|
139
|
+
id = r[0][:contactid]
|
140
|
+
c = @zoho.find_record_by_id('Contacts', id)
|
141
|
+
c[0][:contactid].should eq(id)
|
142
|
+
delete_dummy_contact
|
143
|
+
end
|
118
144
|
end
|
119
145
|
|
120
146
|
it 'should find by a potential by name, id and related id' do
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
147
|
+
VCR.use_cassette 'api_response' do
|
148
|
+
accounts = @zoho.some('Accounts')
|
149
|
+
p = {
|
150
|
+
:potential_name => 'A very big potential INDEED!!!!!!!!!!!!!',
|
151
|
+
:accountid => accounts.first[:accountid],
|
152
|
+
:account_name => accounts.first[:account_name],
|
153
|
+
:closing_date => '1/1/2014',
|
154
|
+
:type => 'New Business',
|
155
|
+
:stage => 'Needs Analysis'
|
156
|
+
}
|
157
|
+
potentials = @zoho.find_records('Potentials', :potential_name, '=', p[:potential_name])
|
158
|
+
potentials.map { |r| @zoho.delete_record('Potentials', r[:potentialid]) } unless potentials.nil?
|
159
|
+
|
160
|
+
@zoho.add_record('Potentials', p)
|
161
|
+
p1 = @zoho.find_records('Potentials', :potential_name, '=', p[:potential_name])
|
162
|
+
p1.should_not eq(nil)
|
163
|
+
|
164
|
+
p2 = @zoho.find_records('Potentials', :potentialid, '=', p1.first[:potentialid])
|
165
|
+
p2.first[:potentialid].should eq(p1.first[:potentialid])
|
166
|
+
|
167
|
+
p_related = @zoho.find_records('Potentials', :accountid, '=', p[:accountid])
|
168
|
+
p_related.first[:accountid].should eq(p[:accountid])
|
169
|
+
|
170
|
+
potentials = @zoho.find_records('Potentials', :potential_name, '=', p[:potential_name])
|
171
|
+
potentials.map { |r| @zoho.delete_record('Potentials', r[:potentialid]) } unless potentials.nil?
|
172
|
+
end
|
145
173
|
end
|
146
174
|
|
147
175
|
it 'should get a list of fields for a module' do
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
176
|
+
VCR.use_cassette 'api_response/list_of_fields' do
|
177
|
+
r = @zoho.fields('Accounts')
|
178
|
+
r.count.should >= 10
|
179
|
+
r = @zoho.fields('Contacts')
|
180
|
+
r.count.should be >= 10
|
181
|
+
r = @zoho.fields('Events')
|
182
|
+
r.count.should >= 10
|
183
|
+
r = @zoho.fields('Leads')
|
184
|
+
r.count.should be >= 10
|
185
|
+
r = @zoho.fields('Potentials')
|
186
|
+
r.count.should be >= 10
|
187
|
+
r = @zoho.fields('Tasks')
|
188
|
+
r.count.should >= 10
|
189
|
+
r = @zoho.fields('Users')
|
190
|
+
r.count.should >= 7
|
191
|
+
end
|
162
192
|
end
|
163
193
|
|
164
194
|
it 'should get a list of user fields' do
|
165
|
-
|
166
|
-
|
195
|
+
VCR.use_cassette 'api_response/user_fields' do
|
196
|
+
r = @zoho.user_fields
|
197
|
+
r.count.should be >= 7
|
198
|
+
end
|
167
199
|
end
|
168
200
|
|
169
201
|
it 'should get a list of local and remote fields' do
|
170
202
|
pending
|
171
|
-
|
172
|
-
|
173
|
-
|
203
|
+
VCR.use_cassette 'api_response/remote_fields' do
|
204
|
+
@zoho.fields('Accounts')
|
205
|
+
r = @zoho.fields_original('Accounts')
|
206
|
+
r.count.should >= 10
|
207
|
+
end
|
174
208
|
end
|
175
209
|
|
176
210
|
it 'should retrieve records by module name' do
|
177
|
-
|
178
|
-
|
179
|
-
|
211
|
+
VCR.use_cassette 'api_response/records_by_module_name' do
|
212
|
+
r = @zoho.some('Contacts')
|
213
|
+
r.should_not eq(nil)
|
214
|
+
r.count.should be >= 1
|
215
|
+
end
|
180
216
|
end
|
181
217
|
|
182
218
|
it 'should return related records by module and id' do
|
183
219
|
pending
|
184
|
-
|
185
|
-
|
186
|
-
|
220
|
+
VCR.use_cassette 'api_response/records_by_module_and_id' do
|
221
|
+
r = @zoho.some('Accounts').first
|
222
|
+
true.should eq(false)
|
223
|
+
#related = @zoho.related_records('Accounts', r[:accountid], 'Attachments')
|
224
|
+
end
|
187
225
|
end
|
188
226
|
|
189
227
|
it 'should return calls' do
|
190
228
|
pending
|
191
|
-
|
192
|
-
|
229
|
+
VCR.use_cassette 'api_response/calls' do
|
230
|
+
r = @zoho.some('Calls').first
|
231
|
+
r.should_not eq(nil)
|
232
|
+
end
|
193
233
|
end
|
194
234
|
|
195
235
|
it 'should return events' do
|
196
236
|
pending
|
197
|
-
|
198
|
-
|
237
|
+
VCR.use_cassette 'api_response/events' do
|
238
|
+
r = @zoho.some('Events').first
|
239
|
+
r.should_not eq(nil)
|
240
|
+
end
|
199
241
|
end
|
200
242
|
|
201
243
|
it 'should return tasks' do
|
202
|
-
|
203
|
-
|
244
|
+
VCR.use_cassette 'api_response/tasks' do
|
245
|
+
r = @zoho.some('Tasks').first
|
246
|
+
r.should_not eq(nil)
|
247
|
+
end
|
204
248
|
end
|
205
249
|
|
206
250
|
it 'should return users' do
|
207
|
-
|
208
|
-
|
251
|
+
VCR.use_cassette 'api_response/users' do
|
252
|
+
r = @zoho.users
|
253
|
+
r.should_not eq(nil)
|
254
|
+
end
|
209
255
|
end
|
210
256
|
|
211
257
|
it 'should test for a primary key' do
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
258
|
+
VCR.use_cassette 'api_response/primary_key' do
|
259
|
+
@zoho.primary_key?('Accounts', 'accountid').should eq(true)
|
260
|
+
@zoho.primary_key?('Accounts', 'potentialid').should eq(false)
|
261
|
+
@zoho.primary_key?('Accounts', 'Potential Name').should eq(false)
|
262
|
+
@zoho.primary_key?('Accounts', 'Account Name').should eq(false)
|
263
|
+
@zoho.primary_key?('Accounts', 'account_name').should eq(false)
|
264
|
+
end
|
217
265
|
end
|
218
266
|
|
219
267
|
it 'should test for a related id' do
|
220
|
-
|
221
|
-
|
268
|
+
VCR.use_cassette 'api_response/related_id' do
|
269
|
+
@zoho.related_id?('Potentials', 'Account Name').should eq(false)
|
270
|
+
@zoho.related_id?('Potentials', 'Accountid').should eq(true)
|
271
|
+
end
|
222
272
|
end
|
223
273
|
|
224
274
|
it 'should test for a valid related field' do
|
225
|
-
|
226
|
-
|
227
|
-
|
275
|
+
VCR.use_cassette 'api_response/valid_related_id' do
|
276
|
+
@zoho.valid_related?('Accounts', 'accountid').should_not eq(nil)
|
277
|
+
@zoho.valid_related?('Notes', 'notesid').should_not eq(nil)
|
278
|
+
@zoho.valid_related?('Accounts', 'email').should eq(nil)
|
279
|
+
end
|
228
280
|
end
|
229
281
|
|
230
282
|
it 'should do a full CRUD lifecycle on tasks' do
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
283
|
+
VCR.use_cassette 'api_response/full_crud_lifecycle' do
|
284
|
+
mod_name = 'Tasks'
|
285
|
+
fields = @zoho.fields(mod_name)
|
286
|
+
fields.count >= 10
|
287
|
+
fields.index(:task_owner).should_not eq(nil)
|
288
|
+
@zoho.add_record(mod_name, {:task_owner => 'Task Owner', :subject => 'Test Task', :due_date => '2100/1/1'})
|
289
|
+
r = @zoho.find_record_by_field('Tasks', 'Subject', '=', 'Test Task')
|
290
|
+
r.should_not eq(nil)
|
291
|
+
r.map { |t| @zoho.delete_record('Tasks', t[:activityid]) }
|
292
|
+
end
|
240
293
|
end
|
241
294
|
|
242
|
-
it 'should update fields from a record' do
|
243
|
-
|
295
|
+
it 'should update fields from a record/update_fields_from_record' do
|
296
|
+
VCR.use_cassette 'api_response' do
|
297
|
+
@zoho.module_fields.count.should be >= 7
|
298
|
+
end
|
244
299
|
end
|
245
300
|
|
246
301
|
it 'should update a contact' do
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
302
|
+
VCR.use_cassette 'api_response/update_contact' do
|
303
|
+
@zoho.add_record('Contacts', @h_smith)
|
304
|
+
contact = @zoho.find_records('Contacts', :email, '=', @h_smith[:email])
|
305
|
+
h_changed = {:email => 'robert.smith@smithereens.com'}
|
306
|
+
@zoho.update_record('Contacts', contact[0][:contactid], h_changed)
|
307
|
+
changed_contact = @zoho.find_records('Contacts', :email, '=', h_changed[:email])
|
308
|
+
changed_contact[0][:email].should eq(h_changed[:email])
|
309
|
+
@zoho.delete_record('Contacts', contact[0][:contactid])
|
310
|
+
end
|
254
311
|
end
|
255
312
|
|
256
313
|
it 'should validate that a field name is clean' do
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
314
|
+
VCR.use_cassette 'api_response/clean_field_name' do
|
315
|
+
@zoho.clean_field_name?(nil).should eq(false)
|
316
|
+
@zoho.clean_field_name?('Name').should eq(true)
|
317
|
+
@zoho.clean_field_name?('Full_Name').should eq(true)
|
318
|
+
@zoho.clean_field_name?('Name (All Upper)').should eq(false)
|
319
|
+
end
|
261
320
|
end
|
262
321
|
|
263
322
|
it 'should relate contact with a product' do
|
264
|
-
|
265
|
-
|
323
|
+
VCR.use_cassette 'api_response/relate_contact_with_product' do
|
324
|
+
contact = @zoho.add_record('Contacts', @h_smith)
|
325
|
+
product = @zoho.add_record('Products', {product_name: 'Watches'})
|
266
326
|
|
267
|
-
|
268
|
-
|
269
|
-
|
327
|
+
related_module_params = {related_module: 'Contacts', xml_data: {contactid: contact[:id]}}
|
328
|
+
r = @zoho.update_related_records('Products', product[:id], related_module_params)
|
329
|
+
r.should eq('4800')
|
270
330
|
|
271
|
-
|
272
|
-
|
331
|
+
r = @zoho.related_records('Products', product[:id], 'Contacts')
|
332
|
+
r.should eq(200)
|
273
333
|
|
274
|
-
|
275
|
-
|
334
|
+
@zoho.delete_record('Contacts', contact[:id])
|
335
|
+
@zoho.delete_record('Products', product[:id])
|
336
|
+
end
|
276
337
|
end
|
277
338
|
|
278
|
-
|
279
|
-
|
280
339
|
end
|