Class: Xoxzo::Cloudruby::XoxzoClient
- Inherits:
-
Object
- Object
- Xoxzo::Cloudruby::XoxzoClient
- Defined in:
- lib/xoxzo/cloudruby.rb
Instance Method Summary collapse
- #call_simple_playback(caller:, recipient:, recording_url:) ⇒ Object
- #get_sent_sms_list(sent_date: nil) ⇒ Object
- #get_simple_playback_status(callid:) ⇒ Object
- #get_sms_delivery_status(msgid) ⇒ Object
-
#initialize(sid, token) ⇒ XoxzoClient
constructor
A new instance of XoxzoClient.
- #json_safe_parse(s) ⇒ Object
- #send_sms(message:, recipient:, sender:) ⇒ Object
Constructor Details
#initialize(sid, token) ⇒ XoxzoClient
Returns a new instance of XoxzoClient.
19 20 21 22 23 24 |
# File 'lib/xoxzo/cloudruby.rb', line 19 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_voice_simple_url = api_host + "/voice/simple/playback/" end |
Instance Method Details
#call_simple_playback(caller:, recipient:, recording_url:) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/xoxzo/cloudruby.rb', line 65 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.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}) if res.code == 201 xr = XoxzoRespose.new(messages: json_safe_parse(res.body)) else xr = XoxzoRespose.new(errors: res.code,message: json_safe_parse(res.body)) end return xr end |
#get_sent_sms_list(sent_date: nil) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/xoxzo/cloudruby.rb', line 50 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 = XoxzoRespose.new(messages: json_safe_parse(res.body)) else xr = XoxzoRespose.new(errors: res.code, message: json_safe_parse(res.body)) end return xr end |
#get_simple_playback_status(callid:) ⇒ Object
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/xoxzo/cloudruby.rb', line 78 def get_simple_playback_status(callid:) url = @xoxzo_api_voice_simple_url + callid res = HTTParty.get(url, :basic_auth => @auth) if res.code == 200 xr = XoxzoRespose.new(message: json_safe_parse(res.body)) else xr = XoxzoRespose.new(errors: res.code,message: json_safe_parse(res.body)) end return xr end |
#get_sms_delivery_status(msgid) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/xoxzo/cloudruby.rb', line 39 def get_sms_delivery_status(msgid) url = @xoxzo_api_sms_url + msgid res = HTTParty.get(url, :basic_auth => @auth) if res.code == 200 xr = XoxzoRespose.new(message: json_safe_parse(res.body)) else xr = XoxzoRespose.new(errors: res.code,message: json_safe_parse(res.body)) end return xr end |
#json_safe_parse(s) ⇒ Object
89 90 91 92 93 |
# File 'lib/xoxzo/cloudruby.rb', line 89 def json_safe_parse(s) return JSON.parse(s) rescue JSON::ParserError => e return {} end |
#send_sms(message:, recipient:, sender:) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/xoxzo/cloudruby.rb', line 26 def send_sms(message:, recipient:, sender:) body = {"message" => , "recipient" => recipient , "sender" => sender} res = HTTParty.post(@xoxzo_api_sms_url, :basic_auth => @auth, :body => body.to_json, :headers => { 'Content-Type' => 'application/json', 'Accept' => 'application/json'}) if res.code == 201 xr = XoxzoRespose.new(messages: json_safe_parse(res.body)) else xr = XoxzoRespose.new(errors: res.code,message: json_safe_parse(res.body)) end return xr end |