class Crtsh::API
Constants
- BASE_URL
- HOST
Public Instance Methods
search(identity, match: nil, exclude: nil)
click to toggle source
Search crt.sh by a given identity
@param [String] identity @param [String, nil] match “=”, “ILIKE”, “LIKE”, “single”, “any” or nil @param [String, nil] exclude “expired” or nil
@return [Hash]
# File lib/crtsh/api.rb, line 21 def search(identity, match: nil, exclude: nil) params = { identity: identity, match: match, exclude: exclude, output: "json", }.compact get("/", params) { |json| json } end
Private Instance Methods
get(path, params = {}, &block)
click to toggle source
# File lib/crtsh/api.rb, line 64 def get(path, params = {}, &block) uri = url_for(path) uri.query = URI.encode_www_form(params) get = Net::HTTP::Get.new(uri) request(get, &block) end
https_options()
click to toggle source
# File lib/crtsh/api.rb, line 33 def https_options if proxy = ENV["HTTPS_PROXY"] || ENV["https_proxy"] uri = URI(proxy) { proxy_address: uri.hostname, proxy_port: uri.port, proxy_from_env: false, use_ssl: true } else { use_ssl: true } end end
request(req) { |parse| ... }
click to toggle source
# File lib/crtsh/api.rb, line 47 def request(req) Net::HTTP.start(HOST, 443, https_options) do |http| response = http.request(req) case response.code when "200" yield JSON.parse(response.body) else raise(Error, "Unsupported response code returned: #{response.code}") end end end
url_for(path)
click to toggle source
# File lib/crtsh/api.rb, line 60 def url_for(path) URI(BASE_URL + path) end