Class: Webclient::Response
- Inherits:
-
Object
- Object
- Webclient::Response
- Defined in:
- lib/webclient/webclient.rb
Overview
nested class - wrap Net::HTTP::Response
Defined Under Namespace
Instance Method Summary collapse
- #headers ⇒ Object
-
#initialize(response) ⇒ Response
constructor
A new instance of Response.
-
#json ⇒ Object
convenience helper; returns parsed json data.
- #raw ⇒ Object
- #status ⇒ Object
- #text ⇒ Object
Constructor Details
#initialize(response) ⇒ Response
Returns a new instance of Response.
5 6 7 |
# File 'lib/webclient/webclient.rb', line 5 def initialize( response ) @response = response end |
Instance Method Details
#headers ⇒ Object
35 |
# File 'lib/webclient/webclient.rb', line 35 def headers() @headers ||= Headers.new( @response ); end |
#json ⇒ Object
convenience helper; returns parsed json data
21 |
# File 'lib/webclient/webclient.rb', line 21 def json() JSON.parse( text ); end |
#raw ⇒ Object
8 |
# File 'lib/webclient/webclient.rb', line 8 def raw() @response; end |
#status ⇒ Object
46 |
# File 'lib/webclient/webclient.rb', line 46 def status() @status ||= Status.new( @response ); end |
#text ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/webclient/webclient.rb', line 11 def text # note: Net::HTTP will NOT set encoding UTF-8 etc. # will be set to ASCII-8BIT == BINARY == Encoding Unknown; Raw Bytes Here # thus, set/force encoding to utf-8 text = @response.body.to_s text = text.force_encoding( Encoding::UTF_8 ) text end |