Class: NOMS::Command::UserAgent::Response::Typhoeus
Instance Attribute Summary
#auth_hash, #cache_control, #date, #etag, #expires, #from_cache, #last_modified, #original_date
Attributes inherited from Base
#logger
Instance Method Summary
collapse
#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
#body ⇒ Object
46
47
48
|
# File 'lib/noms/command/useragent/response/typhoeus.rb', line 46
def body
@body || @response.body
end
|
#content_type ⇒ Object
70
71
72
|
# File 'lib/noms/command/useragent/response/typhoeus.rb', line 70
def content_type
@response.['Content-Type']
end
|
54
55
56
57
58
59
60
|
# File 'lib/noms/command/useragent/response/typhoeus.rb', line 54
def (hdr=nil)
if hdr.nil?
@response.
else
Hash[@response..map { |h, v| [h.downcase, v] }][hdr.downcase]
end
end
|
#status ⇒ Object
62
63
64
|
# File 'lib/noms/command/useragent/response/typhoeus.rb', line 62
def status
@response.code.to_i
end
|
#statusText ⇒ Object
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
50
51
52
|
# File 'lib/noms/command/useragent/response/typhoeus.rb', line 50
def success?
@response.success?
end
|