class Databricks::Connector

Underlying connector making API calls

Public Class Methods

new(host, token) click to toggle source

Constructor

Parameters
  • host (String): Host to connect to

  • token (String): Token to be used in th API

# File lib/databricks/connector.rb, line 14
def initialize(host, token)
  @host = host
  @token = token
end

Public Instance Methods

get_json(api_path, json_payload = {}) click to toggle source

Issue a GET request to the API with JSON payload

Parameters
  • api_path (String): API path to query

  • json_payload (Object): JSON payload to include in the query [default = {}]

Result
  • Object: JSON result

# File lib/databricks/connector.rb, line 26
def get_json(api_path, json_payload = {})
  JSON.parse(
    RestClient::Request.execute(
      method: :get,
      url: "#{@host}/api/2.0/#{api_path}",
      payload: json_payload.to_json,
      headers: {
        Authorization: "Bearer #{@token}",
        'Content-Type': 'application/json'
      }
    ).body
  )
end
post(api_path, form_payload = {}) click to toggle source

Issue a POST request to the API with multipart form data payload

Parameters
  • api_path (String): API path to query

  • form_payload (Hash): Form payload to include in the query [default = {}]

# File lib/databricks/connector.rb, line 66
def post(api_path, form_payload = {})
  RestClient::Request.execute(
    method: :post,
    url: "#{@host}/api/2.0/#{api_path}",
    payload: form_payload.merge(multipart: true),
    headers: {
      Authorization: "Bearer #{@token}"
    }
  )
end
post_json(api_path, json_payload = {}) click to toggle source

Issue a POST request to the API with JSON payload

Parameters
  • api_path (String): API path to query

  • json_payload (Object): JSON payload to include in the query [default = {}]

Result
  • Object: JSON result

# File lib/databricks/connector.rb, line 47
def post_json(api_path, json_payload = {})
  JSON.parse(
    RestClient::Request.execute(
      method: :post,
      url: "#{@host}/api/2.0/#{api_path}",
      payload: json_payload.to_json,
      headers: {
        Authorization: "Bearer #{@token}",
        'Content-Type': 'application/json'
      }
    ).body
  )
end