lib/tropo-webapi-ruby/tropo-webapi-ruby-helpers.rb
##
# Method checks for presence of required elements and then builds the action
#
# @param [String] the name of the action to build
# @param [Hash] the elements to be used to build the action
# @return [Hash] provides the properply built hash for the action
Method checks for presence of required elements and then builds the action
Method checks for presence of required elements and then builds the action
def build_action(action, params)
        raise ArgumentError, 'Action requires parameters' if params.nil?
        case action
        when 'ask'
          has_params?(params, 'ask', ['choices', 'say'])
        when 'choices'
          if params[:mode]
            if params[:mode] != 'dtmf' && params[:mode] != 'speech' && params[:mode] != 'any'
              raise ArgumentError, "If mode is provided, only 'dtmf', 'speech' or 'any' is supported"
            end
          end
        when 'call'
          has_params?(params, 'call', ['to'])
        when 'conference'
          has_params?(params, 'conference', ['id'])
        when 'on'
          has_params?(params, 'on', 'event')
        when 'record'
          has_params?(params, 'record', ['url'])
        when 'start_recording'
          has_params?(params, 'start_recording', ['url'])
          action = 'startRecording'
        when 'redirect'
          has_params?(params, 'redirect', ['to'])
          raise ArgumentError, "Redirect should only be used alone and before the session is answered, use transfer instead" if @nested_hash
        when 'say'
          has_params?(params, 'say', ['value'])
          return build_elements(params)
        when 'nestedSay'
          has_params?(params, 'say', 'value')
          return build_elements(params)
        when 'transfer'
          has_params?(params, 'transfer', ['to'])
        when 'wait'
          has_params?(params, 'wait', 'milliseconds')
        when 'message'
          has_params?(params, 'message', ['say', 'to'])
        end
        if action == 'on'
          build_elements(params)
        elsif action == 'generalLogSecurity'
          {action => params[:state]}
        else
          { action.to_sym => build_elements(params) }
        end
      end
def build_action ( action , params ) raise ArgumentError , 'Action requires parameters' if params . nil? case action when 'ask' has_params? ( params , 'ask' , [ 'choices' , 'say' ] ) when 'choices' if params [ :mode ] if params [ :mode ] != 'dtmf' && params [ :mode ] != 'speech' && params [ :mode ] != 'any' raise ArgumentError , "If mode is provided, only 'dtmf', 'speech' or 'any' is supported" end end when 'call' has_params? ( params , 'call' , [ 'to' ] ) when 'conference' has_params? ( params , 'conference' , [ 'id' ] ) when 'on' has_params? ( params , 'on' , 'event' ) when 'record' has_params? ( params , 'record' , [ 'url' ] ) when 'start_recording' has_params? ( params , 'start_recording' , [ 'url' ] ) action = 'startRecording' when 'redirect' has_params? ( params , 'redirect' , [ 'to' ] ) raise ArgumentError , "Redirect should only be used alone and before the session is answered, use transfer instead" if @nested_hash when 'say' has_params? ( params , 'say' , [ 'value' ] ) return build_elements ( params ) when 'nestedSay' has_params? ( params , 'say' , 'value' ) return build_elements ( params ) when 'transfer' has_params? ( params , 'transfer' , [ 'to' ] ) when 'wait' has_params? ( params , 'wait' , 'milliseconds' ) when 'message' has_params? ( params , 'message' , [ 'say' , 'to' ] ) end if action == 'on' build_elements ( params ) elsif action == 'generalLogSecurity' { action => params [ :state ] } else { action . to_sym => build_elements ( params ) } end end
Method checks for presence of required elements and then builds the action
Method checks for presence of required elements and then builds the action
# Camelcase this one to be Java friendly
provides the properply built hash for the action
provides the properply built hash for the action
Hash
action
params
the elements to be used to build the action
the elements to be used to build the action