Skip to content

THECALLR/sdk-ruby

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sdk-ruby

SDK in Ruby for CALLR API

Quick start

Install via Rubygems

gem install callr

Or get sources from Github

Initialize your code

Gem

require 'callr'
api = CALLR::Api.new('login', 'password')

Source

load 'lib/callr.rb'
api = CALLR::Api.new('login', 'password')

Exception management

begin
  api = CALLR::Api.new('login', 'password')
  api.call('sms.send', 'SMS')
rescue CALLR::CallrException, CALLR::CallrLocalException => e
  puts "ERROR: #{e.code}"
  puts "MESSAGE: #{e.msg}"
  puts "DATA: ", e.data
end

Usage

login as :

api.set_login_as('user', 'foo') # login as user foo
api.set_login_as('account', 'foo') # login as account foo
api.set_login_as(nil, nil) # Remove login-as

Sending SMS

Without options

result = api.call('sms.send', 'SMS', '+33123456789', 'Hello world!', nil)

Method

Personalized sender

Your sender must have been authorized and respect the sms_sender format

result = api.call('sms.send', 'Your Brand', '+33123456789', 'Hello world!', nil)

Method

If you want to receive replies, do not set a sender - we will automatically use a shortcode

result = api.call('sms.send', '', '+33123456789', 'Hello world!', nil)

Method

Force GSM encoding

optionSMS = { :force_encoding => 'GSM' }

result = api.call('sms.send', '', '+33123456789', 'Hello world!', optionSMS)

Method

Objects

Long SMS (availability depends on carrier)

text = 'Some super mega ultra long text to test message longer than 160 characters ' +
           'Some super mega ultra long text to test message longer than 160 characters ' +
           'Some super mega ultra long text to test message longer than 160 characters'
result = api.call('sms.send', 'SMS', '+33123456789', text, nil)

Method

Specify your SMS nature (alerting or marketing)

optionSMS = { :nature => 'ALERTING' }

result = api.call('sms.send', 'SMS', '+33123456789', 'Hello world!', optionSMS)

Method

Objects

Custom data

optionSMS = { :user_data => '42' }

result = api.call('sms.send', 'SMS', '+33123456789', 'Hello world!', optionSMS)

Method

Objects

Delivery Notification - set URL to receive notifications

optionSMS = {
    :push_dlr_enabled => true,
    :push_dlr_url => 'http://yourdomain.com/push_delivery_path',
    # :push_dlr_url_auth => 'login:password' # needed if you use Basic HTTP Authentication
}

result = api.call('sms.send', 'SMS', '+33123456789', 'Hello world!', optionSMS)

Method

Objects

Inbound SMS - set URL to receive inbound messages (MO) and replies

Do not set a sender if you want to receive replies - we will automatically use a shortcode.

optionSMS = {
    :push_mo_enabled => true,
    :push_mo_url => 'http://yourdomain.com/mo_delivery_path',
    # :push_mo_url_auth => 'login:password' # needed if you use Basic HTTP Authentication
}

result = api.call('sms.send', '', '+33123456789', 'Hello world!', optionSMS)

Method

Objects

Get an SMS

result = api.call('sms.get', 'SMSHASH')

Method

Objects

SMS Global Settings

Get settings

result = api.call('sms.get_settings')

Method

Objects

Set settings

Add options that you want to change in the object

settings = {
    :push_dlr_enabled => true,
    :push_dlr_url => 'http://yourdomain.com/push_delivery_path',
    :push_mo_enabled => true,
    :push_mo_url => 'http://yourdomain.com/mo_delivery_path'
}

result = api.call('sms.set_settings', settings)

Returns the updated settings.

Method

Objects


REALTIME

Create a REALTIME app with a callback URL

options = {
    :url => 'http://yourdomain.com/realtime_callback_url'
}

result = api.call('apps.create', 'REALTIME10', 'Your app name', options)

Method

Objects

Start a REALTIME outbound call

target = {
    :number => '+33132456789',
    :timeout => 30
}

callOptions = {
    :cdr_field => '42',
    :cli => 'BLOCKED'
}

result = api.call('dialr/call.realtime', 'appHash', target, callOptions)

Method

Objects

Inbound Calls - Assign a phone number to a REALTIME app

result = api.call('apps.assign_did', 'appHash', 'DID ID')

Method

Objects


DIDs

List available countries with DID availability

result = api.call('did/areacode.countries')

Method

Objects

Get area codes available for a specific country and DID type

result = api.call('did/areacode.get_list', 'US', nil)

Method

Objects

Get DID types available for a specific country

result = api.call('did/areacode.types', 'US')

Method

Objects

Buy a DID (after a reserve)

result = api.call('did/store.buy_order', 'OrderToken')

Method

Objects

Cancel your order (after a reserve)

result = api.call('did/store.cancel_order', 'OrderToken')

Method

Cancel a DID subscription

result = api.call('did/store.cancel_subscription', 'DID ID')

Method

View your store quota status

result = api.call('did/store.get_quota_status')

Method

Objects

Get a quote without reserving a DID

result = api.call('did/store.get_quote', 0, 'GOLD', 1)

Method

*Objects/

Reserve a DID

result = api.call('did/store.reserve', 0, 'GOLD', 1, 'RANDOM')

Method

Objects

View your order

result = api.call('did/store.view_order', 'OrderToken')

Method

Objects


Conferencing

Create a conference room

params = { :open => true }
access = []

result = api.call('conference/10.create_room', 'room name', params, access)

Method

Objects

Assign a DID to a room

result = api.call('conference/10.assign_did', 'Room ID', 'DID ID')

Method

Create a PIN protected conference room

params = { :open => true }
access = [
    { :pin => '1234', :level => 'GUEST' },
    { :pin => '4321', :level => 'ADMIN', :phone_number => '+33123456789' }
]

result = api.call('conference/10.create_room', 'room name', params, access)

Method

Objects

Call a room access

result = api.call('conference/10.call_room_access', 'Room Access ID', 'BLOCKED', true)

Method


Media

List your medias

result = api.call('media/library.get_list', nil)

Method

Create an empty media

result = api.call('media/library.create', 'name')

Method

Upload a media

media_id = 0

result = api.call('media/library.set_content', media_id, 'text', 'base64_audio_data')

Method

Use Text-to-Speech

media_id = 0

result = api.call('media/tts.set_content', media_id, 'Hello world!', 'TTS-EN-GB_SERENA', nil)

Method


CDR

Get inbound or outbound CDRs

from = 'YYYY-MM-DD HH:MM:SS'
to = 'YYYY-MM-DD HH:MM:SS'

result = api.call('cdr.get', 'OUT', from, to, nil, nil)

Method

Objects


SENDR

Broadcast messages to a target (BETA)

target = {
    :number => '+33123456789',
    :timeout => 30
}

messages = [131, 132, 'TTS|TTS_EN-GB_SERENA|Hello world! how are you ? I hope you enjoy this call. good bye.']

options = {
    :cdr_field => 'userData',
    :cli => 'BLOCKED',
    :loop => 2
}

result = api.call('sendr/simple.broadcast_1', target, messages, options)
Without options
target = {
    :number => '+33123456789',
    :timeout => 30
}

messages = [131, 132, 134]

result = api.call('sendr/simple.broadcast_1', target, messages, nil)

Method

Objects