Method: Bandwidth#method_missing

Defined in:
lib/bandwidth/bandwidth.rb

#method_missing(method_name, params = {}) ⇒ Hashie::Mash Object

Provides the dispatcher to the available REST methods on the Bandwidth API

Examples:

Retrieve numbers available in an area code

bandwidth.area_code_number_search :area_code => '720', :max_quantity => 10

Parameters:

  • the (required, Symbol)

    method name to invoke on the REST API

  • the (optional, Hash)

    parameters to pass to the method, should be symbols and may be all lowercase with underscores or camelCase

Returns:

  • (Hashie::Mash Object)

    containing the results of the REST call

Raises:

  • NoMethodError if the method requested is not defined in the API_METHODS constant



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/bandwidth/bandwidth.rb', line 60

def method_missing(method_name, params={})
  raise NoMethodError, "The method #{method_name.to_s} does not exist." if API_METHODS.include?(method_name) == false
  
  if method_name == :get_cdr_archive
    @cdrs_request.body = Gyoku.xml({ method_name => params.merge({ :developer_key => @developer_key }),
                                        :attributes! => xml_namespaces(method_name) })
                                                                 
    response = HTTPI.post @cdrs_request
  else
    @numbers_request.body = Gyoku.xml({ method_name => params.merge({ :developer_key => @developer_key }),
                                        :attributes! => xml_namespaces(method_name) })
                                                                 
    response = HTTPI.post @numbers_request
  end
  
  Hashie::Mash.new({ :code    => response.code,
                     :body    => Crack::XML.parse(response.raw_body),
                     :headers => response.headers })
end