Class: Vtiger::Commands
- Inherits:
-
Base
- Object
- Base
- Vtiger::Commands
show all
- Defined in:
- lib/vtiger/commands.rb
Instance Attribute Summary collapse
Attributes inherited from Base
#access_key, #campaigndb, #endpoint_url, #md5, #session_name, #token, #url, #userid, #username
Class Method Summary
collapse
Instance Method Summary
collapse
-
#action(options) ⇒ Object
-
#add_account(options, accountname, hashv) ⇒ Object
-
#add_contact(options, ln, email, hashv) ⇒ Object
-
#add_document(options, status, title, hashv) ⇒ Object
-
#add_email(parentid, parent_type, description, subject, date_start, from, to, cc, time_start, hashv) ⇒ Object
-
#add_trouble_ticket(options, status, title, hashv) ⇒ Object
-
#addlead(options, ln, co, hashv) ⇒ Object
add a lead with ln last name, co company, and hashv a hash of other values you want to set.
-
#addleademail(options, ln, co, email, hashv) ⇒ Object
-
#check_open_tt_by_contact(contact) ⇒ Object
-
#find_contact_by_email_or_add(options, ln, email, hashv) ⇒ Object
-
#find_items_by_date(element, date, extraparam = nil) ⇒ Object
extraparams like ‘,cf_579’ one day ago — Time.now-60*60*24 eg v.find_items_by_date(‘Contacts’,to_s,‘cf_579’).
-
#find_items_by_date_and_key_not_null(element, date, key, extraparam = nil) ⇒ Object
one day ago — Time.now-60*60*24 eg v.find_items_by_date_and_key_not_null(‘Contacts’,to_s,‘cf_579’,“”).
-
#find_items_by_date_and_key_null(element, date, key, extraparam = nil) ⇒ Object
one day ago — Time.now-60*60*24 eg v.find_items_by_date_and_key_null(‘Contacts’,to_s,‘cf_579’,“”).
-
#find_tt_by_contact(contact) ⇒ Object
-
#get_campaigns ⇒ Object
-
#large_find_items(element, extraparam = nil) ⇒ Object
-
#large_find_items_by_date(element, date, extraparam = nil) ⇒ Object
-
#large_find_items_by_date_and_key_null(element, date, key, extraparam = nil) ⇒ Object
-
#list_types(options) ⇒ Object
-
#process_row(row, fieldmapping, options) ⇒ Object
-
#query_account_by_name(name) ⇒ Object
-
#query_accountlist_by_name(name) ⇒ Object
-
#query_element_by_email(email, element) ⇒ Object
updateobject(options,“#{self.new_quantity”,“productname”=>“#:productname”}).
-
#query_element_by_field(element, field, name) ⇒ Object
-
#query_elementlist_by_field(element, field, name) ⇒ Object
-
#query_lead_by_email(name) ⇒ Object
-
#query_product_inventory(options) ⇒ Object
-
#query_tsipid(id, fieldmapping, options) ⇒ Object
-
#run_rules(test) {|test| ... } ⇒ Object
-
#update_yahoo(fieldmapping, values, referring_domain, traffic_source, campaign, revenue, actions, search_phrase) ⇒ Object
Methods inherited from Base
#accessdatabase, #accessdatabase2, #add_object, #addobject, #challenge, #create_digest, #describe_object, #get_contacts_by_cf, #get_contacts_by_email_and_keynull, #get_contacts_from_campaign, #get_list_from_campaign, #http_ask_get, #http_crm_post, #json_parse, #json_please, #large_query, #login, #query, #retrieve_object, #updateobject
Instance Attribute Details
#account_name ⇒ Object
Returns the value of attribute account_name.
16
17
18
|
# File 'lib/vtiger/commands.rb', line 16
def account_name
@account_name
end
|
#new_quantity ⇒ Object
Returns the value of attribute new_quantity.
16
17
18
|
# File 'lib/vtiger/commands.rb', line 16
def new_quantity
@new_quantity
end
|
#object_id ⇒ Object
Returns the value of attribute object_id.
16
17
18
|
# File 'lib/vtiger/commands.rb', line 16
def object_id
@object_id
end
|
#product_id ⇒ Object
Returns the value of attribute product_id.
16
17
18
|
# File 'lib/vtiger/commands.rb', line 16
def product_id
@product_id
end
|
#qty_in_stock ⇒ Object
Returns the value of attribute qty_in_stock.
16
17
18
|
# File 'lib/vtiger/commands.rb', line 16
def qty_in_stock
@qty_in_stock
end
|
Class Method Details
.vtiger_factory(api) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/vtiger/commands.rb', line 18
def self.vtiger_factory(api)
Vtiger::Api.api_settings=api
puts "Using #{Vtiger::Api.api_settings.inspect}"
cmd = Vtiger::Commands.new()
options={}
challenge=cmd.challenge(options)
login=cmd.login(options)
puts "VTIGER FACTORY: #{login} session name is: #{cmd.session_name} userid #{cmd.userid} #{cmd.inspect}"
cmd
end
|
Instance Method Details
#action(options) ⇒ Object
82
83
84
|
# File 'lib/vtiger/commands.rb', line 82
def action(options)
puts "in action"
end
|
#add_account(options, accountname, hashv) ⇒ Object
42
43
44
45
46
|
# File 'lib/vtiger/commands.rb', line 42
def add_account(options,accountname,hashv)
puts "in addobject"
object_map= { 'assigned_user_id'=>"#{self.userid}",'accountname'=>"#{accountname}"}
add_object(object_map,hashv,'Accounts')
end
|
47
48
49
50
51
|
# File 'lib/vtiger/commands.rb', line 47
def add_contact(options,ln,email,hashv)
puts "in contact"
object_map= { 'assigned_user_id'=>"#{self.userid}",'lastname'=>"#{ln}", 'email'=>"#{email}"}
add_object(object_map,hashv,'Contacts')
end
|
#add_document(options, status, title, hashv) ⇒ Object
75
76
77
78
79
80
81
|
# File 'lib/vtiger/commands.rb', line 75
def add_document(options,status,title,hashv)
puts "in add document NOT COMPLETE"
object_map= { 'assigned_user_id'=>"#{self.userid}",'ticketstatus'=>"#{status}", 'ticket_title'=>"#{title}"}
object_map=object_map.merge hashv
add_object(object_map,hashv,'Documents')
end
|
#add_email(parentid, parent_type, description, subject, date_start, from, to, cc, time_start, hashv) ⇒ Object
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/vtiger/commands.rb', line 65
def add_email(parentid,parent_type,description,subject,date_start,from,to,cc, time_start, hashv)
puts "in add email"
object_map= { 'assigned_user_id'=>"#{self.userid}",'parent_id'=>"#{parentid}", 'parent_type'=> "#{parent_type}",
'description' => "#{description}",'subject'=>"#{subject}", 'time'=> "#{time_start}", 'date_start'=>"#{date_start}" ,
'saved_toid' => "#{to}", 'ccmail' => "#{cc}",'from_email'=> "#{from}"
}
object_map=object_map.merge hashv
add_object(object_map,hashv,'Emails')
end
|
#add_trouble_ticket(options, status, title, hashv) ⇒ Object
58
59
60
61
62
63
64
|
# File 'lib/vtiger/commands.rb', line 58
def add_trouble_ticket(options,status,title,hashv)
puts "in add trouble ticket"
object_map= { 'assigned_user_id'=>"#{self.userid}",'ticketstatus'=>"#{status}", 'ticket_title'=>"#{title}"}
object_map=object_map.merge hashv
add_object(object_map,hashv,'HelpDesk')
end
|
#addlead(options, ln, co, hashv) ⇒ Object
add a lead with ln last name, co company, and hashv a hash of other values you want to set
32
33
34
35
36
|
# File 'lib/vtiger/commands.rb', line 32
def addlead(options,ln,co,hashv)
puts "in addobject"
object_map= { 'assigned_user_id'=>"#{self.userid}",'lastname'=>"#{ln}", 'company'=>"#{co}"}
add_object(object_map,hashv,'Leads')
end
|
#addleademail(options, ln, co, email, hashv) ⇒ Object
37
38
39
40
41
|
# File 'lib/vtiger/commands.rb', line 37
def addleademail(options,ln,co,email,hashv)
puts "in addobject"
object_map= { 'assigned_user_id'=>"#{self.userid}",'lastname'=>"#{ln}", 'company'=>"#{co}", 'email'=>"#{email}"}
add_object(object_map,hashv,'Leads')
end
|
317
318
319
320
321
322
323
324
325
326
327
328
329
|
# File 'lib/vtiger/commands.rb', line 317
def check_open_tt_by_contact(contact)
puts "in query open tt by contact"
action_string=ERB::Util.url_encode("select id,ticket_no from HelpDesk where parent_id = '#{contact}' and ticketstatus like 'Open';")
res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
values=res["result"] if res["success"]==true ticketlist=[]
values.each {|v| ticketlist << v['ticket_no'] }
return res["success"],ticketlist
end
|
53
54
55
56
57
|
# File 'lib/vtiger/commands.rb', line 53
def find_contact_by_email_or_add(options,ln,email,hashv)
success,id = query_element_by_email(email,"Contacts")
success,id =add_contact(options,ln,email,hashv) if !success
return success,id
end
|
#find_items_by_date(element, date, extraparam = nil) ⇒ Object
extraparams like ‘,cf_579’ one day ago — Time.now-60*60*24 eg v.find_items_by_date(‘Contacts’,to_s,‘cf_579’)
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
|
# File 'lib/vtiger/commands.rb', line 220
def find_items_by_date(element,date,=nil)
puts "in query by date "
queryparams=''
queryparams=",#{}" if !=nil
t=Time.parse(date)
y=t.strftime('%Y-%m-%d')
action_string=ERB::Util.url_encode("select id#{queryparams} from #{element} where createdtime like '#{y}%';")
res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
puts "TT RES: #{res["result"]} class: #{res["result"].class}"
values=res["result"] if res["success"]==true
return res["success"],values
end
|
#find_items_by_date_and_key_not_null(element, date, key, extraparam = nil) ⇒ Object
one day ago — Time.now-60*60*24 eg v.find_items_by_date_and_key_not_null(‘Contacts’,to_s,‘cf_579’,“”)
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
# File 'lib/vtiger/commands.rb', line 238
def find_items_by_date_and_key_not_null(element,date,key, =nil)
puts "in query by date and not null "
queryparams=''
queryparams=",#{}" if !=nil
t=Time.parse(date)
y=t.strftime('%Y-%m-%d')
action_string=ERB::Util.url_encode("select id,#{key}#{queryparams} from #{element} where createdtime like '#{y}%' and #{key} LIKE '2%' and emailoptout=0;")
puts "action string:" +action_string
res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
puts "TT RES: #{res["result"]} class: #{res["result"].class}"
values=res["result"] if res["success"]==true
return res["success"],values
end
|
#find_items_by_date_and_key_null(element, date, key, extraparam = nil) ⇒ Object
one day ago — Time.now-60*60*24 eg v.find_items_by_date_and_key_null(‘Contacts’,to_s,‘cf_579’,“”)
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
|
# File 'lib/vtiger/commands.rb', line 256
def find_items_by_date_and_key_null(element,date,key, =nil)
puts "in query by date #{date} and not null "
queryparams=''
queryparams=",#{}" if !=nil
t=Time.parse(date)
y=t.strftime('%Y-%m-%d')
action_string=ERB::Util.url_encode("select id,#{key}#{queryparams} from #{element} where createdtime like '#{y}%' and #{key} < '0' and emailoptout=0;")
puts "action string:" +action_string
res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
puts "TT RES: #{res["result"]} class: #{res["result"].class}"
values=res["result"] if res["success"]==true
return res["success"],values
end
|
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
# File 'lib/vtiger/commands.rb', line 202
def find_tt_by_contact(contact)
puts "in query tt by contact"
action_string=ERB::Util.url_encode("select id,ticket_no from HelpDesk where parent_id = '#{contact}';")
res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
puts "TT RES: #{res["result"]} class: #{res["result"].class}"
values=res["result"] if res["success"]==true ticketlist=[]
values.each {|v| ticketlist << v['ticket_no'] }
return res["success"],ticketlist
end
|
#get_campaigns ⇒ Object
304
305
306
307
308
309
310
311
312
313
314
315
316
|
# File 'lib/vtiger/commands.rb', line 304
def get_campaigns
puts "in get campaigns"
action_string=ERB::Util.url_encode("select id,campaignname from Campaigns;")
res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
values=res["result"] if res["success"]==true return res["success"],values
end
|
#large_find_items(element, extraparam = nil) ⇒ Object
295
296
297
298
299
300
301
302
303
|
# File 'lib/vtiger/commands.rb', line 295
def large_find_items(element, =nil)
queryparams=''
queryparams=",#{}" if !=nil
querystring="select id#{queryparams},emailoptout,email,lastname,firstname from #{element}"
countstring="select count(*) from #{element}"
succ, values =self.large_query(countstring,querystring)
end
|
#large_find_items_by_date(element, date, extraparam = nil) ⇒ Object
284
285
286
287
288
289
290
291
292
293
294
|
# File 'lib/vtiger/commands.rb', line 284
def large_find_items_by_date(element,date, =nil)
queryparams=''
queryparams=",#{}" if !=nil
t=Time.parse(date)
y=t.strftime('%Y-%m-%d')
querystring="select id#{queryparams} from #{element} where createdtime like '#{y}%' and emailoptout=0"
countstring="select count(*) from #{element} where createdtime like '#{y}%' and emailoptout=0"
succ, values =self.large_query(countstring,querystring)
end
|
#large_find_items_by_date_and_key_null(element, date, key, extraparam = nil) ⇒ Object
273
274
275
276
277
278
279
280
281
282
283
|
# File 'lib/vtiger/commands.rb', line 273
def large_find_items_by_date_and_key_null(element,date,key, =nil)
queryparams=''
queryparams=",#{}" if !=nil
t=Time.parse(date)
y=t.strftime('%Y-%m-%d')
querystring="select id,#{key}#{queryparams} from #{element} where createdtime like '#{y}%' and #{key} < '0' and emailoptout=0"
countstring="select count(*) from #{element} where createdtime like '#{y}%' and #{key} < '0' and emailoptout=0"
succ, values =self.large_query(countstring,querystring)
end
|
#list_types(options) ⇒ Object
85
86
87
88
89
90
91
|
# File 'lib/vtiger/commands.rb', line 85
def list_types(options)
puts "in list types"
result = http_ask_get(self.endpoint_url+"operation=listtypes&sessionName=#{self.session_name}")
end
|
#process_row(row, fieldmapping, options) ⇒ Object
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/vtiger/commands.rb', line 105
def process_row(row,fieldmapping,options)
result_summary=""
success=false
member_label="Member"
refering_domain_label="Referring URL (Direct)"
traffic_src_label="Traffic Sources (Intelligent)"
campaign_label="Campaign"
unique_label="Unique Actions"
rev_label="Revenue"
search_label="Search Phrases (Direct)"
account_id = self.query_tsipid(row[member_label].to_s,fieldmapping,options)
if account_id!='failed'
values=self.retrieve_object(account_id)
self.update_yahoo(fieldmapping,values,row[refering_domain_label],
row[traffic_src_label], row[campaign_label],row[rev_label],row[unique_label],row[search_label])
result_summary = " Success: row of yahoo csv with TSIPID: #{row[member_label].to_s}\n"
success=true
else
result_summary =" Failure: row of yahoo csv with Member: #{row[member_label].to_s}\n"
end return success,result_summary
end
|
#query_account_by_name(name) ⇒ Object
190
191
192
193
194
195
|
# File 'lib/vtiger/commands.rb', line 190
def query_account_by_name(name)
puts "in query account by name"
element='Accounts'
field='accountname'
query_element_by_field(element,field,name)
end
|
#query_accountlist_by_name(name) ⇒ Object
196
197
198
199
200
201
|
# File 'lib/vtiger/commands.rb', line 196
def query_accountlist_by_name(name)
puts "in query accountlist by name: #{name}"
element='Accounts'
field='accountname'
query_elementlist_by_field(element,field,name)
end
|
#query_element_by_email(email, element) ⇒ Object
updateobject(options,“#{self.new_quantity”,“productname”=>“#:productname”})
151
152
153
154
155
156
|
# File 'lib/vtiger/commands.rb', line 151
def query_element_by_email(email,element)
puts "in query element by email #{email} #{element}"
field='email'
field='email1' if element=='Accounts'
query_element_by_field(element,field,email)
end
|
#query_element_by_field(element, field, name) ⇒ Object
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/vtiger/commands.rb', line 167
def query_element_by_field(element,field,name)
puts "in query element by field #{field} #{element} name: #{name}"
action_string=ERB::Util.url_encode("select id from #{element} where #{field} like '#{name}';")
puts "action string:" +action_string
res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
values=res["result"][0] if res["success"]==true success = false
self.object_id = 'failed'
if values!= nil
self.object_id=values["id"]
success=true
end
return success,self.object_id
end
|
#query_elementlist_by_field(element, field, name) ⇒ Object
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/vtiger/commands.rb', line 157
def query_elementlist_by_field(element,field,name)
puts "in query element by field"
action_string=ERB::Util.url_encode("select id,#{field} from #{element} where #{field} like '#{name}%';")
res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
values=res["result"] if res["success"]==true success = res["success"]
return success,values
end
|
#query_lead_by_email(name) ⇒ Object
184
185
186
187
188
189
|
# File 'lib/vtiger/commands.rb', line 184
def query_lead_by_email(name)
puts "in query lead by email"
element='Leads'
field='email'
query_element_by_field(element,field,name)
end
|
#query_product_inventory(options) ⇒ Object
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
|
# File 'lib/vtiger/commands.rb', line 333
def query_product_inventory(options)
puts "in query product count"
action_string=ERB::Util.url_encode("select id, qtyinstock, productname from Products where productname like '#{options[:productname]}';")
res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
puts JSON.pretty_generate(res)
values=res["result"][0] puts values.inspect
self.product_id = values["id"]
self.object_id=self.product_id
self.qty_in_stock = values["qtyinstock"]
self.new_quantity = self.qty_in_stock.to_i + options[:quantity].to_i
puts "#{self.product_id}, #{self.qty_in_stock} New quantity should be: #{self.new_quantity}"
updateobject({'qtyinstock'=> "#{self.new_quantity}","productname"=>"#{options[:productname]}"})
end
|
#query_tsipid(id, fieldmapping, options) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/vtiger/commands.rb', line 129
def query_tsipid(id,fieldmapping,options)
puts "in query id"
action_string=ERB::Util.url_encode("select id,lastname from #{options[:element_type]} where #{fieldmapping[:tsipid]} = '#{id}';")
res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
values=res["result"][0] self.object_id = 'failed'
if values!= nil
self.object_id=values["id"]
self.account_name=values["accountname"]
end
self.object_id
end
|
#run_rules(test) {|test| ... } ⇒ Object
330
331
332
|
# File 'lib/vtiger/commands.rb', line 330
def run_rules(test)
yield(test)
end
|
#update_yahoo(fieldmapping, values, referring_domain, traffic_source, campaign, revenue, actions, search_phrase) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
|
# File 'lib/vtiger/commands.rb', line 94
def update_yahoo(fieldmapping,values,referring_domain,traffic_source, campaign,revenue,actions,search_phrase)
values[fieldmapping[:referring_domain].to_s]=referring_domain
values[fieldmapping[:revenue].to_s]=revenue values[fieldmapping[:unique_actions].to_s]=actions values[fieldmapping[:search_phrase].to_s]=search_phrase
updateobject(values)
end
|