Class: EasyHTTP::Response
- Inherits:
-
Object
- Object
- EasyHTTP::Response
- Defined in:
- lib/easy_http/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Response body.
-
#charset ⇒ Object
readonly
Response charset.
-
#headers ⇒ Object
readonly
Parsed response headers.
-
#status ⇒ Object
readonly
Response status code.
-
#status_message ⇒ Object
readonly
Response status text.
-
#url ⇒ Object
readonly
Requested URL.
Instance Method Summary collapse
-
#initialize(url, response, default_charset = nil) ⇒ Response
constructor
A new instance of Response.
- #inspect ⇒ Object
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. 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
#body ⇒ Object (readonly)
Response body
13 14 15 |
# File 'lib/easy_http/response.rb', line 13 def body @body end |
#charset ⇒ Object (readonly)
Response charset
17 18 19 |
# File 'lib/easy_http/response.rb', line 17 def charset @charset end |
#headers ⇒ Object (readonly)
Parsed response headers
15 16 17 |
# File 'lib/easy_http/response.rb', line 15 def headers @headers end |
#status ⇒ Object (readonly)
Response status code
9 10 11 |
# File 'lib/easy_http/response.rb', line 9 def status @status end |
#status_message ⇒ Object (readonly)
Response status text
11 12 13 |
# File 'lib/easy_http/response.rb', line 11 def @status_message end |
#url ⇒ Object (readonly)
Requested URL
7 8 9 |
# File 'lib/easy_http/response.rb', line 7 def url @url end |
Instance Method Details
#inspect ⇒ Object
40 41 42 |
# File 'lib/easy_http/response.rb', line 40 def inspect "#<EasyHTTP::Response @status_message='#{@status_message}'>" end |