Class: Xoxzo::Cloudruby::XoxzoClient

Inherits:
Object
  • Object
show all
Defined in:
lib/xoxzo/cloudruby.rb

Overview

API obejet class Xoxzo service

Instance Method Summary collapse

Constructor Details

#initialize(sid, token) ⇒ XoxzoClient

initialize xoxzo api client

sid

your api sid of Xoxzo account

token

your api token of Xoxzo account

return

XoxzoResponse



28
29
30
31
32
33
34
35
# 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

Instance Method Details

#call_simple_playback(caller:, recipient:, recording_url:) ⇒ Object

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



93
94
95
96
97
98
99
100
101
102
103
104
# 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:) ⇒ Object

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



112
113
114
115
116
117
118
119
120
121
122
123
# 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) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# 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) ⇒ Object

get setn sms list method

send_data

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

return

XoxzoResponse



73
74
75
76
77
78
79
80
81
82
83
84
85
86
# 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:) ⇒ Object

get simple playback status method

callid

call id in the return value of the call_simple_playback method

return

XoxzoResponse



128
129
130
131
132
133
134
135
136
137
# 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:) ⇒ Object

get sms delivery status method

msgid

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

return

XoxzoResponse



59
60
61
62
63
64
65
66
67
68
# 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_listObject



179
180
181
182
183
184
185
186
187
188
# 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:) ⇒ Object

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



42
43
44
45
46
47
48
49
50
51
52
53
54
# 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:) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
# 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:) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
# 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:) ⇒ Object



168
169
170
171
172
173
174
175
176
177
# 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