Class: CallParser::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/call_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#pathObject

Returns the value of attribute path.



7
8
9
# File 'lib/call_parser.rb', line 7

def path
  @path
end

#queryObject

Returns the value of attribute query.



7
8
9
# File 'lib/call_parser.rb', line 7

def query
  @query
end

Instance Method Details

#call(env) ⇒ Object



33
34
35
36
37
38
# File 'lib/call_parser.rb', line 33

def call(env)
  env[:query] = parse_query_string(env["QUERY_STRING"])
  env[:path] = parse_uri(env["PATH_INFO"])
  resp = response(env)
  [200, {"Content-Type" => "text/plain"}, [resp]]
end

#initailize(env) ⇒ Object



9
10
11
# File 'lib/call_parser.rb', line 9

def initailize(env)
  @env = env
end

#parse_query_string(query_string) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/call_parser.rb', line 23

def parse_query_string(query_string)
  begin
    params = query_string.split('&').inject({}) {|h,(k,v)| h[k.split('=')[0].intern] = CGI.unescape(k.split('=')[1]); h}
  rescue NoMethodError
    $logger.debug("No Query String found for this request")
    params = Hash.new
  end
  return params
end

#parse_uri(request_path) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/call_parser.rb', line 13

def parse_uri(request_path)
  begin
    uri = (request_path.split("/").collect {|r| r.intern unless r.empty?}).compact
  rescue NoMethodError
    $logger.debug("No URI found for this request")
    uri = Hash.new
  end
  return uri
end