Class: Plivo::Resources::Call
- Inherits:
-
Base::Resource
- Object
- Base::Resource
- Plivo::Resources::Call
- Defined in:
- lib/plivo/resources/calls.rb
Constant Summary
Constants included from Utils
Instance Attribute Summary
Attributes inherited from Base::Resource
Instance Method Summary collapse
- #cancel_request ⇒ Object
- #delete ⇒ Object
- #get_all_streams ⇒ Object
- #get_stream(stream_id) ⇒ Object
-
#initialize(client, options = nil) ⇒ Call
constructor
A new instance of Call.
- #play(urls, options = nil) ⇒ Object
- #record(options = nil) ⇒ Object
- #send_digits(digits, leg = nil) ⇒ Object
- #speak(text, options = nil) ⇒ Object
- #start_stream(service_url, options = nil) ⇒ Object
- #stop_all_streams ⇒ Object
- #stop_play ⇒ Object
- #stop_record(url = nil) ⇒ Object
- #stop_speak ⇒ Object
- #stop_stream(stream_id) ⇒ Object
- #to_s ⇒ Object
- #update(options) ⇒ Object
Methods included from Utils
GetSortedQueryParamString?, compute_signatureV3?, expected_type?, expected_value?, generate_url?, getMapFromQueryString?, is_one_among_string_url?, multi_valid_param?, raise_invalid_request, valid_account?, valid_date_format?, valid_mainaccount?, valid_multiple_destination_integers?, valid_multiple_destination_nos?, valid_param?, valid_range?, valid_signature?, valid_signatureV3?, valid_subaccount?, valid_url?
Constructor Details
#initialize(client, options = nil) ⇒ Call
Returns a new instance of Call.
5 6 7 8 9 10 |
# File 'lib/plivo/resources/calls.rb', line 5 def initialize(client, = nil) @_name = 'Call' @_identifier_string = 'call_uuid' super @_is_voice_request = true end |
Instance Method Details
#cancel_request ⇒ Object
213 214 215 216 |
# File 'lib/plivo/resources/calls.rb', line 213 def cancel_request resource_path = @_resource_uri.sub('Call', 'Request') @_client.send_request(resource_path, 'DELETE', nil, nil, false , is_voice_request: @_is_voice_request) end |
#delete ⇒ Object
62 63 64 |
# File 'lib/plivo/resources/calls.rb', line 62 def delete perform_delete end |
#get_all_streams ⇒ Object
276 277 278 |
# File 'lib/plivo/resources/calls.rb', line 276 def get_all_streams perform_action('Stream', 'GET', nil, true ) end |
#get_stream(stream_id) ⇒ Object
280 281 282 283 |
# File 'lib/plivo/resources/calls.rb', line 280 def get_stream(stream_id) valid_param?(:stream_id, stream_id, [String, Symbol, Integer], true) perform_action('Stream/' + stream_id, 'GET', nil, true) end |
#play(urls, options = nil) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/plivo/resources/calls.rb', line 119 def play(urls, = nil) valid_param?(:urls, urls, Array, true) if .nil? return perform_action('Play', 'POST', { urls: urls.join(',') }, true) end valid_param?(:options, , Hash, true) params = { urls: urls.join(',') } if .key?(:length) && valid_param?(:length, [:length], Integer, true) params[:length] = [:length] end if .key?(:legs) && valid_param?(:legs, [:legs], [String, Symbol], true, %w[aleg bleg both]) params[:legs] = [:legs] end i[loop mix].each do |param| if .key?(param) && valid_param?(param, [param], [TrueClass, FalseClass], true) params[param] = [param] end end perform_action('Play', 'POST', params, true) end |
#record(options = nil) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/plivo/resources/calls.rb', line 66 def record( = nil) return perform_action('Record', 'POST', nil, true) if .nil? valid_param?(:options, , Hash, true) params = {} i[transcription_url callback_url].each do |param| if .key?(param) && valid_param?(param, [param], [String, Symbol], true) params[param] = [param] end end i[transcription_method callback_method].each do |param| if .key?(param) && valid_param?(param, [param], [String, Symbol], true, %w[GET POST]) params[param] = [param] end end if .key?(:time_limit) && valid_param?(:time_limit, [:time_limit], Integer, true) params[:time_limit] = [:time_limit] end if .key?(:file_format) && valid_param?(:file_format, [:file_format], [String, Symbol], true, %w[wav mp3]) params[:file_format] = [:file_format] end if .key?(:transcription_type) && valid_param?(:transcription_type, [:transcription_type], [String, Symbol], true, %w[auto hybrid]) params[:transcription_type] = [:transcription_type] end if .key?(:record_channel_type) && valid_param?(:record_channel_type, [:record_channel_type], [String, Symbol], true) params[:record_channel_type] = [:record_channel_type] end perform_action('Record', 'POST', params, true) end |
#send_digits(digits, leg = nil) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/plivo/resources/calls.rb', line 199 def send_digits(digits, leg = nil) valid_param?(:digits, digits, String, true) params = { digits: digits } if !leg.nil? && valid_param?(:leg, leg, [String, Symbol], true, %w[aleg bleg both]) params[:leg] = leg end perform_action('DTMF', 'POST', params, true) end |
#speak(text, options = nil) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/plivo/resources/calls.rb', line 153 def speak(text, = nil) valid_param?(:text, text, String, true) if .nil? return perform_action('Speak', 'POST', { text: text }, true) end valid_param?(:options, , Hash, true) params = { text: text } if .key?(:language) && valid_param?(:language, [:language], String, true) params[:language] = [:language] end if .key?(:voice) && valid_param?(:voice, [:voice], [String, Symbol], true, %w[MAN WOMAN]) params[:voice] = [:voice] end if .key?(:legs) && valid_param?(:legs, [:legs], [String, Symbol], true, %w[aleg bleg both]) params[:legs] = [:legs] end if .key?(:type) && valid_param?(:type, [:type], [String, Symbol], true, %w[text ssml]) params[:type] = [:type] end i[loop mix].each do |param| if .key?(param) && valid_param?(param, [param], [TrueClass, FalseClass], true) params[param] = [param] end end perform_action('Speak', 'POST', params, true) end |
#start_stream(service_url, options = nil) ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 |
# File 'lib/plivo/resources/calls.rb', line 218 def start_stream(service_url, = nil) valid_param?(:service_url, service_url, [String, Symbol], true) if .nil? return perform_action('Stream', 'POST', { service_url: service_url }, true) end valid_param?(:options, , Hash, true) params = { service_url: service_url } if .key?(:bidirectional) && valid_param?(:bidirectional, [:bidirectional], [TrueClass, FalseClass], false ) params[:bidirectional] = [:bidirectional] end if .key?(:audio_track) && valid_param?(:audio_track, [:audio_track], [String, Symbol], false, %w[inbound outbound both]) params[:audio_track] = [:audio_track] end if .key?(:stream_timeout) && valid_param?(:stream_timeout, [:stream_timeout], Integer, false) params[:stream_timeout] = [:stream_timeout] end if .key?(:status_callback_url) && valid_param?(:status_callback_url, [:status_callback_url], [String, Symbol], false) params[:status_callback_url] = [:status_callback_url] end if .key?(:status_callback_method) && valid_param?(:status_callback_method, [:status_callback_method], [String, Symbol], false, %w[GET POST get post]) params[:status_callback_method] = [:status_callback_method] end if .key?(:content_type) && valid_param?(:content_type, [:content_type], [String, Symbol, Integer], false) params[:content_type] = [:content_type] end if .key?(:extra_headers) && valid_param?(:extra_headers, [:extra_headers], [String], false) params[:extra_headers] = [:extra_headers] end perform_action('Stream', 'POST', params, true) end |
#stop_all_streams ⇒ Object
267 268 269 |
# File 'lib/plivo/resources/calls.rb', line 267 def stop_all_streams perform_action('Stream', 'DELETE', nil, false) end |
#stop_play ⇒ Object
149 150 151 |
# File 'lib/plivo/resources/calls.rb', line 149 def stop_play perform_action('Play', 'DELETE', nil, false) end |
#stop_record(url = nil) ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/plivo/resources/calls.rb', line 111 def stop_record(url = nil) if !url.nil? && valid_param?(:URL, url, [String, Symbol], true) return perform_action('Record', 'DELETE', { URL: url }, false) end perform_action('Record', 'DELETE') end |
#stop_speak ⇒ Object
195 196 197 |
# File 'lib/plivo/resources/calls.rb', line 195 def stop_speak perform_action('Speak', 'DELETE', nil, false) end |
#stop_stream(stream_id) ⇒ Object
271 272 273 274 |
# File 'lib/plivo/resources/calls.rb', line 271 def stop_stream(stream_id) valid_param?(:stream_id, stream_id, [String, Symbol, Integer], true) perform_action('Stream/' + stream_id, 'DELETE', nil, false) end |
#to_s ⇒ Object
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/plivo/resources/calls.rb', line 285 def to_s call_details = { answer_time: @answer_time, api_id: @api_id, bill_duration: @bill_duration, billed_duration: @billed_duration, call_direction: @call_direction, call_duration: @call_duration, call_status: @call_status, call_state: @call_state, call_uuid: @call_uuid, conference_uuid: @conference_uuid, end_time: @end_time, from_number: @from_number, initiation_time: @initiation_time, parent_call_uuid: @parent_call_uuid, hangup_cause_code: @hangup_cause_code, hangup_cause_name: @hangup_cause_name, hangup_source: @hangup_source, resource_uri: @resource_uri, to_number: @to_number, total_amount: @total_amount, total_rate: @total_rate, to: @to, from: @from, request_uuid: @request_uuid, direction: @direction, caller_name: @caller_name, stir_verification: @stir_verification, stir_attestation: @stir_attestation, source_ip: @source_ip, cnam_lookup: @cnam_lookup } call_details = call_details.select {|k, v| !v.nil? } call_details.to_s end |
#update(options) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/plivo/resources/calls.rb', line 12 def update() valid_param?(:options, , Hash, true) params = {} if .key?(:legs) && valid_param?(:legs, [:legs], [String, Symbol], true, %w[aleg bleg both]) params[:legs] = [:legs] end unless .key?(:legs) unless .key?(:aleg_url) raise_invalid_request('default leg is aleg, aleg_url has to be specified') end params[:aleg_url] = [:aleg_url] end if [:legs] == 'aleg' unless .key?(:aleg_url) raise_invalid_request('leg is aleg, aleg_url has to be specified') end params[:aleg_url] = [:aleg_url] end if [:legs] == 'bleg' unless .key?(:bleg_url) raise_invalid_request('leg is bleg, bleg_url has to be specified') end params[:bleg_url] = [:bleg_url] end if [:legs] == 'both' unless .key?(:aleg_url) && .key?(:bleg_url) raise_invalid_request('leg is both, aleg_url & bleg_url have to be specified') end params[:aleg_url] = [:aleg_url] params[:bleg_url] = [:bleg_url] end i[aleg_method bleg_method].each do |param| if .key?(param) && valid_param?(param, [param], [String, Symbol], true, %w[GET POST]) params[param] = [param] end end perform_update(params) end |