rubyzoho 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/zoho_api.rb +26 -3
- data/rubyzoho.gemspec +2 -2
- data/spec/ruby_zoho_spec.rb +28 -20
- data/spec/zoho_api_spec.rb +4 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.5
|
data/lib/zoho_api.rb
CHANGED
@@ -21,7 +21,7 @@ module ZohoApi
|
|
21
21
|
@@module_fields = {}
|
22
22
|
@@users = []
|
23
23
|
|
24
|
-
|
24
|
+
debug_output $stderr
|
25
25
|
|
26
26
|
attr_reader :auth_token, :module_fields
|
27
27
|
|
@@ -36,6 +36,7 @@ module ZohoApi
|
|
36
36
|
element = x.add_element module_name
|
37
37
|
row = element.add_element 'row', { 'no' => '1'}
|
38
38
|
fields_values_hash.each_pair { |k, v| add_field(row, ApiUtils.symbol_to_string(k), v) }
|
39
|
+
pp x.to_s
|
39
40
|
r = self.class.post(create_url(module_name, 'insertRecords'),
|
40
41
|
:query => { :newFormat => 1, :authtoken => @auth_token,
|
41
42
|
:scope => 'crmapi', :xmlData => x },
|
@@ -47,12 +48,21 @@ module ZohoApi
|
|
47
48
|
|
48
49
|
def add_field(row, field, value)
|
49
50
|
r = (REXML::Element.new 'FL')
|
50
|
-
|
51
|
+
adjust_tag_case(field)
|
52
|
+
r.attributes['val'] = adjust_tag_case(field)
|
51
53
|
r.add_text(value.to_s)
|
52
54
|
row.elements << r
|
53
55
|
row
|
54
56
|
end
|
55
57
|
|
58
|
+
def adjust_tag_case(tag)
|
59
|
+
return tag if tag == 'id'
|
60
|
+
return tag.upcase if tag.downcase.rindex('id')
|
61
|
+
u_tags = %w[SEMODULE RELATED\ TO]
|
62
|
+
return tag.upcase if u_tags.index(tag.upcase)
|
63
|
+
tag
|
64
|
+
end
|
65
|
+
|
56
66
|
def attach_file(module_name, record_id, file_path)
|
57
67
|
mime_type = (MIME::Types.type_for(file_path)[0] || MIME::Types["application/octet-stream"][0])
|
58
68
|
url = URI.parse(create_url(module_name, 'uploadFile') + "?authtoken=#{@auth_token}&scope=crmapi&id=#{record_id}")
|
@@ -69,7 +79,6 @@ module ZohoApi
|
|
69
79
|
|
70
80
|
def add_file(module_name, record_id, file_path)
|
71
81
|
url = URI.parse(create_url(module_name, 'uploadFile'))
|
72
|
-
r = nil
|
73
82
|
mime_type = (MIME::Types.type_for(file_path)[0] || MIME::Types["application/octet-stream"][0])
|
74
83
|
f = File.open(file_path)
|
75
84
|
req = Net::HTTP::Post::Multipart.new url.path,
|
@@ -116,6 +125,10 @@ module ZohoApi
|
|
116
125
|
|
117
126
|
def fields(module_name)
|
118
127
|
return user_fields if module_name == 'Users'
|
128
|
+
fields_from_api(module_name) if fields_from_record(module_name).nil?
|
129
|
+
end
|
130
|
+
|
131
|
+
def fields_from_api(module_name)
|
119
132
|
mod_name = ApiUtils.string_to_symbol(module_name)
|
120
133
|
return @@module_fields[mod_name] unless @@module_fields[mod_name].nil?
|
121
134
|
r = self.class.post(create_url(module_name, 'getFields'),
|
@@ -125,6 +138,15 @@ module ZohoApi
|
|
125
138
|
update_module_fields(mod_name, module_name, r)
|
126
139
|
end
|
127
140
|
|
141
|
+
def fields_from_record(module_name)
|
142
|
+
mod_name = ApiUtils.string_to_symbol(module_name)
|
143
|
+
return @@module_fields[mod_name] unless @@module_fields[mod_name].nil?
|
144
|
+
r = first(module_name)
|
145
|
+
return nil if r.nil?
|
146
|
+
@@module_fields[mod_name] = r.first.keys
|
147
|
+
@@module_fields[mod_name]
|
148
|
+
end
|
149
|
+
|
128
150
|
def first(module_name)
|
129
151
|
some(module_name, 1, 1)
|
130
152
|
end
|
@@ -172,6 +194,7 @@ module ZohoApi
|
|
172
194
|
end
|
173
195
|
|
174
196
|
def valid_related?(module_name, field)
|
197
|
+
return nil if field.downcase == 'smownerid'
|
175
198
|
valid_relationships = {
|
176
199
|
'Leads' => %w(email),
|
177
200
|
'Accounts' => %w(accountid accountname),
|
data/rubyzoho.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "rubyzoho"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.5"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["amalc"]
|
12
|
-
s.date = "2013-02-
|
12
|
+
s.date = "2013-02-20"
|
13
13
|
s.description = ""
|
14
14
|
s.email = ""
|
15
15
|
s.extra_rdoc_files = [
|
data/spec/ruby_zoho_spec.rb
CHANGED
@@ -229,29 +229,37 @@ describe RubyZoho::Crm do
|
|
229
229
|
r.each { |c| RubyZoho::Crm::Task.delete(c.activityid) }
|
230
230
|
end
|
231
231
|
|
232
|
-
it 'should save an
|
233
|
-
pending
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
:
|
244
|
-
:
|
232
|
+
it 'should save an task record related to an account' do
|
233
|
+
#pending
|
234
|
+
pp a = RubyZoho::Crm::Account.all.first
|
235
|
+
u = RubyZoho::Crm::User.all.first
|
236
|
+
c = RubyZoho::Crm::Contact.all.last
|
237
|
+
e = RubyZoho::Crm::Task.new(
|
238
|
+
:task_owner => u.user_name,
|
239
|
+
:subject => "Task should be related to #{a.account_name}",
|
240
|
+
:description => 'Nothing',
|
241
|
+
:smownerid => u.id,
|
242
|
+
:status => 'Not Started',
|
243
|
+
:priority => 'High',
|
244
|
+
:send_notification_email => 'false',
|
245
|
+
:due_date => '2014-02-16 16:00:00',
|
245
246
|
:start_datetime => '2013-02-16 16:00:00',
|
246
247
|
:end_datetime => '2014-02-16 16:00:00',
|
247
|
-
:
|
248
|
-
:
|
249
|
-
:
|
250
|
-
:
|
251
|
-
:
|
252
|
-
:contactid => "748054000000097043"
|
248
|
+
:related_to => a.account_name,
|
249
|
+
:relatedtoid => a.accountid,
|
250
|
+
:semodule => 'Accounts',
|
251
|
+
:contact_name => "#{c.first_name} #{c.last_name}",
|
252
|
+
:contactid => c.contactid
|
253
253
|
)
|
254
|
-
e
|
254
|
+
pp e
|
255
|
+
pp e.save
|
256
|
+
end
|
257
|
+
|
258
|
+
it 'should get tasks by user' do
|
259
|
+
#pp u = RubyZoho::Crm::User.all.first
|
260
|
+
#pp tasks = RubyZoho::Crm::Task.find_by_smownerid(u.id)
|
261
|
+
pp tasks = RubyZoho::Crm::Task.all
|
262
|
+
tasks.map { |t| RubyZoho::Crm::Task.delete(t.activityid)} unless tasks.nil?
|
255
263
|
end
|
256
264
|
|
257
265
|
it 'should sort contact records' do
|
data/spec/zoho_api_spec.rb
CHANGED
@@ -225,6 +225,10 @@ describe ZohoApi do
|
|
225
225
|
r.map { |t| @zoho.delete_record('Tasks', t[:activityid]) }
|
226
226
|
end
|
227
227
|
|
228
|
+
it 'should update fields from a record' do
|
229
|
+
@zoho.module_fields.count.should be >= 7
|
230
|
+
end
|
231
|
+
|
228
232
|
it 'should update a contact' do
|
229
233
|
@zoho.add_record('Contacts', @h_smith)
|
230
234
|
contact = @zoho.find_records('Contacts', :email, '=', @h_smith[:email])
|
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.1.
|
4
|
+
version: 0.1.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httmultiparty
|