Module: Qubole

Defined in:
lib/qubole.rb,
lib/qubole/cluster.rb,
lib/qubole/command.rb,
lib/qubole/version.rb,
lib/qubole/exceptions.rb,
lib/qubole/commands/pig.rb,
lib/qubole/commands/hive.rb,
lib/qubole/commands/shell.rb,
lib/qubole/commands/spark.rb,
lib/qubole/commands/hadoop.rb,
lib/qubole/commands/presto.rb,
lib/qubole/commands/composite.rb,
lib/qubole/commands/db_export.rb,
lib/qubole/commands/db_import.rb,
lib/qubole/commands/db_tap_query.rb

Defined Under Namespace

Modules: Commands Classes: Cluster, Command, HttpException

Constant Summary collapse

ACCESS_URL =
'https://api.qubole.com/api/'
API_VERSION =
'v1.2'
VERSION =
"0.0.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.api_tokenObject

Returns the value of attribute api_token



13
14
15
# File 'lib/qubole.rb', line 13

def api_token
  @api_token
end

.versionString

API version

Returns:

  • (String)

    API version used



19
20
21
# File 'lib/qubole.rb', line 19

def version
  @version
end

Class Method Details

.configure(params) ⇒ Object

Configure Qubole

Parameters:

  • params (Hash)

    configuration parameters

Options Hash (params):

  • :api_token (String)

    Qubole API token

  • :version (String)

    Qubole API version (v1.2 be default)



29
30
31
32
# File 'lib/qubole.rb', line 29

def configure(params)
  self.api_token = params[:api_token]
  self.version = params[:version]
end

.headersHash

Request headers

Returns:

  • (Hash)

    request headers



38
39
40
41
42
43
44
# File 'lib/qubole.rb', line 38

def headers
  {
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'X-AUTH-TOKEN' => @api_token
  }
end

.http(name, path, params) {|http, uri| ... } ⇒ Hash|Array

HTTP request to Qubole

Parameters:

  • path (String)

    API path

  • params (Hash)

    GET parameters

Yield Parameters:

  • http (Net::HTTP)

    HTTP connection

  • uri (URI)

    request URI

Returns:

  • (Hash|Array)

    parsed JSON response

Raises:



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/qubole.rb', line 54

def http(name, path, params)
  # Build URI
  uri = URI(ACCESS_URL + version)
  uri.path += path

  # Encode parameters for GET request
  if name == 'GET'
    uri.query = URI.encode_www_form(params)
  else
    # Stringify JSON for all other requests
    data = JSON.generate(params) unless params.empty?
  end

  # Open connection
  res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
    # Execute request
    http.send_request(name, uri, data, headers)
  end

  # Raise error message if not success
  raise HttpException.new(res) unless res.is_a? Net::HTTPSuccess
  # Parse JSON body
  JSON.parse(res.body) rescue res.body
end