Class: Helpers::RequestEcho

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

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ RequestEcho

Returns a new instance of RequestEcho.



3
4
5
# File 'lib/helpers/request_echo.rb', line 3

def initialize(request)
  @request = request
end

Instance Method Details

#response_as(format) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/helpers/request_echo.rb', line 7

def response_as(format)
  content_type = case format
  when :json, :plist
    "application/#{format.to_s.downcase}"
  else
    "text/plain"
  end
  [200, {"Content-Type" => content_type}, to_s(format)]
end

#to_hashObject



28
29
30
31
32
33
34
# File 'lib/helpers/request_echo.rb', line 28

def to_hash
  {"echo" => {
    "params" => @request.params,
    "env"    => env_without_rack_and_async_env,
    "body"   => @request.body.read
  }}
end

#to_s(format) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/helpers/request_echo.rb', line 17

def to_s(format)
  case format
    when :json
      to_hash.to_json
    when :plist
      to_hash.to_plist
    when :text
      to_hash.inspect
  end
end