vtiger 0.3.8 → 0.4.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/lib/vtiger/base.rb CHANGED
@@ -38,7 +38,7 @@ module Vtiger
38
38
  #access key from my_preferences page of vtiger
39
39
  digest_string="#{self.token}#{self.access_key}"
40
40
  self.md5=Digest::MD5.hexdigest(digest_string)
41
- puts "#{self.url}: string #{digest_string} results in digest: "+self.md5 + " access key: "+ self.access_key + " token: " + self.token
41
+ # puts "#{self.url}: string #{digest_string} results in digest: "+self.md5 + " access key: "+ self.access_key + " token: " + self.token
42
42
  end
43
43
  def http_crm_post(operation, body)
44
44
  response = nil
@@ -80,7 +80,7 @@ module Vtiger
80
80
  # 'tsipid'=>"1234"
81
81
  tmp=self.json_please(object_map)
82
82
  input_array ={'operation'=>'create','elementType'=>"#{element}",'sessionName'=>"#{self.session_name}", 'element'=>tmp} # removed the true
83
- puts "input array:" + input_array.to_s #&username=#{self.username}&accessKey=#{self.md5}
83
+ # puts "input array:" + input_array.to_s #&username=#{self.username}&accessKey=#{self.md5}
84
84
  # scott not working -- JSON.generate(input_array,{'array_nl'=>'true'})
85
85
  result = http_crm_post("operation=create",input_array)
86
86
  # self.session_name=result["result"]["sessionName"]
@@ -92,12 +92,12 @@ module Vtiger
92
92
  def login(options)
93
93
  # puts "in login"
94
94
  input_array ={'operation'=>'login', 'username'=>self.username, 'accessKey'=>self.md5} # removed the true
95
- puts "input array:" + input_array.to_s #&username=#{self.username}&accessKey=#{self.md5}
95
+ #puts "input array:" + input_array.to_s #&username=#{self.username}&accessKey=#{self.md5}
96
96
  # scott not working -- JSON.generate(input_array,{'array_nl'=>'true'})
97
97
  result = http_crm_post("operation=login",input_array)
98
98
  self.session_name=result["result"]["sessionName"] if result["result"]!=nil
99
99
  self.userid = result["result"]["userId"] if result["result"]!=nil
100
- puts "session name is: #{self.session_name} userid #{self.userid}"
100
+ # puts "session name is: #{self.session_name} userid #{self.userid}"
101
101
  self.userid!=nil
102
102
  end
103
103
  def retrieve_object(objid)
@@ -134,7 +134,7 @@ def addobject(options)
134
134
  # 'tsipid'=>"1234"
135
135
  tmp=self.json_please(object_map)
136
136
  input_array ={'operation'=>'create','elementType'=>"#{options[:element_type]}",'sessionName'=>"#{self.session_name}", 'element'=>tmp} # removed the true
137
- puts "input array:" + input_array.to_s #&username=#{self.username}&accessKey=#{self.md5}
137
+ # puts "input array:" + input_array.to_s #&username=#{self.username}&accessKey=#{self.md5}
138
138
  # scott not working -- JSON.generate(input_array,{'array_nl'=>'true'})
139
139
  result = http_crm_post("operation=create",input_array)
140
140
  # self.session_name=result["result"]["sessionName"]
@@ -150,7 +150,7 @@ def json_please(object_map)
150
150
  #puts "in JSON code rails env: #{RAILS_ENV}"
151
151
  tmp=object_map.to_json
152
152
  else
153
- puts "rails env is not defined"
153
+ # puts "rails env is not defined"
154
154
  # json = StringIO.new()
155
155
  str = Yajl::Encoder.encode(object_map)
156
156
 
@@ -164,7 +164,9 @@ def json_please(object_map)
164
164
  end
165
165
  def updateobject(values)
166
166
  #puts "in updateobject"
167
- object_map= { 'assigned_user_id'=>"#{self.userid}",'id'=>"#{self.object_id}" }.merge values.to_hash
167
+ # object_map= { 'assigned_user_id'=>"#{self.userid}"}.merge values.to_hash
168
+ object_map= values.to_hash
169
+ object_map['assigned_user_id']=self.userid
168
170
  # 'tsipid'=>"1234"
169
171
  tmp=self.json_please(object_map)
170
172
  input_array ={'operation'=>'update','sessionName'=>"#{self.session_name}", 'element'=>tmp} # removed the true
@@ -94,7 +94,7 @@ module Vtiger
94
94
  # scott not working -- JSON.generate(input_array,{'array_nl'=>'true'})
95
95
  action_string=ERB::Util.url_encode("select id,lastname from #{options[:element_type]} where #{fieldmapping[:tsipid]} = '#{id}';")
96
96
  # action_string=ERB::Util.url_encode("select id,accountname from #{options[:element_type]} where #{fieldmapping[:tsipid]} = '#{id}';") ACCOUNTS
97
- puts "action string:" +action_string
97
+ # puts "action string:" +action_string
98
98
  res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
99
99
  # http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&userId=#{self.userid}&query="+action_string)
100
100
  # puts JSON.pretty_generate(res)
