vtiger 0.6.1 → 0.6.2

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
@@ -7,10 +7,10 @@ require 'digest/md5'
7
7
  require 'erb'
8
8
  #gem 'activerecord'
9
9
  require 'active_record'
10
- class Hash
10
+ class Hash
11
11
  def url_encode
12
12
  to_a.map do |name_value|
13
- name_value.map { |e| CGI.escape e.to_s }.join '='
13
+ name_value.map { |e| URI.encode e.to_s }.join '='
14
14
  end.join '&'
15
15
  end
16
16
  end
@@ -50,9 +50,8 @@ module Vtiger
50
50
  class Base
51
51
  attr_accessor :md5,:token, :endpoint_url, :access_key, :session_name, :url, :username, :userid, :campaigndb
52
52
 
53
- def challenge(options)
54
-
55
- #puts "in challenge"
53
+ def challenge(options)
54
+ # puts "in challenge"
56
55
  self.url=options[:url] || Vtiger::Api.api_settings[:url]
57
56
  self.username = options[:username]|| Vtiger::Api.api_settings[:username]
58
57
  self.access_key = options[:key] || Vtiger::Api.api_settings[:key]
@@ -60,15 +59,12 @@ module Vtiger
60
59
  operation = "operation=getchallenge&username=#{self.username}";
61
60
  #puts "challenge: " + self.endpoint_url + operation
62
61
  r=http_ask_get(self.endpoint_url+operation)
63
- # puts JSON.pretty_generate(r)
64
- # puts "success is: " + r["success"].to_s #==true
65
62
  self.token = r["result"]["token"] #if r["success"]==true
66
63
 
67
- #puts "token is: " + self.token
68
64
  create_digest
69
- #puts "digest is: #{self.md5} token #{self.token}"
65
+ # puts "digest is: #{self.md5} token #{self.token}"
70
66
  self.token!=nil
71
- end
67
+ end
72
68
  def create_digest
73
69
  #access key from my_preferences page of vtiger
74
70
  digest_string="#{self.token}#{self.access_key}"
@@ -82,7 +78,6 @@ module Vtiger
82
78
  t=URI.split(self.endpoint_url.to_s)
83
79
  # puts "host is: " + t[2] #FIX THIS.
84
80
  ht =Net::HTTP.start(t[2],80)
85
-
86
81
  body_enc=body.url_encode
87
82
  # puts "attemping post: #{self.endpoint_url}#{operation} body: #{body} body_enc= #{body_enc}"
88
83
  resp=ht.post(self.endpoint_url+operation,body_enc,response_header)
@@ -110,6 +105,29 @@ module Vtiger
110
105
  self.json_parse resp.body
111
106
  # r
112
107
  end
108
+ def large_query(countquery, query)
109
+ qaction_string=ERB::Util.url_encode("#{countquery};")
110
+ res=http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+qaction_string)
111
+ # puts "action string:" +action_string
112
+ puts "success: #{res['success']} res class #{res} count #{res['result']}"
113
+ temp=res['result'][0]
114
+ puts " temp: #{temp} class #{temp.class} inspect #{temp.inspect}"
115
+ count=temp['count'].to_i
116
+ s=count/100
117
+ puts "s is #{s}"
118
+ output=[]
119
+ finalres=true
120
+ 0.upto(s) { |i| puts i
121
+ action_string=ERB::Util.url_encode("#{query} limit #{i*100},100;")
122
+ puts "COUNT :#{i} #{action_string}"
123
+ res = http_ask_get(self.endpoint_url+"operation=query&sessionName=#{self.session_name}&query="+action_string)
124
+ values=res["result"] if res["success"]==true
125
+ finalres=finalres && res["success"]
126
+ values.each {|i| output << i }
127
+ # output << values
128
+ }
129
+ return finalres, output
130
+ end
113
131
  def add_object(object_map,hashv,element)
114
132
  object_map=object_map.merge hashv
115
133
  # 'tsipid'=>"1234"
@@ -215,6 +215,17 @@ module Vtiger
215
215
  return res["success"],values
216
216
 
217
217
  end
218
+ def large_find_items_by_date_and_key_null(element,date,key, extraparam=nil)
219
+ # NEED TO ADD QUERY SIZE CAPABILIIES
220
+ puts "in query by date #{date} and not null "
221
+ queryparams=''
222
+ queryparams=",#{extraparam}" if extraparam!=nil
223
+ t=Time.parse(date)
224
+ y=t.strftime('%Y-%m-%d')
225
+ querystring="select id,#{key}#{queryparams} from #{element} where createdtime like '#{y}%' and #{key} < '0' and emailoptout=0"
226
+ countstring="select count(*) from #{element} where createdtime like '#{y}%' and #{key} < '0' and emailoptout=0"
227
+ succ, values =self.large_query(countstring,querystring)
228
+ end
218
229
  def get_campaigns
219
230
  puts "in get campaigns"
220
231
  action_string=ERB::Util.url_encode("select id,campaignname from Campaigns;")
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestVtiger < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @options={}
7
+ @options[:url]='democrm.estormtech.com'
8
+ @options[:key]='xBY6leZ5kZHQm2Y'
9
+ @options[:username]="admin"
10
+ @options[:element_type]="Contacts"
11
+ end
12
+
13
+ def test_login
14
+ cmd = Vtiger::Commands.new()
15
+ challenge=cmd.challenge(@options)
16
+ login=cmd.login(@options)
17
+ assert challenge,"challenge is false"
18
+ assert login,"login is false"
19
+ end
20
+
21
+ end
data/test/test_philweb.rb CHANGED
@@ -10,16 +10,21 @@ class TestVtiger < Test::Unit::TestCase
10
10
 
11
11
  end
12
12
 
13
- def test_login
13
+ def test_a_login
14
+ setup
14
15
  cmd = Vtiger::Commands.new()
16
+ puts "#{cmd.inspect}"
15
17
  challenge=cmd.challenge(@options)
18
+ puts "challenge: #{challenge}"
16
19
  login=cmd.login(@options)
20
+ puts "login: #{login}"
17
21
  assert challenge,"challenge is false"
18
22
  assert login,"login is false"
19
23
  end
20
24
 
21
25
 
22
26
  def test_add_trouble_ticket
27
+ setup
23
28
  cmd = Vtiger::Commands.new()
24
29
  challenge=cmd.challenge(@options)
25
30
  puts "challenge is: #{challenge}"
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: 5
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 1
10
- version: 0.6.1
9
+ - 2
10
+ version: 0.6.2
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: 2011-03-03 00:00:00 +08:00
18
+ date: 2011-03-06 00:00:00 +08:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -40,6 +40,7 @@ files:
40
40
  - lib/vtiger/support.rb
41
41
  - lib/vtiger.rb
42
42
  - test/test_helper.rb
43
+ - test/test_login.rb
43
44
  - test/test_philweb.rb
44
45
  - test/test_secret.rb
45
46
  - test/test_vtiger.rb