lib/miteru/http_client.rb in miteru-0.12.10 vs lib/miteru/http_client.rb in miteru-0.12.11
- old
+ new
@@ -9,10 +9,11 @@
class HTTPClient
DEFAULT_UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36"
URLSCAN_UA = "miteru/#{Miteru::VERSION}"
attr_reader :ssl_context
+
def initialize
ctx = OpenSSL::SSL::SSLContext.new
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE
@ssl_context = ctx
end
@@ -21,32 +22,34 @@
down = Down::Http.new(default_options) { |client| client.headers(default_headers) }
down.download(url, destination: destination)
destination
end
- def self.download(url, base_dir = "/tmp")
- new.download(url, base_dir)
- end
-
def get(url, options = {})
options = options.merge default_options
HTTP.follow
.timeout(write: 2, connect: 5, read: 10)
.headers(urlscan_url?(url) ? urlscan_headers : default_headers)
.get(url, options)
end
- def self.get(url, options = {})
- new.get url, options
- end
-
def post(url, options = {})
HTTP.post url, options
end
- def self.post(url, options = {})
- new.post url, options
+ class << self
+ def download(url, base_dir = "/tmp")
+ new.download(url, base_dir)
+ end
+
+ def get(url, options = {})
+ new.get url, options
+ end
+
+ def post(url, options = {})
+ new.post url, options
+ end
end
private
def default_headers