databricks 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c27151990dcc087e396f387f45f6909f54bb6eb8529b8835706ce84d3ac399ab
4
+ data.tar.gz: 0ddfaf4cd06981894bddc1ff2ede2bf2372aa6d08521699458502cdf4b83f308
5
+ SHA512:
6
+ metadata.gz: 747bf19db30cc24740b101aaacd14d22eeb7051995b7d1707917835a34fb90bc096304d2e11c18ea4c04c28049e5ead90961f1fcdb319642bbd54409feb580cf
7
+ data.tar.gz: dae0b046280172f770df37ce37440d0311f5e65896fe35209e3d0e900c4961d1a8396d195b570dac122c23b373aeb0be364f9c94178d54da888fab20dd81a819
@@ -0,0 +1,17 @@
1
+ require 'databricks/domains/root'
2
+ require 'databricks/resource'
3
+
4
+ module Databricks
5
+
6
+ # Get an API connector based on a Databricks URL and API token
7
+ #
8
+ # Parameters::
9
+ # * *host* (String): Host to connect to
10
+ # * *token* (String): Token to be used in th API
11
+ # Result::
12
+ # * Domains::Root: The root domain of the API
13
+ def self.api(host, token)
14
+ Domains::Root.new(Resource.new(host, token))
15
+ end
16
+
17
+ end
@@ -0,0 +1,47 @@
1
+ module Databricks
2
+
3
+ # Encapsulate a part of the API for better organization
4
+ class Domain
5
+
6
+ # Declare sub-domain accessors in the current domain.
7
+ # This will make sure the current domain has methods named after the sub-domain identifiers that will instantiate the corresponding domains at will.
8
+ #
9
+ # Parameters::
10
+ # * *domains* (Array<Symbol>): Domains to instantiate
11
+ def self.sub_domains(*domains)
12
+ domains.flatten.each do |domain|
13
+ self.define_method(domain) do
14
+ sub_domain(domain)
15
+ end
16
+ end
17
+ end
18
+
19
+ # Instantiate a sub-domain.
20
+ # Keep a cache of it.
21
+ #
22
+ # Parameters::
23
+ # * *domain* (Symbol): Sub-domain identifier.
24
+ # Result::
25
+ # * Domain: Corresponding sub-domain
26
+ def sub_domain(domain)
27
+ unless @sub_domains.key?(domain)
28
+ require "#{__dir__}/domains/#{domain}.rb"
29
+ @sub_domains[domain] = Domains.const_get(domain.to_s.split('_').collect(&:capitalize).join.to_sym).new(@resource)
30
+ end
31
+ @sub_domains[domain]
32
+ end
33
+
34
+ # Constructor
35
+ #
36
+ # Parameters::
37
+ # * *resource* (Resource): Resource handling API calls
38
+ def initialize(resource)
39
+ @resource = resource
40
+ # Keep a map of sub-domains instantiated, per domain identifier.
41
+ # Hash< Symbol, Domain >
42
+ @sub_domains = {}
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -0,0 +1,46 @@
1
+ require 'databricks/domain'
2
+
3
+ module Databricks
4
+
5
+ module Domains
6
+
7
+ # Provide the DBFS API
8
+ # cf. https://docs.databricks.com/dev-tools/api/latest/dbfs.html
9
+ class Dbfs < Domain
10
+
11
+ # List a path
12
+ #
13
+ # Parameters::
14
+ # * *path* (String): Path to be listed
15
+ # Result::
16
+ # * Array<String>: List of DBFS paths
17
+ def list(path)
18
+ @resource.get_json(
19
+ 'dbfs/list',
20
+ {
21
+ path: path
22
+ }
23
+ )['files'].map { |file_info| file_info['path'] }
24
+ end
25
+
26
+ # Put a new file
27
+ #
28
+ # Parameters::
29
+ # * *path* (String): Path to the file to create
30
+ # * *local_file* (String): Path to the local file to put
31
+ def put(path, local_file)
32
+ @resource.post(
33
+ 'dbfs/put',
34
+ {
35
+ path: path,
36
+ contents: File.new(local_file, 'rb'),
37
+ overwrite: true
38
+ }
39
+ )
40
+ end
41
+
42
+ end
43
+
44
+ end
45
+
46
+ end
@@ -0,0 +1,31 @@
1
+ require 'databricks/domain'
2
+
3
+ module Databricks
4
+
5
+ module Domains
6
+
7
+ # Provide the Jobs API
8
+ # cf. https://docs.databricks.com/dev-tools/api/latest/jobs.html
9
+ class Jobs < Domain
10
+
11
+ # List a path
12
+ #
13
+ # Result::
14
+ # * Array<Hash>: List of jobs information
15
+ def list
16
+ @resource.get_json('jobs/list')['jobs']
17
+ end
18
+
19
+ # Create a new job
20
+ #
21
+ # Parameters::
22
+ # * *settings* (Hash<Symbol,Object>): Settings to create the job
23
+ def create(**settings)
24
+ @resource.post_json('jobs/create', settings)
25
+ end
26
+
27
+ end
28
+
29
+ end
30
+
31
+ end
@@ -0,0 +1,20 @@
1
+ require 'databricks/domain'
2
+
3
+ module Databricks
4
+
5
+ module Domains
6
+
7
+ # API entry point
8
+ # cf. https://docs.databricks.com/dev-tools/api/latest/index.html
9
+ class Root < Domain
10
+
11
+ sub_domains %i[
12
+ dbfs
13
+ jobs
14
+ ]
15
+
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,79 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+
4
+ module Databricks
5
+
6
+ # Underlying resource making API calls
7
+ class Resource
8
+
9
+ # Constructor
10
+ #
11
+ # Parameters::
12
+ # * *host* (String): Host to connect to
13
+ # * *token* (String): Token to be used in th API
14
+ def initialize(host, token)
15
+ @host = host
16
+ @token = token
17
+ end
18
+
19
+ # Issue a GET request to the API with JSON payload
20
+ #
21
+ # Parameters::
22
+ # * *api_path* (String): API path to query
23
+ # * *json_payload* (Object): JSON payload to include in the query [default = {}]
24
+ # Result::
25
+ # * Object: JSON result
26
+ def get_json(api_path, json_payload = {})
27
+ JSON.parse(
28
+ RestClient::Request.execute(
29
+ method: :get,
30
+ url: "#{@host}/api/2.0/#{api_path}",
31
+ payload: json_payload.to_json,
32
+ headers: {
33
+ Authorization: "Bearer #{@token}",
34
+ 'Content-Type': 'application/json'
35
+ }
36
+ ).body
37
+ )
38
+ end
39
+
40
+ # Issue a POST request to the API with JSON payload
41
+ #
42
+ # Parameters::
43
+ # * *api_path* (String): API path to query
44
+ # * *json_payload* (Object): JSON payload to include in the query [default = {}]
45
+ # Result::
46
+ # * Object: JSON result
47
+ def post_json(api_path, json_payload = {})
48
+ JSON.parse(
49
+ RestClient::Request.execute(
50
+ method: :post,
51
+ url: "#{@host}/api/2.0/#{api_path}",
52
+ payload: json_payload.to_json,
53
+ headers: {
54
+ Authorization: "Bearer #{@token}",
55
+ 'Content-Type': 'application/json'
56
+ }
57
+ ).body
58
+ )
59
+ end
60
+
61
+ # Issue a POST request to the API with multipart form data payload
62
+ #
63
+ # Parameters::
64
+ # * *api_path* (String): API path to query
65
+ # * *form_payload* (Hash): Form payload to include in the query [default = {}]
66
+ def post(api_path, form_payload = {})
67
+ RestClient::Request.execute(
68
+ method: :post,
69
+ url: "#{@host}/api/2.0/#{api_path}",
70
+ payload: form_payload.merge(multipart: true),
71
+ headers: {
72
+ Authorization: "Bearer #{@token}"
73
+ }
74
+ )
75
+ end
76
+
77
+ end
78
+
79
+ end
@@ -0,0 +1,5 @@
1
+ module Databricks
2
+
3
+ VERSION = '1.0.0'
4
+
5
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: databricks
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Muriel Salvan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sem_ver_components
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.0'
69
+ description: Access the Databricks API using the simple Ruby way
70
+ email:
71
+ - muriel@x-aeon.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/databricks.rb
77
+ - lib/databricks/domain.rb
78
+ - lib/databricks/domains/dbfs.rb
79
+ - lib/databricks/domains/jobs.rb
80
+ - lib/databricks/domains/root.rb
81
+ - lib/databricks/resource.rb
82
+ - lib/databricks/version.rb
83
+ homepage: https://github.com/Muriel-Salvan/databricks
84
+ licenses:
85
+ - BSD-3-Clause
86
+ metadata: {}
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ required_rubygems_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: '0'
101
+ requirements: []
102
+ rubygems_version: 3.2.3
103
+ signing_key:
104
+ specification_version: 4
105
+ summary: Rubygem wrapping the Databricks REST API
106
+ test_files: []