voip 3.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/voip.rb +343 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4a28bde69941674d06ec91208197b123e0566099
|
4
|
+
data.tar.gz: 80f25ebbbe88da364936ce8b5b7e26534805e4c5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 285ea9974aabc178247e316205618b41a5cb39e2b369e8371453f3cb90f13f8bf2d00752ce4cdd886c3b16a50723d1ed697d5f222b9fed57d12495f3686bdfdc
|
7
|
+
data.tar.gz: 89b162107f0300ba1a0dd8d37d588261866b18d44f96a1890596a2ca39a31211cb1c5c9a3033a9fc434226b42ecc89deb4e8417724e26d13c234a5417a7c5d86
|
data/lib/voip.rb
ADDED
@@ -0,0 +1,343 @@
|
|
1
|
+
# Simple way to make and receive telephone calls through a VoIP PBX, such as Ozeki Phone System XE.
|
2
|
+
|
3
|
+
class NG
|
4
|
+
|
5
|
+
require 'uri'
|
6
|
+
require 'net/http'
|
7
|
+
|
8
|
+
# Creates a new NG object.
|
9
|
+
def initialize ng_ip_address, username, password, port=9501
|
10
|
+
@ng_ip_address = ng_ip_address
|
11
|
+
@username = username
|
12
|
+
@password = password
|
13
|
+
@port = port
|
14
|
+
end
|
15
|
+
|
16
|
+
# Instance method to send an SMS message.
|
17
|
+
def send_sms to, message, from=nil
|
18
|
+
NG.send_sms @ng_ip_address, @username, @password, to, message, @port, from
|
19
|
+
end
|
20
|
+
|
21
|
+
# Class method to send an SMS message.
|
22
|
+
def self.send_sms ng_ip_address, username, password, to, message, port=9501, from=nil
|
23
|
+
to = URI::encode(to)
|
24
|
+
message = URI::encode(message)
|
25
|
+
from ||= ""
|
26
|
+
uri = URI "http://#{ng_ip_address}:#{port}/api?action=sendmessage&username=#{username}&password=#{password}&originator=#{from}&recipient=#{to}&messagetype=SMS:TEXT&messagedata=#{message}"
|
27
|
+
Response.create Net::HTTP.get uri
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class OPS
|
32
|
+
|
33
|
+
require 'uri'
|
34
|
+
require 'net/http'
|
35
|
+
|
36
|
+
# Creates a new OPS object.
|
37
|
+
def initialize ops_ip_address, http_api_service_port=7780, api_extension=nil, username=nil, password=nil
|
38
|
+
@ops_ip_address = ops_ip_address
|
39
|
+
@username = username
|
40
|
+
@password = password
|
41
|
+
@api_extension = api_extension
|
42
|
+
@http_api_service_port = http_api_service_port || 7780
|
43
|
+
|
44
|
+
@api_extension = api_extension
|
45
|
+
end
|
46
|
+
|
47
|
+
# Instance method to make a call.
|
48
|
+
def make_call dialed, url=nil, error_url=nil, caller_id=nil, caller_displayed_name=nil
|
49
|
+
OPS.make_call @ops_ip_address, @api_extension, dialed, @http_api_service_port, url, error_url, caller_id, caller_displayed_name, @username, @password
|
50
|
+
end
|
51
|
+
|
52
|
+
# Instance method to send an SMS message.
|
53
|
+
def send_sms to, message, from=nil, delivery_report_url=nil
|
54
|
+
OPS.send_sms @ops_ip_address, @api_extension, to, message, @http_api_service_port, from, delivery_report_url, @username, @password
|
55
|
+
end
|
56
|
+
|
57
|
+
# Instance method to send an e-mail message.
|
58
|
+
def send_email to, message=nil, subject=nil, from=nil
|
59
|
+
OPS.send_email @ops_ip_address, @api_extension, to, @http_api_service_port, message, subject, from, @username, @password
|
60
|
+
end
|
61
|
+
|
62
|
+
# Instance method to retrieve the list of active calls.
|
63
|
+
def list_active_calls
|
64
|
+
OPS.list_active_calls @ops_ip_address, @http_api_service_port, @username, @password
|
65
|
+
end
|
66
|
+
|
67
|
+
# Class method to retrieve the list of active calls.
|
68
|
+
def self.list_active_calls ops_ip_address, http_api_service_port=7780, username=nil, password=nil
|
69
|
+
http_api_service_port ||= 7780
|
70
|
+
|
71
|
+
query = "http://#{ops_ip_address}:#{http_api_service_port}/?Command=ListActiveCalls"
|
72
|
+
|
73
|
+
if (username != nil) && (password != nil)
|
74
|
+
query += "&username=#{username}&password=#{password}"
|
75
|
+
end
|
76
|
+
|
77
|
+
uri = URI query
|
78
|
+
response = Net::HTTP.get uri
|
79
|
+
|
80
|
+
resp = Response.create response
|
81
|
+
if (resp.code != "200")
|
82
|
+
return resp
|
83
|
+
end
|
84
|
+
|
85
|
+
lines = response.split(/[\r\n]+/)
|
86
|
+
|
87
|
+
call_infos = []
|
88
|
+
|
89
|
+
lines.each do |line|
|
90
|
+
|
91
|
+
if (line.index('<CallInfo>') != nil)
|
92
|
+
call_infos << Call.new(ops_ip_address, http_api_service_port, username, password)
|
93
|
+
|
94
|
+
elsif (((start_index = line.index('<CallId>')) != nil) && (end_index = line.index('</CallId>')) != nil)
|
95
|
+
call_infos.last.call_id = line[start_index + 8, end_index - start_index - 8]
|
96
|
+
|
97
|
+
elsif (((start_index = line.index('<CallState>')) != nil) && (end_index = line.index('</CallState>')) != nil)
|
98
|
+
call_infos.last.call_state = line[start_index + 11, end_index - start_index - 11]
|
99
|
+
|
100
|
+
elsif (((start_index = line.index('<Source>')) != nil) && (end_index = line.index('</Source>')) != nil)
|
101
|
+
call_infos.last.source = line[start_index + 8, end_index - start_index - 8]
|
102
|
+
|
103
|
+
elsif (((start_index = line.index('<CallerId>')) != nil) && (end_index = line.index('</CallerId>')) != nil)
|
104
|
+
call_infos.last.caller_id = line[start_index + 10, end_index - start_index - 10]
|
105
|
+
|
106
|
+
elsif (((start_index = line.index('<Destination>')) != nil) && (end_index = line.index('</Destination>')) != nil)
|
107
|
+
call_infos.last.destination = line[start_index + 13, end_index - start_index - 13]
|
108
|
+
|
109
|
+
elsif (((start_index = line.index('<StartTime>')) != nil) && (end_index = line.index('</StartTime>')) != nil)
|
110
|
+
call_infos.last.start_time = line[start_index + 11, end_index - start_index - 11]
|
111
|
+
|
112
|
+
elsif (((start_index = line.index('<RingDuration>')) != nil) && (end_index = line.index('</RingDuration>')) != nil)
|
113
|
+
call_infos.last.ring_duration = line[start_index + 14, end_index - start_index - 14]
|
114
|
+
|
115
|
+
elsif (((start_index = line.index('<TalkDuration>')) != nil) && (end_index = line.index('</TalkDuration>')) != nil)
|
116
|
+
call_infos.last.talk_duration = line[start_index + 14, end_index - start_index - 14]
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
return call_infos
|
121
|
+
end
|
122
|
+
|
123
|
+
# Class method to make a call.
|
124
|
+
def self.make_call ops_ip_address, api_extension, dialed, http_api_service_port=7780, url=nil, error_url=nil, caller_id=nil, caller_displayed_name=nil, username=nil, password=nil
|
125
|
+
url ||= ""
|
126
|
+
error_url ||= ""
|
127
|
+
caller_id ||= ""
|
128
|
+
caller_displayed_name ||= caller_id
|
129
|
+
http_api_service_port ||= 7780
|
130
|
+
|
131
|
+
OPS.execute_query "http://#{ops_ip_address}:#{http_api_service_port}/?Command=Call&Dialed=#{dialed}&ApiExtension=#{api_extension}&CallerId=#{caller_id}&CallerDisplayName=#{caller_displayed_name}&Url=#{url}&ErrorUrl=#{error_url}", username, password
|
132
|
+
end
|
133
|
+
|
134
|
+
# Class method to send an SMS message.
|
135
|
+
def self.send_sms ops_ip_address, api_extension, to, message, http_api_service_port=7780, from=nil, delivery_report_url=nil, username=nil, password=nil
|
136
|
+
to = URI::encode(to)
|
137
|
+
message = URI::encode(message)
|
138
|
+
|
139
|
+
from ||= ""
|
140
|
+
from = URI::encode(from)
|
141
|
+
delivery_report_url ||= ""
|
142
|
+
delivery_report_url = URI::encode(delivery_report_url)
|
143
|
+
http_api_service_port ||= 7780
|
144
|
+
|
145
|
+
OPS.execute_query "http://#{ops_ip_address}:#{http_api_service_port}/?Command=SendSms&ApiExtension=#{api_extension}&Sender=#{from}&Recipient=#{to}&Message=#{message}&DeliveryReportURL=#{delivery_report_url}", username, password
|
146
|
+
end
|
147
|
+
|
148
|
+
# Class method to send an e-mail message.
|
149
|
+
def self.send_email ops_ip_address, api_extension, to, http_api_service_port=7780, message=nil, subject=nil, from=nil, username=nil, password=nil
|
150
|
+
|
151
|
+
subject = URI::encode(subject || '')
|
152
|
+
from = URI::encode(from || '')
|
153
|
+
message = URI::encode(message || '')
|
154
|
+
to = URI::encode(to)
|
155
|
+
http_api_service_port ||= 7780
|
156
|
+
|
157
|
+
OPS.execute_query "http://#{ops_ip_address}:#{http_api_service_port}/?Command=SendEmail&ApiExtension=#{api_extension}&Sender=#{from}&Recipient=#{to}&Message=#{message}&Subject=#{subject}", username, password
|
158
|
+
end
|
159
|
+
|
160
|
+
private
|
161
|
+
# Executes a HTTP get request
|
162
|
+
def self.execute_query query, username, password
|
163
|
+
if (username != nil) && (password != nil)
|
164
|
+
query += "&username=#{username}&password=#{password}"
|
165
|
+
end
|
166
|
+
|
167
|
+
uri = URI query
|
168
|
+
Response.create Net::HTTP.get uri
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
class Response
|
173
|
+
|
174
|
+
# code: Get the status code of the returned response
|
175
|
+
# message: Get the status message of the returned response
|
176
|
+
attr_accessor :code, :message
|
177
|
+
|
178
|
+
# User friendly string format
|
179
|
+
def to_s
|
180
|
+
message + " (" + code + ")"
|
181
|
+
end
|
182
|
+
|
183
|
+
private
|
184
|
+
def initialize code=nil, message=nil
|
185
|
+
@code = code || ""
|
186
|
+
@message = message || ""
|
187
|
+
end
|
188
|
+
|
189
|
+
private
|
190
|
+
def self.create response
|
191
|
+
lines = response.split(/[\r\n]+/)
|
192
|
+
|
193
|
+
resp = Response.new
|
194
|
+
|
195
|
+
lines.each do |line|
|
196
|
+
if (((start_index = line.index('<Code>')) != nil) && (end_index = line.index('</Code>')) != nil)
|
197
|
+
resp.code = line[start_index + 6, end_index - start_index - 6]
|
198
|
+
elsif (((start_index = line.index('<statuscode>')) != nil) && (end_index = line.index('</statuscode>')) != nil)
|
199
|
+
resp.code = line[start_index + 12, end_index - start_index - 12]
|
200
|
+
elsif (((start_index = line.index('<Message>')) != nil) && (end_index = line.index('</Message>')) != nil)
|
201
|
+
resp.message = line[start_index + 9, end_index - start_index - 9]
|
202
|
+
elsif (((start_index = line.index('<statusmessage>')) != nil) && (end_index = line.index('</statusmessage>')) != nil)
|
203
|
+
resp.message = line[start_index + 15, end_index - start_index - 15]
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
if (resp.code != "") && (resp.message != "")
|
208
|
+
return resp
|
209
|
+
else
|
210
|
+
return response
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
class Call
|
216
|
+
|
217
|
+
def initialize ops_ip_address=nil, http_api_service_port=nil, username=nil, password=nil, call_id=nil, call_state=nil, source=nil, caller_id=nil, destination=nil, start_time=nil, ring_duration=nil, talk_duration=nil
|
218
|
+
@http_api_service_port = http_api_service_port || 7780
|
219
|
+
@ops_ip_address = ops_ip_address || "localhost"
|
220
|
+
@username = username
|
221
|
+
@password = password
|
222
|
+
@call_id = call_id || ""
|
223
|
+
@call_state = call_state || ""
|
224
|
+
@source = source || ""
|
225
|
+
@caller_id = caller_id || ""
|
226
|
+
@destination = destination || ""
|
227
|
+
@start_time = start_time || ""
|
228
|
+
@ring_duration = ring_duration || ""
|
229
|
+
@talk_duration = talk_duration || ""
|
230
|
+
end
|
231
|
+
|
232
|
+
attr_accessor :call_id, :call_state, :source, :caller_id, :destination, :start_time, :ring_duration, :talk_duration
|
233
|
+
|
234
|
+
public
|
235
|
+
def to_s
|
236
|
+
caller_id + " => " + destination + " - " + call_id + "(" + call_state + ")"
|
237
|
+
end
|
238
|
+
|
239
|
+
# If getting a call, you can put it on hold and call a 2nd number, then connect the call with the 2nd number using AttendedTransfer.
|
240
|
+
def attended_transfer target_call_id
|
241
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=AttendedTransfer&TransferredCallId=#{@call_id}&TargetCallId=#{target_call_id}"
|
242
|
+
end
|
243
|
+
|
244
|
+
# Transfer the call during the conversation, and the callee will leave the conversation.
|
245
|
+
def blind_transfer_callee target
|
246
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=BlindTransfer&CallId=#{@call_id}&TransferorParty=callee&Target=#{target}"
|
247
|
+
end
|
248
|
+
|
249
|
+
# Transfer the call during the conversation, and the caller will leave the conversation.
|
250
|
+
def blind_transfer_caller target
|
251
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=BlindTransfer&CallId=#{@call_id}&TransferorParty=caller&Target=#{target}"
|
252
|
+
end
|
253
|
+
|
254
|
+
# Forward a call by ID to another number if it can't be answered.
|
255
|
+
def forward destination
|
256
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Forward&CallId=#{@call_id}&Destination=#{destination}"
|
257
|
+
end
|
258
|
+
|
259
|
+
# Terminates a call in progress by ID.
|
260
|
+
def hangup
|
261
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Hangup&CallId=#{@call_id}"
|
262
|
+
end
|
263
|
+
|
264
|
+
# Puts both legs of the call from InCall state to Hold state by ID.
|
265
|
+
def hold
|
266
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Hold&CallId=#{@call_id}"
|
267
|
+
end
|
268
|
+
|
269
|
+
# Plays an audio file (local or downloaded from URL) in an existing call for both party.
|
270
|
+
def play_file filename, repeat=false
|
271
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Play&CallId=#{@call_id}&Party=all&AudioFile=#{filename}&Repeat=#{repeat}"
|
272
|
+
end
|
273
|
+
|
274
|
+
# Plays an audio file (local or downloaded from URL) in an existing call for the callee.
|
275
|
+
def play_file_to_callee filename, repeat=false
|
276
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Play&CallId=#{@call_id}&Party=callee&AudioFile=#{filename}&Repeat=#{repeat}"
|
277
|
+
end
|
278
|
+
|
279
|
+
# Plays an audio file (local or downloaded from URL) in an existing call for the caller.
|
280
|
+
def play_file_to_caller filename, repeat=false
|
281
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Play&CallId=#{@call_id}&Party=caller&AudioFile=#{filename}&Repeat=#{repeat}"
|
282
|
+
end
|
283
|
+
|
284
|
+
# Records a call in mp3 format.
|
285
|
+
def record_mp3 finished_url=""
|
286
|
+
finished_url ||= ""
|
287
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Record&CallId=#{@call_id}&Format=mp3&FinishedUrl=#{finished_url}"
|
288
|
+
end
|
289
|
+
|
290
|
+
# Records a call in wav format.
|
291
|
+
def record_wav finished_url=""
|
292
|
+
finished_url ||= ""
|
293
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Record&CallId=#{@call_id}&Format=wav&FinishedUrl=#{finished_url}"
|
294
|
+
end
|
295
|
+
|
296
|
+
# Sends a DTMF message for both party.
|
297
|
+
def dtmf keys
|
298
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=SendDTMF&CallId=#{@call_id}&Party=all&Keys=#{keys}"
|
299
|
+
end
|
300
|
+
|
301
|
+
# Sends a DTMF message for the callee.
|
302
|
+
def dtmf_to_callee keys
|
303
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=SendDTMF&CallId=#{@call_id}&Party=callee&Keys=#{keys}"
|
304
|
+
end
|
305
|
+
|
306
|
+
# Sends a DTMF message for the caller.
|
307
|
+
def dtmf_to_caller keys
|
308
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=SendDTMF&CallId=#{@call_id}&Party=caller&Keys=#{keys}"
|
309
|
+
end
|
310
|
+
|
311
|
+
# Reads a text for both party using the text to speech engine into a call in progress.
|
312
|
+
def speak message
|
313
|
+
message = URI::encode message
|
314
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Speak&CallId=#{@call_id}&Text=#{message}&Party=all"
|
315
|
+
end
|
316
|
+
|
317
|
+
# Reads a text for callee using the text to speech engine into a call in progress.
|
318
|
+
def speak_to_callee message
|
319
|
+
message = URI::encode message
|
320
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Speak&CallId=#{@call_id}&Text=#{message}&Party=callee"
|
321
|
+
end
|
322
|
+
|
323
|
+
# Reads a text for caller using the text to speech engine into a call in progress.
|
324
|
+
def speak_to_caller message
|
325
|
+
message = URI::encode message
|
326
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Speak&CallId=#{@call_id}&Text=#{message}&Party=caller"
|
327
|
+
end
|
328
|
+
|
329
|
+
# Puts both legs of the call to InCall state by ID.
|
330
|
+
def unhold
|
331
|
+
execute_query "http://#{@ops_ip_address}:#{@http_api_service_port}/?Command=Unhold&CallId=#{@call_id}"
|
332
|
+
end
|
333
|
+
|
334
|
+
private
|
335
|
+
def execute_query query
|
336
|
+
if (@username != nil) && (@password != nil)
|
337
|
+
query += "&username=#{@username}&password=#{@password}"
|
338
|
+
end
|
339
|
+
|
340
|
+
uri = URI query
|
341
|
+
Response.create Net::HTTP.get uri
|
342
|
+
end
|
343
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: voip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.7.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert Simon
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Simple way to make and receive telephone calls through a VoIP PBX, such
|
14
|
+
as Ozeki Phone System XE.
|
15
|
+
email: simon.robert@ozekiphone.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/voip.rb
|
21
|
+
homepage: http://www.ozekiphone.com/index.php?owpn=825
|
22
|
+
licenses:
|
23
|
+
- MIT
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubyforge_project:
|
41
|
+
rubygems_version: 2.0.2
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: Ozeki Phone System SDK
|
45
|
+
test_files: []
|