pbxtra 0.5.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/VERSION +1 -1
- data/example/extension.rb +65 -0
- data/example/report.rb +34 -0
- data/lib/pbxtra.rb +69 -26
- metadata +7 -5
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'pbxtra'
|
5
|
+
|
6
|
+
pbx = PBXtra::Base.new("user", 'pass', {:debug => true})
|
7
|
+
parameters = {:list_ext => 'all' }
|
8
|
+
request = {
|
9
|
+
:callforward => nil,
|
10
|
+
:override_phone => 1,
|
11
|
+
:existing_extension => 5003,
|
12
|
+
:old_mailbox => nil,
|
13
|
+
:old_in_blast_group => nil,
|
14
|
+
:existing_username => nil,
|
15
|
+
:existing_password => nil,
|
16
|
+
:username => nil,
|
17
|
+
:password => nil.
|
18
|
+
:do => 'ext',
|
19
|
+
:old_visual_only => 0,
|
20
|
+
:old_department => nil,
|
21
|
+
:add_ext_final_step => 1,
|
22
|
+
:extension => 5002,
|
23
|
+
:description => 'John',
|
24
|
+
:first_name => 'Doe',
|
25
|
+
:last_name => 'User',
|
26
|
+
:username2 => 7744_5003,
|
27
|
+
:password2 => 'Sugar123!',
|
28
|
+
:employee_email => 'jdoe@sugarcrm.com',
|
29
|
+
:employee_im => 'jdoe@yahoo.com',
|
30
|
+
:employee_phonenumber => '+1-555-555-5555',
|
31
|
+
:sms_selector => 'cingularme.com',
|
32
|
+
:sms_gateway => '15555555555@cingularme.com',
|
33
|
+
:phone_number => nil,
|
34
|
+
:caller_id => 14084546900,
|
35
|
+
:moh_dialargs => nil,
|
36
|
+
:ring_seconds => 20,
|
37
|
+
:old_device_id => nil,
|
38
|
+
:device_id => 322674,
|
39
|
+
:virt_device_id => 280874,
|
40
|
+
:department => nil,
|
41
|
+
:auto_logoff => 0,
|
42
|
+
:press_to_accept => 0,
|
43
|
+
:q_ignore_if_busy => 1,
|
44
|
+
:q_call_on_qcall => 0,
|
45
|
+
:q_dont_req_pass => 0,
|
46
|
+
:insert_into_dir => 1,
|
47
|
+
:in_company_dir => 1,
|
48
|
+
:in_blast_group => 0,
|
49
|
+
:in_hud => 1,
|
50
|
+
:is_private => 0,
|
51
|
+
:visual_only => 0,
|
52
|
+
:vm_enabled => 1,
|
53
|
+
:uae_ret => 0,
|
54
|
+
:crm_user_id => 'None',
|
55
|
+
:mailbox => 'new',
|
56
|
+
:vm_pass => 5002,
|
57
|
+
:vm_email => 'jdoe@sugarcrm.com',
|
58
|
+
:vm_pager => nil,
|
59
|
+
:vm_attach => 1,
|
60
|
+
:vm_auto_delete => 0,
|
61
|
+
:call_return => 1,
|
62
|
+
:call_out => 1,
|
63
|
+
}
|
64
|
+
|
65
|
+
response = pbx.post(:ext, parameters, request)
|
data/example/report.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'pbxtra'
|
5
|
+
|
6
|
+
pbx = PBXtra::Base.new("user", 'pass', {:debug => true})
|
7
|
+
ext = 5555
|
8
|
+
|
9
|
+
start_date = "2000-01-01"
|
10
|
+
end_date = "2000-01-10"
|
11
|
+
|
12
|
+
csv = pbx.get(:rep, {
|
13
|
+
:showinbound => :on,
|
14
|
+
:showoutbound => :on,
|
15
|
+
:showacd => :on,
|
16
|
+
:src => :on,
|
17
|
+
:dst => :on,
|
18
|
+
:disposition => :on,
|
19
|
+
:calldate => :on,
|
20
|
+
:duration => :on,
|
21
|
+
:clid => :on,
|
22
|
+
:csv => :on,
|
23
|
+
:for_ext => ext,
|
24
|
+
:reporting => 1,
|
25
|
+
:month1 => start_date.split(/-/)[1],
|
26
|
+
:month2 => end_date.split(/-/)[1],
|
27
|
+
:day1 => start_date.split(/-/)[2],
|
28
|
+
:day2 => end_date.split(/-/)[2],
|
29
|
+
:year1 => start_date.split(/-/)[0],
|
30
|
+
:year2 => end_date.split(/-/)[0],
|
31
|
+
:show_report_results => 1
|
32
|
+
})
|
33
|
+
|
34
|
+
puts csv
|
data/lib/pbxtra.rb
CHANGED
@@ -9,9 +9,11 @@ module PBXtra
|
|
9
9
|
class LoginError < RuntimeError
|
10
10
|
end
|
11
11
|
|
12
|
+
class UnhandledResponse < RuntimeError
|
13
|
+
end
|
14
|
+
|
12
15
|
class Base
|
13
16
|
|
14
|
-
HOST = "cp-b.fonality.com"
|
15
17
|
URL = "/cpa.cgi"
|
16
18
|
attr :url, true
|
17
19
|
attr :user, false
|
@@ -20,13 +22,17 @@ class Base
|
|
20
22
|
attr :debug, true
|
21
23
|
attr :cookie, true
|
22
24
|
|
23
|
-
def initialize(user, pass,
|
24
|
-
|
25
|
+
def initialize(user, pass, opts={})
|
26
|
+
options = {
|
27
|
+
:host => "https://cp52.fonality.com",
|
28
|
+
:debug => false
|
29
|
+
}.merge! opts
|
25
30
|
@debug = options[:debug]
|
26
31
|
|
27
32
|
@user = user
|
28
33
|
@pass = pass
|
29
|
-
@
|
34
|
+
@host = options[:host]
|
35
|
+
@url = URI.parse(@host + URL)
|
30
36
|
|
31
37
|
# Handles http/https in url string
|
32
38
|
@ssl = false
|
@@ -37,35 +43,43 @@ class Base
|
|
37
43
|
raise LoginError, "Invalid Username or Password" unless logged_in?
|
38
44
|
end
|
39
45
|
|
46
|
+
def get(method, parameters={})
|
47
|
+
@url.query = wrap_url_query(method, parameters)
|
48
|
+
request(Net::HTTP::Get.new(@url.path + @url.query, header)).body
|
49
|
+
end
|
50
|
+
|
51
|
+
def post(method=nil, parameters={}, body={})
|
52
|
+
@url.query = wrap_url_query(method, parameters)
|
53
|
+
req = Net::HTTP::Post.new(@url.path + @url.query, header)
|
54
|
+
req.body = wrap_body(body)
|
55
|
+
request(req)
|
56
|
+
end
|
57
|
+
|
40
58
|
# Send a request to the CP. Send Auth information if we have it.
|
41
|
-
def request(
|
59
|
+
def request(request)
|
42
60
|
login! unless logged_in?
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
header = {'Cookie' => @cookie, 'Accept-Encoding' => ''}
|
50
|
-
request = Net::HTTP::Get.new(@url.path + @url.query, header)
|
61
|
+
if @debug
|
62
|
+
puts "Request Type: #{request.class}"
|
63
|
+
puts "Request Path: #{@url}"
|
64
|
+
puts "Request Body: #{request.body}"
|
65
|
+
puts "\n"
|
66
|
+
end
|
51
67
|
response = @connection.request(request)
|
52
|
-
|
53
68
|
if @debug
|
54
|
-
puts "
|
55
|
-
puts response
|
69
|
+
puts "Response Header: " + response.header.to_s
|
70
|
+
puts "Response Body: " + response.body
|
56
71
|
puts "\n"
|
57
72
|
end
|
58
|
-
|
59
73
|
case response
|
60
74
|
when Net::HTTPOK
|
61
|
-
|
62
|
-
return response.body
|
75
|
+
return response
|
63
76
|
when Net::HTTPUnauthorized
|
64
77
|
login!
|
65
78
|
request(method, parameters)
|
66
79
|
when Net::HTTPForbidden
|
67
80
|
raise LoginError, "Invalid Username or Password"
|
68
|
-
else
|
81
|
+
else
|
82
|
+
raise UnhandledResponse, "Can't handle response #{response}"
|
69
83
|
end
|
70
84
|
end
|
71
85
|
|
@@ -74,13 +88,26 @@ class Base
|
|
74
88
|
# Attempt authentication with PBXtra CP
|
75
89
|
def login!
|
76
90
|
connect! unless connected?
|
91
|
+
body = {
|
92
|
+
:forcesec => nil,
|
93
|
+
:do => 'authenticate',
|
94
|
+
:username => @user,
|
95
|
+
:password => @pass
|
96
|
+
}
|
77
97
|
request = Net::HTTP::Post.new(@url.path)
|
78
|
-
request.body =
|
98
|
+
request.body = wrap_body(body)
|
79
99
|
response = @connection.request(request)
|
80
|
-
|
100
|
+
|
101
|
+
if response["Set-Cookie"]
|
102
|
+
@cookie = response["Set-Cookie"].split(/;/)[0]
|
103
|
+
else
|
104
|
+
raise LoginError, "Invalid Username or Password"
|
105
|
+
end
|
106
|
+
|
81
107
|
if @debug
|
82
108
|
puts "Cookie: #{@cookie}"
|
83
109
|
end
|
110
|
+
|
84
111
|
end
|
85
112
|
|
86
113
|
# Check to see if we are logged in
|
@@ -106,12 +133,28 @@ class Base
|
|
106
133
|
@connection.start
|
107
134
|
end
|
108
135
|
|
109
|
-
def
|
110
|
-
|
136
|
+
def wrap_url_query(method, parameters={})
|
137
|
+
url = "?do=#{method}"
|
111
138
|
parameters.each_pair do |k,v|
|
112
|
-
|
139
|
+
url << "&" + k.to_s + "=" + v.to_s
|
140
|
+
end
|
141
|
+
url
|
142
|
+
end
|
143
|
+
|
144
|
+
def wrap_body(parameters={})
|
145
|
+
body = []
|
146
|
+
parameters.each_pair do |k,v|
|
147
|
+
body << k.to_s + "=" + v.to_s
|
148
|
+
end
|
149
|
+
body.join('&')
|
150
|
+
end
|
151
|
+
|
152
|
+
def header
|
153
|
+
if @cookie
|
154
|
+
{'Cookie' => @cookie, 'Accept-Encoding' => ''}
|
155
|
+
else
|
156
|
+
{}
|
113
157
|
end
|
114
|
-
body
|
115
158
|
end
|
116
159
|
|
117
160
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pbxtra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 7
|
9
|
+
- 0
|
10
|
+
version: 0.7.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Carl Hicks
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-08-10 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -48,6 +48,8 @@ files:
|
|
48
48
|
- README.rdoc
|
49
49
|
- Rakefile
|
50
50
|
- VERSION
|
51
|
+
- example/extension.rb
|
52
|
+
- example/report.rb
|
51
53
|
- lib/pbxtra.rb
|
52
54
|
- test/helper.rb
|
53
55
|
- test/test_pbxtra.rb
|