Class: Databricks::Connector
- Inherits:
-
Object
- Object
- Databricks::Connector
- Defined in:
- lib/databricks/connector.rb
Overview
Underlying connector making API calls
Instance Method Summary collapse
-
#get_json(api_path, json_payload = {}) ⇒ Object
Issue a GET request to the API with JSON payload.
-
#initialize(host, token) ⇒ Connector
constructor
Constructor.
-
#post(api_path, form_payload = {}) ⇒ Object
Issue a POST request to the API with multipart form data payload.
-
#post_json(api_path, json_payload = {}) ⇒ Object
Issue a POST request to the API with JSON payload.
Constructor Details
#initialize(host, token) ⇒ Connector
Constructor
- Parameters
-
host (String): Host to connect to
-
token (String): Token to be used in th API
14 15 16 17 |
# File 'lib/databricks/connector.rb', line 14 def initialize(host, token) @host = host @token = token end |
Instance Method Details
#get_json(api_path, json_payload = {}) ⇒ Object
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
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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 = {}) ⇒ Object
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 = {}]
66 67 68 69 70 71 72 73 74 75 |
# 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 = {}) ⇒ Object
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
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 |