vtiger 0.7.8 → 0.8.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.
- data/bin/update_lead.rb +147 -0
- data/lib/vtiger/base.rb +1 -1
- data/lib/vtiger/commands.rb +6 -0
- data/lib/vtiger/support.rb +2 -0
- metadata +5 -3
data/bin/update_lead.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
usage=<<EOF_USAGE
|
3
|
+
|
4
|
+
# == Synopsis
|
5
|
+
# read a csv file and update leads in a crm system - this is specific example but you can modify as you see fit
|
6
|
+
# == Usage
|
7
|
+
# update_lead.rb -u democrm.estormtech.com -c test -e Contacts -n scott -k xxxxx -f csvfile
|
8
|
+
# csv file needs to be in the format (including headers) with destination, template, asmanyparameters as needed separated by commas
|
9
|
+
# == Author
|
10
|
+
# Scott Sproule --- Ficonab.com (scott.sproule@ficonab.com)
|
11
|
+
# == Example
|
12
|
+
# update_lead.rb -u xxxx -p yyyy -f yyy.csv
|
13
|
+
# == Copyright
|
14
|
+
# Copyright (c) 2011 Ficonab Pte. Ltd.
|
15
|
+
# See license for license details
|
16
|
+
EOF_USAGE
|
17
|
+
require 'yaml'
|
18
|
+
require 'rubygems'
|
19
|
+
require 'uri'
|
20
|
+
gem 'ficonabses'
|
21
|
+
gem 'fastercsv'
|
22
|
+
gem 'vtiger'
|
23
|
+
require 'vtiger'
|
24
|
+
require 'fastercsv'
|
25
|
+
require 'ficonabses'
|
26
|
+
require 'optparse'
|
27
|
+
#require 'java' if RUBY_PLATFORM =~ /java/
|
28
|
+
# start the processing
|
29
|
+
def process_row(vtiger,row,newgroup)
|
30
|
+
#puts "row destination: #{row['destination']} template: #{row['template']} campaign: #{row['campaign']} campaign flag: #{flag}"
|
31
|
+
|
32
|
+
# puts "row is #{row.inspect}"
|
33
|
+
if row!=nil then
|
34
|
+
result=true
|
35
|
+
result, id=vtiger.query_element_by_email(row['email'],'Leads')
|
36
|
+
row['phone']=row['telephone']
|
37
|
+
if result then #UPDATE SINCE IT EXISTS
|
38
|
+
values={}
|
39
|
+
values=vtiger.retrieve_object(id)
|
40
|
+
|
41
|
+
if values['cf_632']==nil or values['cf_632']=='' then
|
42
|
+
values['cf_632']=newgroup.to_s
|
43
|
+
else
|
44
|
+
values['cf_632']="#{values['cf_632']} |##| #{newgroup.to_s}" if !values['cf_632'].include? newgroup.to_s #NOTE multi slect separator
|
45
|
+
end
|
46
|
+
puts "found #{id} for #{row['email']} new group is #{values['cf_632']}"
|
47
|
+
# grup is cf_632
|
48
|
+
row['id']=id
|
49
|
+
values['id']=id
|
50
|
+
values = row.merge values #NOTE values will override the row where these is existing data
|
51
|
+
values['mobile']=row['cf_643']
|
52
|
+
values['lane']=row['cf_631']
|
53
|
+
values['phone']=row['cf_646']
|
54
|
+
values['fax']=row['cf_645']
|
55
|
+
row.each { |k,v| values[k]=v if values[k]==''}
|
56
|
+
values.each { |k,v| values[k]="" if v==nil} #remove nils
|
57
|
+
values.delete(nil)
|
58
|
+
|
59
|
+
@oldcount=@oldcount+1
|
60
|
+
|
61
|
+
result=vtiger.updateobject(values)
|
62
|
+
if result['success']!=true then
|
63
|
+
newvalues=values.clone
|
64
|
+
result, id=vtiger.query_element_by_email(row['email'],'Leads')
|
65
|
+
newvalues['id']=id
|
66
|
+
puts "FAILED UPDATE try again"
|
67
|
+
result=vtiger.updateobject(newvalues)
|
68
|
+
@failed << row if result['success']!=true
|
69
|
+
end
|
70
|
+
puts "result: #{result} values were #{values.inspect}"
|
71
|
+
puts "UPDATE=================END UPDATE"
|
72
|
+
else #CREATE SINCE NOT IN SYSTEM
|
73
|
+
puts "in else statement -Just add the lead"
|
74
|
+
#SET THE GROUP HERE
|
75
|
+
@newcount=@newcount+1
|
76
|
+
row['cf_632']=newgroup.to_s
|
77
|
+
row['mobile']=row['cf_643']
|
78
|
+
row['phone']=row['cf_646']
|
79
|
+
row['fax']=row['cf_645']
|
80
|
+
row['lane']=row['cf_631']
|
81
|
+
row['company']=row['email'] if row['company']==nil or row['company']==''
|
82
|
+
row['company']=row['lastname'] if row['company']==nil or row['company']==''
|
83
|
+
result,id =vtiger.addleademail(row,row['lastname'],row['company'],row['email'],row)
|
84
|
+
puts "adding lead #{row['email']} company #{row['company']} with group: #{newgroup}"
|
85
|
+
puts "result: #{result} id #{id} values were #{row.inspect}"
|
86
|
+
puts "ADD=================END ADD"
|
87
|
+
@failed << row if !result
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
result
|
92
|
+
end
|
93
|
+
def readfile(filename)
|
94
|
+
csvfile=File.open(filename,'r')
|
95
|
+
rawfile= FasterCSV.parse(csvfile.read, { :headers => true})
|
96
|
+
rawfile
|
97
|
+
end
|
98
|
+
def manage_row(vtiger,row,options)
|
99
|
+
begin
|
100
|
+
hash={}
|
101
|
+
hash=hash.merge row
|
102
|
+
res=process_row(vtiger,hash.clone,options[:group])
|
103
|
+
puts "COUNT: #{@count} result: #{res} row: #{hash} "
|
104
|
+
@count+=1
|
105
|
+
|
106
|
+
rescue Exception => e
|
107
|
+
@errors+=1
|
108
|
+
puts "ERROR===Found count: #{@count} error #{e.inspect}"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
arg_hash=Vtiger::Options.parse_options(ARGV)
|
112
|
+
Vtiger::Options.show_usage_exit(usage) if arg_hash[:help]==true
|
113
|
+
|
114
|
+
require 'pp'
|
115
|
+
options=arg_hash
|
116
|
+
puts "[#{Time.now}] START"
|
117
|
+
VTIGERAPIHASH = {
|
118
|
+
:username => options[:username],
|
119
|
+
:key => options[:key],
|
120
|
+
# :username => 'admin',
|
121
|
+
# :key => 'ISGRkVGyEYunzQlD',
|
122
|
+
:url => options[:url],
|
123
|
+
}
|
124
|
+
puts "API HASH #{VTIGERAPIHASH.inspect}"
|
125
|
+
#Vtiger::Api.api_settings=VTIGERAPIHASH
|
126
|
+
@failed=[]
|
127
|
+
@count=0
|
128
|
+
@errors=0
|
129
|
+
vtiger_cmd =Vtiger::Commands.vtiger_factory(VTIGERAPIHASH)
|
130
|
+
@newcount=0
|
131
|
+
@oldcount=0
|
132
|
+
rows=readfile(options[:filename])
|
133
|
+
rows.each {|row| manage_row(vtiger_cmd,row,options)
|
134
|
+
#puts "row is: #{row}"
|
135
|
+
|
136
|
+
}
|
137
|
+
rows=@failed.clone
|
138
|
+
vtiger_cmd =Vtiger::Commands.vtiger_factory(VTIGERAPIHASH)
|
139
|
+
@failed=[]
|
140
|
+
rows.each {|row|
|
141
|
+
puts "processing failed row is: #{row}"
|
142
|
+
manage_row(vtiger_cmd,row,options)
|
143
|
+
}
|
144
|
+
|
145
|
+
# puts "response is list is #{list.to_yaml} #{finallist.to_yaml}"
|
146
|
+
puts "[#{Time.now}] FINISHED: sending: #{@count} error count #{@errors} new count #{@newcount} oldcount #{@oldcount}"
|
147
|
+
puts "Failures count #{@failed.size} are:====== #{@failed.inspect}"
|
data/lib/vtiger/base.rb
CHANGED
@@ -151,7 +151,7 @@ end
|
|
151
151
|
return finalres, output
|
152
152
|
end
|
153
153
|
def add_object(object_map,hashv,element)
|
154
|
-
object_map=
|
154
|
+
object_map=hashv.merge object_map # object map overrides
|
155
155
|
# 'tsipid'=>"1234"
|
156
156
|
tmp=self.json_please(object_map)
|
157
157
|
input_array ={'operation'=>'create','elementType'=>"#{element}",'sessionName'=>"#{self.session_name}", 'element'=>tmp} # removed the true
|
data/lib/vtiger/commands.rb
CHANGED
@@ -33,6 +33,11 @@ module Vtiger
|
|
33
33
|
puts "in addobject"
|
34
34
|
object_map= { 'assigned_user_id'=>"#{self.userid}",'lastname'=>"#{ln}", 'company'=>"#{co}"}
|
35
35
|
add_object(object_map,hashv,'Leads')
|
36
|
+
end
|
37
|
+
def addleademail(options,ln,co,email,hashv)
|
38
|
+
puts "in addobject"
|
39
|
+
object_map= { 'assigned_user_id'=>"#{self.userid}",'lastname'=>"#{ln}", 'company'=>"#{co}", 'email'=>"#{email}"}
|
40
|
+
add_object(object_map,hashv,'Leads')
|
36
41
|
end
|
37
42
|
def add_account(options,accountname,hashv)
|
38
43
|
puts "in addobject"
|
@@ -44,6 +49,7 @@ module Vtiger
|
|
44
49
|
object_map= { 'assigned_user_id'=>"#{self.userid}",'lastname'=>"#{ln}", 'email'=>"#{email}"}
|
45
50
|
add_object(object_map,hashv,'Contacts')
|
46
51
|
end
|
52
|
+
|
47
53
|
def find_contact_by_email_or_add(options,ln,email,hashv)
|
48
54
|
success,id = query_element_by_email(email,"Contacts")
|
49
55
|
success,id =add_contact(options,ln,email,hashv) if !success
|
data/lib/vtiger/support.rb
CHANGED
@@ -46,6 +46,8 @@ module Vtiger
|
|
46
46
|
puts "objectid #{val}" }
|
47
47
|
opts.on("-q","--query VAL", String) {|val| temp_hash[:query ] = val
|
48
48
|
puts "contact #{val}" }
|
49
|
+
opts.on("-g","--group VAL", String) {|val| temp_hash[:group ] = val
|
50
|
+
puts "group #{val}" }
|
49
51
|
opts.on("-e","--elementtype VAL", String) {|val| temp_hash[:element_type ] = val
|
50
52
|
puts "elementtype #{val}" }
|
51
53
|
opts.on("-k","--access_key VAL", String) {|val| temp_hash[:key ] = val
|
metadata
CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
|
-
- 7
|
8
7
|
- 8
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 0.8.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Scott Sproule
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-
|
17
|
+
date: 2012-08-06 00:00:00 +08:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -23,6 +23,7 @@ email: scott.sproule@estormtech.com
|
|
23
23
|
executables:
|
24
24
|
- add_contact.rb
|
25
25
|
- add_lead.rb
|
26
|
+
- update_lead.rb
|
26
27
|
- add_email.rb
|
27
28
|
- describe_object.rb
|
28
29
|
- list_types.rb
|
@@ -52,6 +53,7 @@ files:
|
|
52
53
|
- bin/helloworld.rb
|
53
54
|
- bin/list_types.rb
|
54
55
|
- bin/query.rb
|
56
|
+
- bin/update_lead.rb
|
55
57
|
- bin/update_stock_inventory.rb
|
56
58
|
- bin/yahoo_csv.rb
|
57
59
|
- History.txt
|