Class: WebSpeak::ResponseAccessor

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

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ResponseAccessor

Returns a new instance of ResponseAccessor.



3
4
5
# File 'lib/webspeak/response_accessor.rb', line 3

def initialize(response)
  @response = response
end

Instance Method Details

#bodyObject



34
35
36
# File 'lib/webspeak/response_accessor.rb', line 34

def body
  @response.body
end

#cookiesObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/webspeak/response_accessor.rb', line 19

def cookies
  res = ""
  @response.get_fields('set-cookie').each do |full_cookie|
    elems = full_cookie.split(";")
    cookie = elems.shift # the rest of the elements are expiry, domain, path, ...
    name, value = cookie.split("=", 2)
    res << "#{name.strip} => #{value.strip}\n"
    elems.each do |attr|
      name, value = attr.split("=", 2)
      res << "  #{name.strip}: #{value.strip}\n"
    end
  end
  res
end

#headersObject



11
12
13
14
15
16
17
# File 'lib/webspeak/response_accessor.rb', line 11

def headers
  res = ""
  @response.each_header do |name, values|
    values.each {|val| res << "#{name} => #{val}\n"} unless name == 'set-cookie'
  end
  res
end

#http_responseObject



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

def http_response
  @response
end