class Ahiru::API

Constants

DUCKDUCKGO_ENDPOINT

Public Class Methods

Public Instance Methods

Private Instance Methods

get_body(url, params) click to toggle source
# File lib/ahiru/api.rb, line 40
def get_body(url, params)
  res = http.get(url, params: params)
  return nil unless res.code == 200

  res.body.to_s
rescue HTTP::Error, OpenSSL::SSL::SSLError, Addressable::URI::InvalidURIError => _
  nil
end
http() click to toggle source
# File lib/ahiru/api.rb, line 36
def http
  proxy? ? HTTP.via(proxy.host, proxy.port) : HTTP
end
proxy() click to toggle source
# File lib/ahiru/api.rb, line 29
def proxy
  @proxy ||= [].tap do |out|
    https_proxy = ENV["https_proxy"] || ENV["HTTPS_PROXY"]
    out << URI(https_proxy) if https_proxy
  end.first
end
proxy?() click to toggle source
# File lib/ahiru/api.rb, line 25
def proxy?
  proxy != nil
end