Class: Webclient::Response

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

Overview

nested class - wrap Net::HTTP::Response

Defined Under Namespace

Classes: Headers, Status

Instance Method Summary collapse

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

#headersObject



35
# File 'lib/webclient/webclient.rb', line 35

def headers() @headers ||= Headers.new( @response ); end

#jsonObject

convenience helper; returns parsed json data



21
# File 'lib/webclient/webclient.rb', line 21

def json() JSON.parse( text ); end

#rawObject



8
# File 'lib/webclient/webclient.rb', line 8

def raw() @response; end

#statusObject



46
# File 'lib/webclient/webclient.rb', line 46

def status() @status ||= Status.new( @response ); end

#textObject



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