#!/usr/bin/ruby
# encoding=utf-8
require "json"
require "open-uri"
require 'net/https'
sql = $stdin.read()
params = {'sql': sql, 'reindent': 1,
'keyword_case': 'upper', 'identifier_case': 'lower'}
url = 'https://sqlformat.org/api/v1/format'
uri = URI(url)
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == "https"
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
req = Net::HTTP::Post.new(uri.path)
req.set_form_data(params)
res = http.request(req)
json_body = JSON.parse res.body
puts json_body['result']