Class: AutoSqlFormatter::Formatter
- Inherits:
-
Object
- Object
- AutoSqlFormatter::Formatter
- Defined in:
- lib/auto_sql_formatter/formatter.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- DEFAULT_INDENT =
2
- DEFAULT_CASE =
'upper'.freeze
- API_URI =
'https://sqlformat.org/api/v1/format'.freeze
- HEADERS =
{ 'Content-Type' => 'application/x-www-form-urlencoded' }.freeze
Class Method Summary collapse
Class Method Details
.do(sqls) ⇒ Object
13 14 15 |
# File 'lib/auto_sql_formatter/formatter.rb', line 13 def do(sqls) Array(sqls).map { |sql| { from: sql, to: format(sql) } } end |
.format(sql) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/auto_sql_formatter/formatter.rb', line 17 def format(sql) uri = URI(API_URI) https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true body = URI.encode_www_form(sql: sql, keyword_case: DEFAULT_CASE) '===Net::HTTP===' response = https.post(uri.path, body, HEADERS) JSON.parse(response.body)['result'] end |