Module: Presto::Client

Defined in:
lib/presto/client/query.rb,
lib/presto/client.rb,
lib/presto/client/client.rb,
lib/presto/client/errors.rb,
lib/presto/client/models.rb,
lib/presto/client/version.rb,
lib/presto/client/faraday_client.rb,
lib/presto/client/statement_client.rb

Overview

Presto client for Ruby

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Defined Under Namespace

Modules: ModelVersions, PrestoHeaders Classes: Client, PrestoClientError, PrestoError, PrestoHttpError, PrestoQueryError, PrestoQueryTimeoutError, Query, StatementClient

Constant Summary collapse

Models =
ModelVersions::V316
VERSION =
"0.6.6"
HEADERS =
{
  "User-Agent" => "presto-ruby/#{VERSION}",
}
HTTP11_SEPARATOR =
["(", ")", "<", ">", "@", ",", ";", ":", "\\", "<", ">", "/", "[", "]", "?", "=", "{", "}", " ", "\v"]
HTTP11_TOKEN_CHARSET =
(32..126).map {|x| x.chr } - HTTP11_SEPARATOR
HTTP11_TOKEN_REGEXP =
/^[#{Regexp.escape(HTTP11_TOKEN_CHARSET.join)}]+\z/
HTTP11_CTL_CHARSET =
(0..31).map {|x| x.chr } + [127.chr]
HTTP11_CTL_CHARSET_REGEXP =
/[#{Regexp.escape(HTTP11_CTL_CHARSET.join)}]/

Class Method Summary collapse

Class Method Details

.faraday_client(options) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/presto/client/faraday_client.rb', line 41

def self.faraday_client(options)
  server = options[:server]
  unless server
    raise ArgumentError, ":server option is required"
  end

  ssl = faraday_ssl_options(options)

  if options[:password] && !ssl
    raise ArgumentError, "Protocol must be https when passing a password"
  end

  url = "#{ssl ? "https" : "http"}://#{server}"
  proxy = options[:http_proxy] || options[:proxy]  # :proxy is obsoleted

  faraday_options = {url: url, proxy: "#{proxy}"}
  faraday_options[:ssl] = ssl if ssl

  faraday = Faraday.new(faraday_options) do |faraday|
    if options[:user] && options[:password]
      faraday.basic_auth(options[:user], options[:password])
    end
    if options[:follow_redirect]
      faraday.use FaradayMiddleware::FollowRedirects
    end
    if options[:gzip]
      faraday.use FaradayMiddleware::Gzip
    end
    faraday.response :logger if options[:http_debug]
    faraday.adapter Faraday.default_adapter
  end

  faraday.headers.merge!(HEADERS)
  faraday.headers.merge!(optional_headers(options))

  return faraday
end

.new(*args) ⇒ Object



75
76
77
# File 'lib/presto/client/client.rb', line 75

def self.new(*args)
  Client.new(*args)
end