vtiger 0.3.6 → 0.3.7

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.
@@ -21,7 +21,12 @@ Vtiger::API.api_settings = {
21
21
 
22
22
  == FEATURES/PROBLEMS:
23
23
 
24
- * TBD
24
+ many commands to add via webservices including add trouble ticket, add contact etc.
25
+ queries,
26
+ describe object
27
+ list entities
28
+
29
+ are all running
25
30
 
26
31
  == SYNOPSIS:
27
32
 
@@ -68,14 +68,27 @@ module Vtiger
68
68
  # puts "url path is #{url.path}"
69
69
  http.request(req)
70
70
  }
71
- # puts resp.body
71
+ # puts "HTTP_ASK_GET" + resp.body.to_s
72
72
 
73
73
 
74
74
  # puts "resp: " + resp
75
75
  self.json_parse resp.body
76
76
  # r
77
77
  end
78
-
78
+ def add_object(object_map,hashv,element)
79
+ object_map=object_map.merge hashv
80
+ # 'tsipid'=>"1234"
81
+ tmp=self.json_please(object_map)
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}
84
+ # scott not working -- JSON.generate(input_array,{'array_nl'=>'true'})
85
+ result = http_crm_post("operation=create",input_array)
86
+ # self.session_name=result["result"]["sessionName"]
87
+ # puts JSON.pretty_generate(result)
88
+ success=result['success']
89
+ id =result["result"]['id'] if success
90
+ return success,id
91
+ end
79
92
  def login(options)
80
93
  # puts "in login"
81
94
  input_array ={'operation'=>'login', 'username'=>self.username, 'accessKey'=>self.md5} # removed the true
@@ -22,33 +22,23 @@ module Vtiger
22
22
  def addlead(options,ln,co,hashv)
23
23
  puts "in addobject"
24
24
  object_map= { 'assigned_user_id'=>"#{self.userid}",'lastname'=>"#{ln}", 'company'=>"#{co}"}
25
- object_map=object_map.merge hashv
26
- # 'tsipid'=>"1234"
27
- tmp=self.json_please(object_map)
28
- input_array ={'operation'=>'create','elementType'=>"Leads",'sessionName'=>"#{self.session_name}", 'element'=>tmp} # removed the true
29
- puts "input array:" + input_array.to_s #&username=#{self.username}&accessKey=#{self.md5}
30
- # scott not working -- JSON.generate(input_array,{'array_nl'=>'true'})
31
- result = http_crm_post("operation=create",input_array)
32
- # self.session_name=result["result"]["sessionName"]
33
- # puts JSON.pretty_generate(result)
34
- result["success"]
25
+ add_object(object_map,hashv,'Leads')
26
+ end
27
+ def add_contact(options,ln,email,hashv)
28
+ puts "in contact"
29
+ object_map= { 'assigned_user_id'=>"#{self.userid}",'lastname'=>"#{ln}", 'email'=>"#{email}"}
30
+ add_object(object_map,hashv,'Contacts')
31
+ end
32
+ def find_contact_by_email_or_add(options,ln,email,hashv)
33
+ success,id = query_element_by_email(email,"Contacts")
34
+ success,id =add_contact(options,ln,email,hashv) if !success
35
35
  end
36
36
  def add_trouble_ticket(options,status,title,hashv)
37
37
  puts "in add trouble ticket"
38
38
  object_map= { 'assigned_user_id'=>"#{self.userid}",'ticketstatus'=>"#{status}", 'ticket_title'=>"#{title}"}
39
39
  object_map=object_map.merge hashv
40
40
  # 'tsipid'=>"1234"
41
- tmp=self.json_please(object_map)
42
- input_array ={'operation'=>'create','elementType'=>"HelpDesk",'sessionName'=>"#{self.session_name}", 'element'=>tmp} # removed the true
43
- puts "input array:" + input_array.to_s #&username=#{self.username}&accessKey=#{self.md5}
44
- # scott not working -- JSON.generate(input_array,{'array_nl'=>'true'})
45
- result = http_crm_post("operation=create",input_array)
46
- puts "#{result.inspect}"
47
- # self.session_name=result["result"]["sessionName"]
48
- # puts JSON.pretty_generate(result)
49
- ttnumber="invalid"
50
- ttnumber =result["result"]["ticket_no"] if result["success"]
51
- return result["success"],ttnumber
41
+ add_object(object_map,hashv,'HelpDesk')
52
42
  end
