class Ahiru::API
Constants
- DUCKDUCKGO_ENDPOINT
Public Class Methods
search(params)
click to toggle source
# File lib/ahiru/api.rb, line 19 def self.search(params) new.search(params) end
Public Instance Methods
search(q:, s: nil, dc: nil)
click to toggle source
# File lib/ahiru/api.rb, line 11 def search(q:, s: nil, dc: nil) params = { q: q, s: s, dc: dc }.compact body = get_body(DUCKDUCKGO_ENDPOINT, params) return nil if body.nil? Page.new body end
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