@@ -111,27 +111,46 @@ module Vtiger
111
111
  # updateobject(options,{'qtyinstock'=> "#{self.new_quantity}","productname"=>"#{options[:productname]}"})
112
112
  end
113
113
  def query_element_by_email(email,element)
114
- puts "in query contact"
114
+ puts "in query element by email"
115
115
  action_string=ERB::Util.url_encode("select id from #{element} where email like '#{email}';")
116
- puts "action string:" +action_string
116
+ # puts "action string:" +action_string
117
117
  res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
118
118
  values=res["result"][0] if res["success"]==true #comes back as array
119
+ success = false
119
120
  #puts values.inspect
120
121
  # return the account id
121
122
  self.object_id = 'failed'
122
123
  if values!= nil
123
124
  self.object_id=values["id"]
124
- self.account_name=values["accountname"]
125
+ success=true
126
+ # self.account_name=values["accountname"]
125
127
  end
126
- return res["success"],self.object_id
127
-
128
+
129
+ return success,self.object_id
128
130
  end
131
+ def find_tt_by_contact(contact)
132
+ puts "in query tt by contact"
133
+ action_string=ERB::Util.url_encode("select id,ticket_no from HelpDesk where parent_id = '#{contact}';")
134
+ # puts "action string:" +action_string
135
+ res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
136
+ puts "TT RES: #{res["result"]} class: #{res["result"].class}"
137
+ values=res["result"] if res["success"]==true #comes back as array
138
+ #puts values.inspect
139
+ # return the account id
140
+ ticketlist=[]
141
+ values.each {|v| ticketlist << v['ticket_no'] }
142
+ return res["success"],ticketlist
143
+
144
+ end
145
+ def run_rules(test)
146
+ yield(test)
147
+ end
129
148
  def query_product_inventory(options)
130
149
  puts "in query product count"
131
150
  #&username=#{self.username}&accessKey=#{self.md5}
132
151
  # scott not working -- JSON.generate(input_array,{'array_nl'=>'true'})
133
152
  action_string=ERB::Util.url_encode("select id, qtyinstock, productname from Products where productname like '#{options[:productname]}';")
134
- puts "action string:" +action_string
153
+ #puts "action string:" +action_string
135
154
  res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
136
155
  # http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&userId=#{self.userid}&query="+action_string)
137
156
  puts JSON.pretty_generate(res)
data/test/test_vtiger.rb CHANGED
@@ -104,6 +104,23 @@ class TestVtiger < Test::Unit::TestCase
104
104
  assert success,"add should succeed"
105
105
  puts "id is #{id}"
106
106
  end
107
+ def test_update_contact
108
+ puts "in update contact"
109
+ cmd = Vtiger::Commands.new()
110
+ challenge=cmd.challenge(@options)
111
+ login=cmd.login(@options)
112
+ hv={}
113
+
114
+ success,id=cmd.query_element_by_email("scott.sproule@gmail.com","Contacts")
115
+ values=cmd.retrieve_object(id)
116
+ values['firstname']='testupdtae'
117
+ upd= cmd.updateobject(values)
118
+ assert challenge,"challenge is false "
119
+ assert login,"login should succeed"
120
+ assert success,"add should succeed"
121
+ assert upd,"update should succeed"
122
+ puts "id is #{id}"
123
+ end
107
124
 
108
125
  def test_add_trouble_ticket
109
126
  cmd = Vtiger::Commands.new()
@@ -118,7 +135,32 @@ class TestVtiger < Test::Unit::TestCase
118
135
  assert login,"login should succeed"
119
136
  assert tt,"trouble ticket should succeed"
120
137
  end
121
-
138
+ def test_rule_block
139
+ cmd = Vtiger::Commands.new()
140
+ challenge=cmd.challenge(@options)
141
+ login=cmd.login(@options)
142
+ res=cmd.run_rules("hello") {|t| puts "RULE BLOCK #{t} what is self? #{self.inspect} class #{self.class}"
143
+ return t=="hello"}
144
+ assert challenge,"challenge is false "
145
+ assert login,"login should succeed"
146
+ assert res,"rules should succeed"
147
+ end
148
+ def test_find_trouble_ticket_by_contacts
149
+ cmd = Vtiger::Commands.new()
150
+ challenge=cmd.challenge(@options)
151
+ login=cmd.login(@options)
152
+ hv={}
153
+ # hv[:firstname]='test'
154
+ success,contact_id=cmd.query_element_by_email("scott.sproule@gmail.com","Contacts")
155
+ tt,ticketlist=cmd.find_tt_by_contact(contact_id) if success
156
+
157
+ puts "trouble ticket is #{tt} ticket number is #{ticketlist}"
158
+ assert challenge,"challenge is false "
159
+ assert success,"could not find contact id with email scott.sproule@gmail.com "
160
+ assert login,"login should succeed"
161
+ assert tt,"trouble ticket findersshould succeed"
162
+ puts "tickelist is #{ticketlist}"
163
+ end
122
164
  def test_describe_object
123
165
  cmd = Vtiger::Commands.new()
124
166
  challenge=cmd.challenge(@options)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vtiger
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 8
10
- version: 0.3.8
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Scott Sproule
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-24 00:00:00 +08:00
18
+ date: 2010-07-02 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21