lib/tropo-webapi-ruby/tropo-webapi-ruby.rb
def on(params={}, &block)
      if block_given?
        if @nested_hash
          create_nested_on_hash(params)
          instance_exec(&block)
          if @nested_hash[@nested_name.to_sym][:on].nil?
            @nested_hash[@nested_name.to_sym][:on] = Array.new
          end
          @nested_on_hash[:on].each do |hash|
            @nested_hash[@nested_name.to_sym][:on] << hash
          end
          @nested_on_hash = nil
          @nested_on_hash_cnt = nil
        else
          @on_hash = { :on => build_action('on', params)}
          instance_exec(&block)
          @response[:tropo] << @on_hash
          @on_hash = nil
        end
      else
        create_on_hash
        hash = build_action('on', params)
#        @on_hash[:on] << hash
        if @nested_hash
          if @nested_hash[@nested_name.to_sym][:on].nil?
            @nested_hash[@nested_name.to_sym][:on] = Array.new
          end
          @nested_hash[@nested_name.to_sym][:on] << hash
        else
          @on_hash = nil
          @response[:tropo] << { :on => hash }
          render_response if @building.nil?
        end
      end
    end
##
# Sets event handlers to call a REST resource when a particular event occurs
#
# @overload initialize(params)
#   @param [Hash] params the options to create a message with.
#   @option params [required, String] :event the event name that should trigger the callback
#   @option params [optional, String] :next the resource to send the callback to, such as '/error.json'
#   @option params [optional, String] :say determines what is played or sent to the caller
#   @option params [optional, String] :post This parameter is only available in the 'connect' event of transfer.
# @overload initialize(params, &block)
#   @param [Hash] params the options to create a message with.
#   @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event
#   @option params [required, String] :event the event name that should trigger the callback
#   @option params [optional, String] :next the resource to send the callback to, such as '/error.json'
#   @option params [optional, String] :say determines what is played or sent to the caller
#   @option params [optional, String] :post This parameter is only available in the 'connect' event of transfer.
# @option [String, nil] the JSON string to be passed back to Tropo or nil
#   if the method has been called from inside a block
Sets event handlers to call a REST resource when a particular event occurs
Sets event handlers to call a REST resource when a particular event occurs
def on(params={}, &block)
      if block_given?
        if @nested_hash
          create_nested_on_hash(params)
          instance_exec(&block)
          if @nested_hash[@nested_name.to_sym][:on].nil?
            @nested_hash[@nested_name.to_sym][:on] = Array.new
          end
          @nested_on_hash[:on].each do |hash|
            @nested_hash[@nested_name.to_sym][:on] << hash
          end
          @nested_on_hash = nil
          @nested_on_hash_cnt = nil
        else
          @on_hash = { :on => build_action('on', params)}
          instance_exec(&block)
          @response[:tropo] << @on_hash
          @on_hash = nil
        end
      else
        create_on_hash
        hash = build_action('on', params)
        if @nested_hash
          if @nested_hash[@nested_name.to_sym][:on].nil?
            @nested_hash[@nested_name.to_sym][:on] = Array.new
          end
          @nested_hash[@nested_name.to_sym][:on] << hash
        else
          @on_hash = nil
          @response[:tropo] << { :on => hash }
          render_response if @building.nil?
        end
      end
    end
def on ( params = { } , & block ) if block_given? if @nested_hash create_nested_on_hash ( params ) instance_exec ( & block ) if @nested_hash [ @nested_name . to_sym ] [ :on ] . nil? @nested_hash [ @nested_name . to_sym ] [ :on ] = Array . new end @nested_on_hash [ :on ] . each do | hash | @nested_hash [ @nested_name . to_sym ] [ :on ] << hash end @nested_on_hash = nil @nested_on_hash_cnt = nil else @on_hash = { :on => build_action ( 'on' , params ) } instance_exec ( & block ) @response [ :tropo ] << @on_hash @on_hash = nil end else create_on_hash hash = build_action ( 'on' , params ) if @nested_hash if @nested_hash [ @nested_name . to_sym ] [ :on ] . nil? @nested_hash [ @nested_name . to_sym ] [ :on ] = Array . new end @nested_hash [ @nested_name . to_sym ] [ :on ] << hash else @on_hash = nil @response [ :tropo ] << { :on => hash } render_response if @building . nil? end end end
Sets event handlers to call a REST resource when a particular event occurs
Sets event handlers to call a REST resource when a particular event occurs
#        @on_hash[:on] << hash
params
block
the JSON string to be passed back to Tropo or nil if the method has been called from inside a block
the JSON string to be passed back to Tropo or nil if the method has been called from inside a block
overload
initialize(params) @param [Hash] params the options to create a message with. @option params [required, String] :event the event name that should trigger the callback @option params [optional, String] :next the resource to send the callback to, such as '/error.json' @option params [optional, String] :say determines what is played or sent to the caller @option params [optional, String] :post This parameter is only available in the 'connect' event of transfer.
initialize ( params ) @param [ Hash ] params the options to create a message with . @option params [ required String ] : event the event name that should trigger the callback @option params [ optional String ] : next the resource to send the callback to such as ' / error . json ' @option params [ optional String ] : say determines what is played or sent to the caller @option params [ optional String ] : post This parameter is only available in the ' connect ' event of transfer .
overload
initialize(params, █) @param [Hash] params the options to create a message with. @param [Block] takes a block so that you may trigger actions, such as a say, on a specific event @option params [required, String] :event the event name that should trigger the callback @option params [optional, String] :next the resource to send the callback to, such as '/error.json' @option params [optional, String] :say determines what is played or sent to the caller @option params [optional, String] :post This parameter is only available in the 'connect' event of transfer.
initialize ( params █ ) @param [ Hash ] params the options to create a message with . @param [ Block ] takes a block so that you may trigger actions such as a say on a specific event @option params [ required String ] : event the event name that should trigger the callback @option params [ optional String ] : next the resource to send the callback to such as ' / error . json ' @option params [ optional String ] : say determines what is played or sent to the caller @option params [ optional String ] : post This parameter is only available in the ' connect ' event of transfer .