danbooru::http: parse html responses.

This commit is contained in:
evazion
2020-06-20 16:45:50 -05:00
parent f730951e7f
commit a929f3134e
4 changed files with 40 additions and 0 deletions

View File

@@ -1,3 +1,6 @@
require "danbooru/http/html_adapter"
require "danbooru/http/xml_adapter"
module Danbooru
class Http
class DownloadError < StandardError; end

View File

@@ -0,0 +1,12 @@
module Danbooru
class Http
class HtmlAdapter < HTTP::MimeType::Adapter
HTTP::MimeType.register_adapter "text/html", self
HTTP::MimeType.register_alias "text/html", :html
def decode(str)
Nokogiri::HTML5(str)
end
end
end
end

View File

@@ -0,0 +1,12 @@
module Danbooru
class Http
class XmlAdapter < HTTP::MimeType::Adapter
HTTP::MimeType.register_adapter "application/xml", self
HTTP::MimeType.register_alias "application/xml", :xml
def decode(str)
Hash.from_xml(str).with_indifferent_access
end
end
end
end