Class: NOMS::Command::UserAgent::Response::Typhoeus

Inherits:
NOMS::Command::UserAgent::Response show all
Defined in:
lib/noms/command/useragent/response/typhoeus.rb

Instance Attribute Summary

Attributes inherited from NOMS::Command::UserAgent::Response

#auth_hash, #cache_control, #date, #etag, #expires, #from_cache, #last_modified, #original_date

Attributes inherited from Base

#logger

Instance Method Summary collapse

Methods inherited from NOMS::Command::UserAgent::Response

#age, #cacheable?, #cacheable_copy, #cached!, #content_encoding, #current?, from_cache, #from_cache?, from_json, #get_expires, #get_header_time, #header_params, #to_cache, #to_hash, #to_json

Methods inherited from Base

#default_logger

Constructor Details

#initialize(httpresponse, opts = {}) ⇒ Typhoeus

Returns a new instance of Typhoeus.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/noms/command/useragent/response/typhoeus.rb', line 25

def initialize(httpresponse, opts={})
    super
    if @response.return_code != :ok
        raise NOMS::Command::Error.new "Client error[#{@response.return_code.inspect}]: #{@response.return_message}"
    end
    content_encoding = self.content_encoding || 'utf-8'
    @body = @response.body

    if @body

        begin
            @log.debug "Forcing body string encoding to #{content_encoding}"
            @body.force_encoding(content_encoding)
        rescue Encoding::UndefinedConversionError
            @log.debug "   (coercing 'binary' to '#{content_encoding}')"
            @body = @body.encode('utf8', 'binary', :undef => :replace, :invalid => :replace)
        end

    end
end

Instance Method Details

#bodyObject



46
47
48
# File 'lib/noms/command/useragent/response/typhoeus.rb', line 46

def body
    @body || @response.body
end

#content_typeObject



70
71
72
# File 'lib/noms/command/useragent/response/typhoeus.rb', line 70

def content_type
    @response.headers['Content-Type']
end

#header(hdr = nil) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/noms/command/useragent/response/typhoeus.rb', line 54

def header(hdr=nil)
    if hdr.nil?
        @response.headers
    else
        Hash[@response.headers.map { |h, v| [h.downcase, v] }][hdr.downcase]
    end
end

#statusObject



62
63
64
# File 'lib/noms/command/useragent/response/typhoeus.rb', line 62

def status
    @response.code.to_i
end

#statusTextObject



66
67
68
# File 'lib/noms/command/useragent/response/typhoeus.rb', line 66

def statusText
    @response.code.to_s + ' ' + @response.status_message
end

#success?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/noms/command/useragent/response/typhoeus.rb', line 50

def success?
    @response.success?
end