class Xoxzo::Cloudruby::XoxzoClient

API obejet class Xoxzo service

Public Class Methods

new(sid,token) click to toggle source

initialize xoxzo api client

sid

your api sid of Xoxzo account

token

your api token of Xoxzo account

return

XoxzoResponse

# File lib/xoxzo/cloudruby.rb, line 28
def initialize(sid,token)
    @auth = {:username => sid, :password => token}
    api_host = "https://api.xoxzo.com"
    @xoxzo_api_sms_url = api_host + "/sms/messages/"
    @xoxzo_api_call_url = api_host + "/voice/calls/"
    @xoxzo_api_voice_simple_url = api_host + "/voice/simple/playbacks/"
    @xoxzo_api_dins_url = api_host + "/voice/dins/"
end

Public Instance Methods

call_simple_playback(caller:, recipient:, recording_url:) click to toggle source

call simple playback method

caller

caller phone number displayed on the recipient hand set

recipient

sms recipient phone number eg. “+818012345678”, remove first 0 in front of area number

recording_url

URL of the mp3 file to playback. eg. “example.com/example.mp3

return

XoxzoResponse

# File lib/xoxzo/cloudruby.rb, line 93
def call_simple_playback(caller:, recipient:, recording_url:)
  body = {"caller" => caller , "recipient" => recipient , "recording_url" => recording_url}
  res = HTTParty.post(@xoxzo_api_voice_simple_url, :basic_auth => @auth,
                      :body => body,
                      :headers => { 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json'})
  if res.code == 201
    xr = XoxzoResponse.new(messages: json_safe_parse(res.body))
  else
    xr = XoxzoResponse.new(errors: res.code,message: json_safe_parse(res.body))
  end
  return xr
end
call_tts_playback(caller:, recipient:, tts_message:, tts_lang:) click to toggle source

call TTS playback method

caller

caller phone number displayed on the recipient hand set

recipient

sms recipient phone number eg. “+818012345678”, remove first 0 in front of area number

tts_message

TTS text message you want to playback. eg. “Hello”

tts_lang

language code of TTS call. eg. “en”

return

XoxzoResponse

# File lib/xoxzo/cloudruby.rb, line 112
def call_tts_playback(caller:, recipient:, tts_message:, tts_lang:)
  body = {"caller" => caller , "recipient" => recipient , "tts_message" => tts_message , "tts_lang" => tts_lang}
  res = HTTParty.post(@xoxzo_api_voice_simple_url, :basic_auth => @auth,
                      :body => body,
                      :headers => { 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json'})
  if res.code == 201
    xr = XoxzoResponse.new(messages: json_safe_parse(res.body))
  else
    xr = XoxzoResponse.new(errors: res.code,message: json_safe_parse(res.body))
  end
  return xr
end
get_din_list(search_string: nil) click to toggle source
# File lib/xoxzo/cloudruby.rb, line 139
def get_din_list(search_string: nil)
  if search_string == nil
    url = @xoxzo_api_dins_url
  else
    url = @xoxzo_api_dins_url + '?' + search_string
  end
  res = HTTParty.get(url, :basic_auth => @auth)
  if res.code == 200
    xr = XoxzoResponse.new(message: json_safe_parse(res.body))
  else
    xr = XoxzoResponse.new(errors: res.code,message: json_safe_parse(res.body))
  end
  return xr
end
get_sent_sms_list(sent_date: nil) click to toggle source

get setn sms list method

send_data

query string. eg. “=2016-05-18”

return

XoxzoResponse

# File lib/xoxzo/cloudruby.rb, line 73
def get_sent_sms_list(sent_date: nil)
  if sent_date == nil
    url = @xoxzo_api_sms_url
  else
    url = @xoxzo_api_sms_url + "?sent_date" + sent_date
  end
  res = HTTParty.get(url, :basic_auth => @auth)
  if res.code == 200
    xr = XoxzoResponse.new(messages: json_safe_parse(res.body))
  else
    xr = XoxzoResponse.new(errors: res.code, message: json_safe_parse(res.body))
  end
  return xr
end
get_simple_playback_status(callid:) click to toggle source

get simple playback status method

callid

call id in the return value of the call_simple_playback method

return

XoxzoResponse

# File lib/xoxzo/cloudruby.rb, line 128
def get_simple_playback_status(callid:)
  url = @xoxzo_api_call_url + callid
  res = HTTParty.get(url, :basic_auth => @auth)
  if res.code == 200
    xr = XoxzoResponse.new(message: json_safe_parse(res.body))
  else
    xr = XoxzoResponse.new(errors: res.code,message: json_safe_parse(res.body))
  end
  return xr
end
get_sms_delivery_status(msgid:) click to toggle source

get sms delivery status method

msgid

message id of in the return value of the send_sms method.

return

XoxzoResponse

# File lib/xoxzo/cloudruby.rb, line 59
def get_sms_delivery_status(msgid:)
  url = @xoxzo_api_sms_url + msgid
  res = HTTParty.get(url, :basic_auth => @auth)
  if res.code == 200
    xr = XoxzoResponse.new(message: json_safe_parse(res.body))
  else
    xr = XoxzoResponse.new(errors: res.code,message: json_safe_parse(res.body))
  end
  return xr
end
get_subscription_list() click to toggle source
# File lib/xoxzo/cloudruby.rb, line 179
def get_subscription_list()
  url = @xoxzo_api_dins_url + 'subscriptions/'
  res = HTTParty.get(url, :basic_auth => @auth)
  if res.code == 200
    xr = XoxzoResponse.new(messages: json_safe_parse(res.body))
  else
    xr = XoxzoResponse.new(errors: res.code,message: json_safe_parse(res.body))
  end
  return xr
end
send_sms(message:, recipient:, sender:) click to toggle source

send sms method

messages

sms text message

recipient

sms recipient phone numner eg. “+818012345678”, remove first 0 in front of area number

sender

sem sender phone number. This value may not be displayed as is for some operators.

return

XoxzoResponse

# File lib/xoxzo/cloudruby.rb, line 42
def send_sms(message:, recipient:, sender:)
  body = {"message" => message , "recipient" => recipient , "sender" => sender}
  res = HTTParty.post(@xoxzo_api_sms_url, :basic_auth => @auth,
                      :body => body,
                      #:debug_output => $stdout,
                      :headers => { 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json'})
  if res.code == 201
    xr = XoxzoResponse.new(messages: json_safe_parse(res.body))
  else
    xr = XoxzoResponse.new(errors: res.code,message: json_safe_parse(res.body))
  end
  return xr
end
set_action_url(din_uid:, action_url:) click to toggle source
# File lib/xoxzo/cloudruby.rb, line 190
def set_action_url(din_uid:, action_url:)
  url = @xoxzo_api_dins_url + 'subscriptions/' + din_uid + '/'
  body = {'action_url': action_url}
  res = HTTParty.post(url, :basic_auth => @auth,
                      :body => body,
                      :headers => { 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json'})
  if res.code == 200
    xr = XoxzoResponse.new(messages: json_safe_parse(res.body))
  else
    xr = XoxzoResponse.new(errors: res.code,message: json_safe_parse(res.body))
  end
  return xr
end
subscribe_din(din_uid:) click to toggle source
# File lib/xoxzo/cloudruby.rb, line 154
def subscribe_din(din_uid:)
  url = @xoxzo_api_dins_url + 'subscriptions/'
  body = {"din_uid" => din_uid }
  res = HTTParty.post(url, :basic_auth => @auth,
                      :body => body,
                      :headers => { 'Content-Type' => 'application/x-www-form-urlencoded', 'Accept' => 'application/json'})
  if res.code == 201
    xr = XoxzoResponse.new(messages: json_safe_parse(res.body))
  else
    xr = XoxzoResponse.new(errors: res.code,message: json_safe_parse(res.body))
  end
  return xr
end
unsubscribe_din(din_uid:) click to toggle source
# File lib/xoxzo/cloudruby.rb, line 168
def unsubscribe_din(din_uid:)
  url = @xoxzo_api_dins_url + 'subscriptions/' + din_uid + '/'
  res = HTTParty.delete(url, :basic_auth => @auth)
  if res.code == 200
    xr = XoxzoResponse.new(messages: json_safe_parse(res.body))
  else
    xr = XoxzoResponse.new(errors: res.code,message: json_safe_parse(res.body))
  end
  return xr
end

Private Instance Methods

json_safe_parse(s) click to toggle source
# File lib/xoxzo/cloudruby.rb, line 205
def json_safe_parse(s)
  return JSON.parse(s)
rescue JSON::ParserError => e
  return {}
end