class Bandwidth::Call

The Calls resource lets you make phone calls and view information about previous inbound and outbound calls.

Public Class Methods

create(client, data) click to toggle source

Make a phone call @param client [Client] optional client instance to make requests @param data [Hash] data to create a call @return [Call] created call @example

call = Call.create(client, {:from=>"from", :to=>"to"})
# File lib/bandwidth/call.rb, line 41
def self.create(client, data)
  headers = client.make_request(:post, client.concat_user_path(CALL_PATH), data)[1]
  id = Client.get_id_from_location_header(headers[:location])
  self.get(client, id)
end
get(client, id) click to toggle source

Get information about a call that was made or received @param client [Client] optional client instance to make requests @param id [String] id of call @return [Call] Call instance @example

call = Call.get(client, "1")
# File lib/bandwidth/call.rb, line 16
def self.get(client, id)
  item = client.make_request(:get, client.concat_user_path("#{CALL_PATH}/#{id}"))[0]
  Call.new(item, client)
end
list(client, query = nil) click to toggle source

Get a list of previous calls that were made or received @param client [Client] optional client instance to make requests @param query [Hash] query options @return [Array] array of Call ionstances @example

calls = Call.list(client)
# File lib/bandwidth/call.rb, line 28
def self.list(client, query = nil)
  client.make_request(:get, client.concat_user_path(CALL_PATH), query)[0].map do |item|
    Call.new(item, client)
  end
end

Public Instance Methods

answer_on_incoming() click to toggle source

Answer on an incoming call

# File lib/bandwidth/call.rb, line 145
def answer_on_incoming()
  update({:state => 'active'})
  reload()
end
create_gather(data) click to toggle source

Gather the DTMF digits pressed @param data [String|Hash] sentence to speak on creating cather if string, otherwise it is hash with gather options @return [Hash] created gather @example

gather = call.create_gather("Press a digit")
gather = call.create_gather(:max_digits => 1, :prompt => {:sentence => "Press a digit",  :bargeable => true })
# File lib/bandwidth/call.rb, line 81
def create_gather(data)
  d = if data.is_a?(String)
        {
          :tag => id, :max_digits => 1,
          :prompt => {:locale => 'en_US', :gender => 'female', :sentence => data, :voice => 'kate', :bargeable => true }
        }
      else
        data
      end
  headers = @client.make_request(:post, @client.concat_user_path("#{CALL_PATH}/#{id}/gather"), d)[1]
  id = Client.get_id_from_location_header(headers[:location])
  get_gather(id)
end
get_event(event_id) click to toggle source

Gets information about one call event @param event_id [String] id of event @return [Hash] event data @example

e = call.get_event("id")
# File lib/bandwidth/call.rb, line 118
def get_event(event_id)
  @client.make_request(:get, @client.concat_user_path("#{CALL_PATH}/#{id}/events/#{event_id}"))[0]
end
get_events() click to toggle source

Gets the list of call events for a call @return [Array] list of events @example

events = call.get_events()
# File lib/bandwidth/call.rb, line 126
def get_events()
  @client.make_request(:get, @client.concat_user_path("#{CALL_PATH}/#{id}/events"))[0]
end
get_gather(gather_id) click to toggle source

Get the gather DTMF parameters and results @param gather_id [String] id of gather @return [Hash] gather options @example

gather = call.get_gather("id")
# File lib/bandwidth/call.rb, line 109
def get_gather(gather_id)
  @client.make_request(:get, @client.concat_user_path("#{CALL_PATH}/#{id}/gather/#{gather_id}"))[0]
end
get_recordings() click to toggle source

Retrieve all recordings related to the call @return [Array] list of recordings @example

recordings = call.get_recordings()
# File lib/bandwidth/call.rb, line 134
def get_recordings()
  @client.make_request(:get, @client.concat_user_path("#{CALL_PATH}/#{id}/recordings"))[0]
end
hangup() click to toggle source

Hangup a call

# File lib/bandwidth/call.rb, line 139
def hangup()
  update({:state => 'completed'})
  reload()
end
play_audio(data) click to toggle source

Play an audio or speak a sentence in a call @param data [Hash] options for play audio @example

call.play_audio(:file_url => "http://host1")
# File lib/bandwidth/call.rb, line 63
def play_audio(data)
  @client.make_request(:post, @client.concat_user_path("#{CALL_PATH}/#{id}/audio"), data)[0]
end
recording_off() click to toggle source

Tune off recording of a call

# File lib/bandwidth/call.rb, line 163
def recording_off()
  update({:recording_enabled => false})
  reload()
end
recording_on() click to toggle source

Tune on recording of a call

# File lib/bandwidth/call.rb, line 157
def recording_on()
  update({:recording_enabled => true})
  reload()
end
reject_incoming() click to toggle source

Reject a call

# File lib/bandwidth/call.rb, line 151
def reject_incoming()
  update({:state => 'rejected'})
  reload()
end
set_dtmf(dtmf) click to toggle source

Send DTMF @param dtmf [String] dtmf value to send @example

call.send_dtmf("0")
# File lib/bandwidth/call.rb, line 71
def set_dtmf(dtmf)
  @client.make_request(:post, @client.concat_user_path("#{CALL_PATH}/#{id}/dtmf"), {:dtmf_out => dtmf})[0]
end
update(data) click to toggle source

Make changes to an active phone call. E.g.: transfer, hang up, answer or reject incoming calls, call recording, etc. @param data [Hash] changed data @example

call.update(:state=>"completed") #hangup a call
# File lib/bandwidth/call.rb, line 52
def update(data)
  headers = @client.make_request(:post, @client.concat_user_path("#{CALL_PATH}/#{id}"), data)[1]
  if headers[:location]
     Client.get_id_from_location_header(headers[:location])
  end
end
update_gather(gather_id, data) click to toggle source

Update the gather DTMF (Stop Gather) @param gather_id [String] id of gather @param data [Hash] changed data @example

call.update_gather("1", :state => "completed")
# File lib/bandwidth/call.rb, line 100
def update_gather(gather_id, data)
  @client.make_request(:post, @client.concat_user_path("#{CALL_PATH}/#{id}/gather/#{gather_id}"), data)[0]
end

Protected Instance Methods

reload() click to toggle source
# File lib/bandwidth/call.rb, line 170
def reload()
  @data.merge!(@client.make_request(:get, @client.concat_user_path("#{CALL_PATH}/#{id}"))[0])
end