Sha256: 03727a3c5b4abb789bd6cfad25bff94f92a7eff3742868272221a3eb3cff5a84
Contents?: true
Size: 783 Bytes
Versions: 1
Compression:
Stored size: 783 Bytes
Contents
require "json" require "net/http" require "drill/version" class Drill class Error < StandardError; end def initialize(url: nil) url ||= ENV["DRILL_URL"] || "http://localhost:8047" @uri = URI.parse("#{url}/query.json") @http = Net::HTTP.new(@uri.host, @uri.port) end def query(statement) header = {"Content-Type" => "application/json", "Accept" => "application/json"} data = { queryType: "sql", query: statement } begin response = @http.post(@uri.request_uri, data.to_json, header) rescue Errno::ECONNREFUSED => e raise Drill::Error, e.message end body = JSON.parse(response.body) if body["errorMessage"] raise Drill::Error, body["errorMessage"].split("\n")[0] end body["rows"] end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
drill-sergeant-0.1.0 | lib/drill.rb |