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.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/easy_http/response.rb', line 19

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
  if response["content-type"]
    @charset = determine_charset(response['content-type'], response.body) || default_charset
  end
  @charset = default_charset if @charset.nil?
  @body = response.body

  if response["content-type"] && response["content-type"][0, 5] == "text/"
    convert_to_default_encoding! @body
  end

  @headers = {}
  response.each_header { |k, v| @headers[k] = v }

  self
end

Instance Attribute Details

#bodyObject (readonly)

Response body



13
14
15
# File 'lib/easy_http/response.rb', line 13

def body
  @body
end

#charsetObject (readonly)

Response charset



17
18
19
# File 'lib/easy_http/response.rb', line 17

def charset
  @charset
end

#headersObject (readonly)

Parsed response headers



15
16
17
# File 'lib/easy_http/response.rb', line 15

def headers
  @headers
end

#statusObject (readonly)

Response status code



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

def status
  @status
end

#status_messageObject (readonly)

Response status text



11
12
13
# File 'lib/easy_http/response.rb', line 11

def status_message
  @status_message
end

#urlObject (readonly)

Requested URL



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

def url
  @url
end

Instance Method Details

#inspectObject



40
41
42
# File 'lib/easy_http/response.rb', line 40

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