class Robtex::API

Constants

HOST
URL

Public Instance Methods

as(q) click to toggle source
# File lib/robtex/api.rb, line 9
def as(q)
  get("/asquery/#{q}") { |body| JSON.parse body }
end
fpdns(q) click to toggle source
# File lib/robtex/api.rb, line 23
def fpdns(q)
  get("/pdns/forward/#{q}") do |body|
    body.lines.map { |line| JSON.parse line }
  end
end
get(path, &block) click to toggle source
# File lib/robtex/api.rb, line 64
def get(path, &block)
  get = Net::HTTP::Get.new(url_for(path))
  request(get, &block)
end
https_options() click to toggle source
# File lib/robtex/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
ip(q) click to toggle source
# File lib/robtex/api.rb, line 13
def ip(q)
  get("/ipquery/#{q}") { |body| JSON.parse body }
end
request(req) { |body| ... } click to toggle source
# File lib/robtex/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' then yield response.body
    when '400' then raise ProcessingError, response.body
    when '401' then raise AuthenticationError, response.body
    when '404' then raise NotFound, response.body
    when '429' then raise RateLimited, response.body
    when '500' then raise InternalServerError, response.body
    else
      raise ResponseError, response.body
    end
  end
end
rpdns(q) click to toggle source
# File lib/robtex/api.rb, line 17
def rpdns(q)
  get("/pdns/reverse/#{q}") do |body|
    body.lines.map { |line| JSON.parse line }
  end
end
url_for(path) click to toggle source
# File lib/robtex/api.rb, line 29
def url_for(path)
  URI(URL + path)
end