lib/tropo-webapi-ruby/tropo-webapi-ruby-helpers.rb
def build_elements(params)
        if params[:url]
          if params[:url].is_a? Array
            for i in params[:url] do  
              uri = URI.parse i[:url]
              # Check to see if it is a valid http address
              if uri.class != URI::HTTP
                # Check to see if it is a valid email address
                if params[:url].match(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/) == false
                  raise ArgumentError, "The 'url' paramater must be a valid URL"
                end
              end
            end
          elsif params[:url].nil?
            if params[:url][:url].nil?
              uri = URI.parse params[:url][:url]
              # Check to see if it is a valid http address
              if uri.class != URI::HTTP
                # Check to see if it is a valid email address
                if params[:url].match(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/) == false
                  raise ArgumentError, "The 'url' paramater must be a valid URL"
                end
              end
            else
              uri = URI.parse params[:url]
              # Check to see if it is a valid http address
              if uri.class != URI::HTTP
                # Check to see if it is a valid email address
                if params[:url].match(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/) == false
                  raise ArgumentError, "The 'url' paramater must be a valid URL"
                end
              end
            end
          end
        end

        hash = Hash.new
        params.each_pair do |k,v|
          if k.to_s.include? "_"
            k = camelize k.to_s
            k = k.to_sym if k
          end
          hash.merge!({ k => v })
        end
        hash
      end
##
# Method builds the elements for each of the actions
#
# @param [Hash] the individual elements to be used to build the hash
# @return [Hash] returns the elements properly formatted in a hash
Method builds the elements for each of the actions
Method builds the elements for each of the actions
def build_elements(params)
        if params[:url]
          if params[:url].is_a? Array
            for i in params[:url] do  
              uri = URI.parse i[:url]
              if uri.class != URI::HTTP
                if params[:url].match(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/) == false
                  raise ArgumentError, "The 'url' paramater must be a valid URL"
                end
              end
            end
          elsif params[:url].nil?
            if params[:url][:url].nil?
              uri = URI.parse params[:url][:url]
              if uri.class != URI::HTTP
                if params[:url].match(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/) == false
                  raise ArgumentError, "The 'url' paramater must be a valid URL"
                end
              end
            else
              uri = URI.parse params[:url]
              if uri.class != URI::HTTP
                if params[:url].match(/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/) == false
                  raise ArgumentError, "The 'url' paramater must be a valid URL"
                end
              end
            end
          end
        end
        hash = Hash.new
        params.each_pair do |k,v|
          if k.to_s.include? "_"
            k = camelize k.to_s
            k = k.to_sym if k
          end
          hash.merge!({ k => v })
        end
        hash
      end
def build_elements ( params ) if params [ :url ] if params [ :url ] . is_a? Array for i in params [ :url ] do uri = URI . parse i [ :url ] if uri . class != URI :: HTTP if params [ :url ] . match ( / ^[a-zA-Z][ \w \. -]*[a-zA-Z0-9]@[a-zA-Z0-9][ \w \. -]*[a-zA-Z0-9] \. [a-zA-Z][a-zA-Z \. ]*[a-zA-Z]$ / ) == false raise ArgumentError , "The 'url' paramater must be a valid URL" end end end elsif params [ :url ] . nil? if params [ :url ] [ :url ] . nil? uri = URI . parse params [ :url ] [ :url ] if uri . class != URI :: HTTP if params [ :url ] . match ( / ^[a-zA-Z][ \w \. -]*[a-zA-Z0-9]@[a-zA-Z0-9][ \w \. -]*[a-zA-Z0-9] \. [a-zA-Z][a-zA-Z \. ]*[a-zA-Z]$ / ) == false raise ArgumentError , "The 'url' paramater must be a valid URL" end end else uri = URI . parse params [ :url ] if uri . class != URI :: HTTP if params [ :url ] . match ( / ^[a-zA-Z][ \w \. -]*[a-zA-Z0-9]@[a-zA-Z0-9][ \w \. -]*[a-zA-Z0-9] \. [a-zA-Z][a-zA-Z \. ]*[a-zA-Z]$ / ) == false raise ArgumentError , "The 'url' paramater must be a valid URL" end end end end end hash = Hash . new params . each_pair do | k , v | if k . to_s . include? "_" k = camelize k . to_s k = k . to_sym if k end hash . merge! ( { k => v } ) end hash end
Method builds the elements for each of the actions
Method builds the elements for each of the actions
# Check to see if it is a valid http address # Check to see if it is a valid email address # Check to see if it is a valid http address # Check to see if it is a valid email address # Check to see if it is a valid http address # Check to see if it is a valid email address
returns the elements properly formatted in a hash
returns the elements properly formatted in a hash
Hash
params
the individual elements to be used to build the hash
the individual elements to be used to build the hash