class DNSDB::Clients::Client
Constants
- BASE_URL
- HOST
Public Class Methods
new(api_key)
click to toggle source
# File lib/dnsdb/clients/client.rb, line 13 def initialize(api_key) @api_key = api_key end
Private Instance Methods
_get(path, params, &block)
click to toggle source
# File lib/dnsdb/clients/client.rb, line 59 def _get(path, params, &block) uri = url_for(path) uri.query = URI.encode_www_form(params) request = Net::HTTP::Get.new(uri) request["Accept"] = "application/json" request["X-Api-Key"] = @api_key make_request(request, &block) end
build_request(type: "GET", path:, params: {})
click to toggle source
# File lib/dnsdb/clients/client.rb, line 57 def build_request(type: "GET", path:, params: {}); end
https_options()
click to toggle source
# File lib/dnsdb/clients/client.rb, line 23 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
make_request(req) { |json| ... }
click to toggle source
# File lib/dnsdb/clients/client.rb, line 37 def make_request(req) Net::HTTP.start(HOST, 443, https_options) do |http| response = http.request(req) code = response.code.to_i body = response.body case code when 200 json = body.lines.map do |line| JSON.parse line.chomp end yield json else error = body.chomp raise Error, "Unsupported response code returned: #{code} - #{error}" end end end
url_for(path)
click to toggle source
# File lib/dnsdb/clients/client.rb, line 19 def url_for(path) URI(BASE_URL + path) end