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
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(options, status, title, 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.
-
#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_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_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
|
Instance Method Details
#action(options) ⇒ Object
63
64
65
|
# File 'lib/vtiger/commands.rb', line 63
def action(options)
puts "in action"
end
|
#add_account(options, accountname, hashv) ⇒ Object
27
28
29
30
31
|
# File 'lib/vtiger/commands.rb', line 27
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
|
32
33
34
35
36
|
# File 'lib/vtiger/commands.rb', line 32
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
56
57
58
59
60
61
62
|
# File 'lib/vtiger/commands.rb', line 56
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(options, status, title, hashv) ⇒ Object
49
50
51
52
53
54
55
|
# File 'lib/vtiger/commands.rb', line 49
def add_email(options,status,title,hashv)
puts "in add email ticket 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,'Emails')
end
|
#add_trouble_ticket(options, status, title, hashv) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/vtiger/commands.rb', line 42
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
22
23
24
25
26
|
# File 'lib/vtiger/commands.rb', line 22
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
|
281
282
283
284
285
286
287
288
289
290
291
292
293
|
# File 'lib/vtiger/commands.rb', line 281
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
|
37
38
39
40
41
|
# File 'lib/vtiger/commands.rb', line 37
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’)
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
|
# File 'lib/vtiger/commands.rb', line 195
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’,“”)
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
|
# File 'lib/vtiger/commands.rb', line 213
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’,“”)
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
|
# File 'lib/vtiger/commands.rb', line 231
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
|
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/vtiger/commands.rb', line 177
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
268
269
270
271
272
273
274
275
276
277
278
279
280
|
# File 'lib/vtiger/commands.rb', line 268
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
259
260
261
262
263
264
265
266
267
|
# File 'lib/vtiger/commands.rb', line 259
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_and_key_null(element, date, key, extraparam = nil) ⇒ Object
248
249
250
251
252
253
254
255
256
257
258
|
# File 'lib/vtiger/commands.rb', line 248
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
66
67
68
69
70
71
72
|
# File 'lib/vtiger/commands.rb', line 66
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
# File 'lib/vtiger/commands.rb', line 86
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
165
166
167
168
169
170
|
# File 'lib/vtiger/commands.rb', line 165
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
171
172
173
174
175
176
|
# File 'lib/vtiger/commands.rb', line 171
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”})
132
133
134
135
136
137
|
# File 'lib/vtiger/commands.rb', line 132
def query_element_by_email(email,element)
puts "in query element by email"
field='email'
field='email1' if element=='Accounts'
query_element_by_field(element,field,email)
end
|
#query_element_by_field(element, field, name) ⇒ Object
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/vtiger/commands.rb', line 148
def query_element_by_field(element,field,name)
puts "in query element by field"
action_string=ERB::Util.url_encode("select id 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"][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
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/vtiger/commands.rb', line 138
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_product_inventory(options) ⇒ Object
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
|
# File 'lib/vtiger/commands.rb', line 297
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/vtiger/commands.rb', line 110
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
294
295
296
|
# File 'lib/vtiger/commands.rb', line 294
def run_rules(test)
yield(test)
end
|
#update_yahoo(fieldmapping, values, referring_domain, traffic_source, campaign, revenue, actions, search_phrase) ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/vtiger/commands.rb', line 75
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
|