class SipgateIo::XmlResponse
Public Class Methods
dial(options = {})
click to toggle source
# File lib/sipgate_io/xml_response.rb, line 7 def dial(options = {}) anonymous = options[:clip] == :anonymous ? Hash[ anonymous: true ] : nil caller_id = !!/\d+/.match(options[:clip]) ? Hash[ callerId: options[:clip] ] : nil builder(options) do |b| b.Dial(anonymous, caller_id) do |b| options[:target] == :voicemail ? b.Voicemail : b.Number(options[:target]) end end end
gather(options = {})
click to toggle source
# File lib/sipgate_io/xml_response.rb, line 24 def gather(options = {}) on_data = Hash[ onData: SipgateIo.configuration.callback_url ] max_digits = parse_option(options, :max_digits, :maxDigits) timeout = parse_option(options, :timeout) play_url = options.key?(:soundfile_url) ? options[:soundfile_url] : nil builder(options) do |b| b.Gather(on_data, max_digits, timeout) do |b| unless play_url.nil? b.Play { |b| b.Url(play_url) } end end end end
hangup(options = {})
click to toggle source
# File lib/sipgate_io/xml_response.rb, line 47 def hangup(options = {}) builder(options) { |b| b.Hangup } end
on_answer()
click to toggle source
# File lib/sipgate_io/xml_response.rb, line 51 def on_answer builder(Hash[ callback: :on_answer ]) end
on_hangup()
click to toggle source
# File lib/sipgate_io/xml_response.rb, line 55 def on_hangup builder(Hash[ callback: :on_hangup ]) end
play(options = {})
click to toggle source
# File lib/sipgate_io/xml_response.rb, line 18 def play(options = {}) url = options[:soundfile_url] builder(options) { |b| b.Play { |b| b.Url(url) } } end
reject(options = {})
click to toggle source
# File lib/sipgate_io/xml_response.rb, line 41 def reject(options = {}) reason = parse_option(options, :reason) builder(options) { |b| b.Reject(reason) } end
Private Class Methods
builder(options) { |response| ... }
click to toggle source
# File lib/sipgate_io/xml_response.rb, line 72 def builder(options) xml = Builder::XmlMarkup.new(indent: 2) xml.instruct! xml.Response(with_callback(options)) do |response| yield(response) if block_given? end end
parse_option(options, key, xml_key_name = nil)
click to toggle source
# File lib/sipgate_io/xml_response.rb, line 61 def parse_option(options, key, xml_key_name = nil) xml_key_name ||= key options.key?(key) ? Hash[ xml_key_name => options[key] ] : nil end
with_callback(options)
click to toggle source
# File lib/sipgate_io/xml_response.rb, line 66 def with_callback(options) return nil unless options.key?(:callback) type = (options[:callback] == :on_answer) ? :onAnswer : :onHangup Hash[ type => SipgateIo.configuration.callback_url ] end