Class: EasyHTTP::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, response, default_charset = nil) ⇒ Response

Returns a new instance of Response.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/easy_http/response.rb', line 8

def initialize url, response, default_charset = nil
  default_charset = "ASCII-8BIT" unless default_charset
  @url = url

  @status = response.code.to_i
  @status_message = response.message

  @body = response.body
  @body = @body.encode default_charset if String.method_defined? :encode

  @headers = {}
  response.each_header { |k, v| @headers[k] = v}
  if response['Content-type'].nil?
    @charset =  default_charset
  else
    @charset = determine_charset(response['Content-type'], response.body) || default_charset
  end
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/easy_http/response.rb', line 6

def body
  @body
end

#charsetObject (readonly)

Returns the value of attribute charset.



6
7
8
# File 'lib/easy_http/response.rb', line 6

def charset
  @charset
end

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/easy_http/response.rb', line 6

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/easy_http/response.rb', line 6

def status
  @status
end

#status_messageObject (readonly)

Returns the value of attribute status_message.



6
7
8
# File 'lib/easy_http/response.rb', line 6

def status_message
  @status_message
end

#urlObject (readonly)

Returns the value of attribute url.



6
7
8
# File 'lib/easy_http/response.rb', line 6

def url
  @url
end

Instance Method Details

#inspectObject



27
28
29
# File 'lib/easy_http/response.rb', line 27

def inspect
  "#<EasyHTTP::Response @status_message='#{@status_message}'>"
end