Ruby VoIP developers 101

Part 4: Ruby connection with gem library (Calls)

The Ozeki Phone System gives you the opportunity to use its special features. It is possible to use the ops_sdk.gem library to connect to the Ozeki Phone System. This guide helps you to install, and use this library.

Part 1: Ruby example on sending SMS, making VoIP calls
Part 2: Ruby example on recording VoIP calls, call routing
Part 3: Ruby connection with gem library (SMS)
Part 5: Ruby SDK Commands

Overview

This page assumes that you already have some basic knowledge in Ruby programming language. If you don't have these skills, then you should check out our basic examle site at Ruby basic example.

1. Installing

First you should download the Ozeki_VoIP_Ruby_Library.zip (100KB). After unpacking this zip file, you should execute the following command in a command prompt or in a terminal.

gem install ops_sdk

2. Using the library

In your project after the successful installation, you should include the gem file with the following command.

require 'ops_sdk'

Code example 1 - Including Ozeki Phone System SDK library

Now you are ready to call the functions. Here is an example how to send an SMS from the 9999 API extension to the 2000 SIP extension if your Ozeki Phone System XE IP address is 192.168.0.1, the HTTP API service is listening on port 7780, and the authentication is set to Anonymous.

OPS.send_sms '192.168.0.1', '9999', '2000', 'Hello world!'

ops = OPS.new '192.168.0.1', '9999'
ops.send_sms '2000', 'Hello world!'

Code example 2 - Sending an SMS message

To send an e-mail with the aid of 9999 API extension.

OPS.send_email '192.168.0.1', '9999', 'teszt.elek@company.hu', 'Nin hao!', nil, 'toth.elemer@company.hu'

ops = OPS.new '192.168.0.1', '9999'
ops.send_email 'teszt.elek@company.hu', 'Nin hao!', nil, 'toth.elemer@company.hu'

Code example 3 - Sending an e-mail message

To call an extension with the aid of 9999 API extension.

OPS.make_call '192.168.0.1', '9999', '2000', 7780, 'http://localhost/test.xml', nil, 'Elek'

ops = OPS.new '192.168.0.1', '9999'
ops.make_call '2000', 7780, 'http://localhost/test.xml', nil, 'Elek'

Code example 4 - Make a call

To get a list of active calls.

calls = OPS.list_active_calls '192.168.0.1'
puts calls

ops = OPS.new '192.168.0.1'
calls = ops.list_active_calls
puts calls

Code example 5 - List active calls

3. Call functions

After you get the active calls with the list_active_calls command, you are able to use the following commands too.

# Get active calls if HTTP API service running on port 7781
calls = OPS.list_active_calls '192.168.0.1', 7781

call = calls[0]
if (call == nil)
return 'No call in progress.'

# The hold command is used to put both legs of the call into Hold state.
call.hold

# The unhold command is used to put both legs of the call to InCall state.
call.unhold

# The dtmf command is used to send a DTMF message to a participant of the conversation.
call.dtmf "12345"
call.dtmf_to_caller "678"
call.dtmf_to_callee "90"

# The speak command converts the given text to speech and plays it to the caller, callee or all.
call.speak "12345"
call.speak_to_caller "678"
call.speak_to_callee "90"

# The play_file command is used to play a wav or mp3 sound to the parties of the conversation.
call.play_file "C:\work\Other\simpledemo.wav"
call.play_file_to_caller "C:\work\Other\simpledemo.wav"
call.play_file_to_callee "C:\work\Other\simpledemo.wav"

# Records the conversation in a call. When the call finished, a request will be sent to the specified URL.
call.record_mp3
call.record_wav

# The forward command forwards a call by ID to another number while it's still in ringing state.
call.forward 1000

# The BlindTransfer command is used to connect two phones together.
call.blind_transfer_callee 1002
call.blind_transfer_caller 1000

# The Hangup command is used to disconnect an ongoing call in the system.
call.hangup

Code example 5 - Call commands

Read more about OzML commands.

Part 5: Ruby SDK Commands

If you have any questions or need assistance, please do not hesitate to contact us at info@ozekiphone.com.

More information