53
43
  def action(options)
54
44
  puts "in action"
@@ -119,6 +109,22 @@ module Vtiger
119
109
  # self.new_quantity = self.qty_in_stock.to_i + options[:quantity].to_i
120
110
  # updateobject(options,{'qtyinstock'=> "#{self.new_quantity}","productname"=>"#{options[:productname]}"})
121
111
  end
112
+ def query_element_by_email(email,element)
113
+ puts "in query contact"
114
+ action_string=ERB::Util.url_encode("select id from #{element} where email like '#{email}';")
115
+ puts "action string:" +action_string
116
+ res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
117
+ values=res["result"][0] if res["success"]==true #comes back as array
118
+ #puts values.inspect
119
+ # return the account id
120
+ self.object_id = 'failed'
121
+ if values!= nil
122
+ self.object_id=values["id"]
123
+ self.account_name=values["accountname"]
124
+ end
125
+ return res["success"],self.object_id
126
+
127
+ end
122
128
  def query_product_inventory(options)
123
129
  puts "in query product count"
124
130
  #&username=#{self.username}&accessKey=#{self.md5}
@@ -46,6 +46,20 @@ class TestVtiger < Test::Unit::TestCase
46
46
  assert challenge,"challenge is false"
47
47
  assert login,"login is false"
48
48
  end
49
+
50
+ def test_find_or_add_contact
51
+ cmd = Vtiger::Commands.new()
52
+ @options[:username]='admin'
53
+ challenge=cmd.challenge(@options)
54
+ login=cmd.login(@options)
55
+ success,id=cmd.find_contact_by_email_or_add(@options,'sproule','scott.sproule@gmail.com',{})
56
+ assert challenge,"challenge is false "
57
+ assert login,"login should succeed"
58
+ assert success,"find contact should success"
59
+ assert id=='4x173', "id is #{id}"
60
+ puts "id is #{id}"
61
+
62
+ end
49
63
  def test_bad_login
50
64
  cmd = Vtiger::Commands.new()
51
65
  @options[:username]='test'
@@ -54,17 +68,42 @@ class TestVtiger < Test::Unit::TestCase
54
68
  assert challenge,"challenge is false "
55
69
  assert !login,"login should not succeed"
56
70
  end
71
+ def test_query_contact
72
+ cmd = Vtiger::Commands.new()
73
+ @options[:username]='admin'
74
+ challenge=cmd.challenge(@options)
75
+ login=cmd.login(@options)
76
+ success,id=cmd.query_element_by_email("scott.sproule@gmail.com","Contacts")
77
+ assert challenge,"challenge is false "
78
+ assert login,"login should succeed"
79
+ assert success,"find contact should success"
80
+ puts "id is #{id}"
81
+
82
+ end
57
83
  def test_add_lead
58
84
  cmd = Vtiger::Commands.new()
59
85
  challenge=cmd.challenge(@options)
60
86
  login=cmd.login(@options)
61
87
  hv={}
62
88
  hv[:firstname]='test'
63
- lead=cmd.addlead(@options,"testlastname","testco",hv)
89
+ success,id=cmd.addlead(@options,"testlastname","testco",hv)
64
90
  assert challenge,"challenge is false "
65
91
  assert login,"login should succeed"
66
- assert lead,"lead should succeed"
92
+ assert success,"lead should succeed"
93
+ puts "id is #{id}"
67
94
  end
95
+ def test_add_contact
96
+ cmd = Vtiger::Commands.new()
97
+ challenge=cmd.challenge(@options)
98
+ login=cmd.login(@options)
99
+ hv={}
100
+ hv[:firstname]='test'
101
+ success,id=cmd.add_contact(@options,"testlastname","scott.sproule@gmail.com",hv)
102
+ assert challenge,"challenge is false "
103
+ assert login,"login should succeed"
104
+ assert success,"add should succeed"
105
+ puts "id is #{id}"
106
+ end
68
107
 
69
108
  def test_add_trouble_ticket
70
109
  cmd = Vtiger::Commands.new()
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: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 6
10
- version: 0.3.6
9
+ - 7
10
+ version: 0.3.7
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-23 00:00:00 +08:00
18
+ date: 2010-06-24 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21