Class: OPS
- Inherits:
-
Object
- Object
- OPS
- Defined in:
- lib/voip.rb
Class Method Summary collapse
-
.list_active_calls(ops_ip_address, http_api_service_port = 7780, username = nil, password = nil) ⇒ Object
Class method to retrieve the list of active calls.
-
.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) ⇒ Object
Class method to make a call.
-
.send_email(ops_ip_address, api_extension, to, http_api_service_port = 7780, message = nil, subject = nil, from = nil, username = nil, password = nil) ⇒ Object
Class method to send an e-mail message.
-
.send_sms(ops_ip_address, api_extension, to, message, http_api_service_port = 7780, from = nil, delivery_report_url = nil, username = nil, password = nil) ⇒ Object
Class method to send an SMS message.
Instance Method Summary collapse
-
#initialize(ops_ip_address, http_api_service_port = 7780, api_extension = nil, username = nil, password = nil) ⇒ OPS
constructor
Creates a new OPS object.
-
#list_active_calls ⇒ Object
Instance method to retrieve the list of active calls.
-
#make_call(dialed, url = nil, error_url = nil, caller_id = nil, caller_displayed_name = nil) ⇒ Object
Instance method to make a call.
-
#send_email(to, message = nil, subject = nil, from = nil) ⇒ Object
Instance method to send an e-mail message.
-
#send_sms(to, message, from = nil, delivery_report_url = nil) ⇒ Object
Instance method to send an SMS message.
Constructor Details
#initialize(ops_ip_address, http_api_service_port = 7780, api_extension = nil, username = nil, password = nil) ⇒ OPS
Creates a new OPS object.
37 38 39 40 41 42 43 44 45 |
# File 'lib/voip.rb', line 37 def initialize ops_ip_address, http_api_service_port=7780, api_extension=nil, username=nil, password=nil @ops_ip_address = ops_ip_address @username = username @password = password @api_extension = api_extension @http_api_service_port = http_api_service_port || 7780 @api_extension = api_extension end |
Class Method Details
.list_active_calls(ops_ip_address, http_api_service_port = 7780, username = nil, password = nil) ⇒ Object
Class method to retrieve the list of active calls.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/voip.rb', line 68 def self.list_active_calls ops_ip_address, http_api_service_port=7780, username=nil, password=nil http_api_service_port ||= 7780 query = "http://#{ops_ip_address}:#{http_api_service_port}/?Command=ListActiveCalls" if (username != nil) && (password != nil) query += "&username=#{username}&password=#{password}" end uri = URI query response = Net::HTTP.get uri resp = Response.create response if (resp.code != "200") return resp end lines = response.split(/[\r\n]+/) call_infos = [] lines.each do |line| if (line.index('<CallInfo>') != nil) call_infos << Call.new(ops_ip_address, http_api_service_port, username, password) elsif (((start_index = line.index('<CallId>')) != nil) && (end_index = line.index('</CallId>')) != nil) call_infos.last.call_id = line[start_index + 8, end_index - start_index - 8] elsif (((start_index = line.index('<CallState>')) != nil) && (end_index = line.index('</CallState>')) != nil) call_infos.last.call_state = line[start_index + 11, end_index - start_index - 11] elsif (((start_index = line.index('<Source>')) != nil) && (end_index = line.index('</Source>')) != nil) call_infos.last.source = line[start_index + 8, end_index - start_index - 8] elsif (((start_index = line.index('<CallerId>')) != nil) && (end_index = line.index('</CallerId>')) != nil) call_infos.last.caller_id = line[start_index + 10, end_index - start_index - 10] elsif (((start_index = line.index('<Destination>')) != nil) && (end_index = line.index('</Destination>')) != nil) call_infos.last.destination = line[start_index + 13, end_index - start_index - 13] elsif (((start_index = line.index('<StartTime>')) != nil) && (end_index = line.index('</StartTime>')) != nil) call_infos.last.start_time = line[start_index + 11, end_index - start_index - 11] elsif (((start_index = line.index('<RingDuration>')) != nil) && (end_index = line.index('</RingDuration>')) != nil) call_infos.last.ring_duration = line[start_index + 14, end_index - start_index - 14] elsif (((start_index = line.index('<TalkDuration>')) != nil) && (end_index = line.index('</TalkDuration>')) != nil) call_infos.last.talk_duration = line[start_index + 14, end_index - start_index - 14] end end return call_infos end |
.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) ⇒ Object
Class method to make a call.
124 125 126 127 128 129 130 131 132 |
# File 'lib/voip.rb', line 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 url ||= "" error_url ||= "" caller_id ||= "" caller_displayed_name ||= caller_id http_api_service_port ||= 7780 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 end |
.send_email(ops_ip_address, api_extension, to, http_api_service_port = 7780, message = nil, subject = nil, from = nil, username = nil, password = nil) ⇒ Object
Class method to send an e-mail message.
149 150 151 152 153 154 155 156 157 158 |
# File 'lib/voip.rb', line 149 def self.send_email ops_ip_address, api_extension, to, http_api_service_port=7780, =nil, subject=nil, from=nil, username=nil, password=nil subject = URI::encode(subject || '') from = URI::encode(from || '') = URI::encode( || '') to = URI::encode(to) http_api_service_port ||= 7780 OPS.execute_query "http://#{ops_ip_address}:#{http_api_service_port}/?Command=SendEmail&ApiExtension=#{api_extension}&Sender=#{from}&Recipient=#{to}&Message=#{}&Subject=#{subject}", username, password end |
.send_sms(ops_ip_address, api_extension, to, message, http_api_service_port = 7780, from = nil, delivery_report_url = nil, username = nil, password = nil) ⇒ Object
Class method to send an SMS message.
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/voip.rb', line 135 def self.send_sms ops_ip_address, api_extension, to, , http_api_service_port=7780, from=nil, delivery_report_url=nil, username=nil, password=nil to = URI::encode(to) = URI::encode() from ||= "" from = URI::encode(from) delivery_report_url ||= "" delivery_report_url = URI::encode(delivery_report_url) http_api_service_port ||= 7780 OPS.execute_query "http://#{ops_ip_address}:#{http_api_service_port}/?Command=SendSms&ApiExtension=#{api_extension}&Sender=#{from}&Recipient=#{to}&Message=#{}&DeliveryReportURL=#{delivery_report_url}", username, password end |
Instance Method Details
#list_active_calls ⇒ Object
Instance method to retrieve the list of active calls.
63 64 65 |
# File 'lib/voip.rb', line 63 def list_active_calls OPS.list_active_calls @ops_ip_address, @http_api_service_port, @username, @password end |
#make_call(dialed, url = nil, error_url = nil, caller_id = nil, caller_displayed_name = nil) ⇒ Object
Instance method to make a call.
48 49 50 |
# File 'lib/voip.rb', line 48 def make_call dialed, url=nil, error_url=nil, caller_id=nil, caller_displayed_name=nil OPS.make_call @ops_ip_address, @api_extension, dialed, @http_api_service_port, url, error_url, caller_id, caller_displayed_name, @username, @password end |
#send_email(to, message = nil, subject = nil, from = nil) ⇒ Object
Instance method to send an e-mail message.
58 59 60 |
# File 'lib/voip.rb', line 58 def send_email to, =nil, subject=nil, from=nil OPS.send_email @ops_ip_address, @api_extension, to, @http_api_service_port, , subject, from, @username, @password end |
#send_sms(to, message, from = nil, delivery_report_url = nil) ⇒ Object
Instance method to send an SMS message.
53 54 55 |
# File 'lib/voip.rb', line 53 def send_sms to, , from=nil, delivery_report_url=nil OPS.send_sms @ops_ip_address, @api_extension, to, , @http_api_service_port, from, delivery_report_url, @username, @password end |