Sha256: aa15400d90b3c940852463b49bc1884c189b861781dcd1aabfda89c1b6afc8a1
Contents?: true
Size: 1.39 KB
Versions: 11
Compression:
Stored size: 1.39 KB
Contents
module HttpUtilities module Http class Response include HttpUtilities::Http::Format include HttpUtilities::Http::Logger attr_accessor :body, :parsed_body, :page, :format, :request, :force_encoding def initialize(body = nil, request = nil, options = {}) options = options.clone() self.body = body self.request = request self.parsed_body = nil self.format = options.delete(:format) { |e| nil } self.force_encoding = options.delete(:force_encoding) { |e| true } encode if (self.force_encoding) parse_response end def encode if (self.body) begin self.body = self.body.force_encoding('UTF-8').encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "") rescue Exception => e log(:error, "[HttpUtilities::Http::Format] - Failed to convert response with String#encode. Error: #{e.class.name}. Message: #{e.message}.") end end end def parse_response self.send("as_#{self.format}".to_sym) if (self.body && self.format) end def set_page(page) self.page = page if (page && page.parser) self.body = page.parser.content self.parsed_body = page.parser end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems