azure-kusto-ruby 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/kusto/rest/context/context.rb +42 -0
- data/lib/kusto/rest/context/management_context.rb +18 -0
- data/lib/kusto/rest/context/query_context.rb +18 -0
- data/lib/kusto/rest/context.rb +4 -0
- data/lib/kusto/rest/query/data.rb +26 -0
- data/lib/kusto/rest/query/query.rb +37 -0
- data/lib/kusto/rest/query.rb +4 -0
- data/lib/kusto/rest/result/data_frame.rb +34 -0
- data/lib/kusto/rest/result/data_set.rb +61 -0
- data/lib/kusto/rest/result/data_set_completion.rb +17 -0
- data/lib/kusto/rest/result/data_set_header.rb +25 -0
- data/lib/kusto/rest/result/data_table.rb +19 -0
- data/lib/kusto/rest/result.rb +7 -0
- data/lib/kusto/rest.rb +9 -0
- data/lib/version.rb +9 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 825e171c28ef4a5b0f5a133cbffa427623e5e28a71519eda8d523f373ed76c58
|
4
|
+
data.tar.gz: 415378a81832dc2369b495da8302f85b1bb1b941704fe72df18020e2f56ae84c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e1fd7e66bea05a43e7ed11db5c83aed4e742cc16aa8e9cee9c4f99cd39e79e1a9203fe266ee65f9ac77c143a2738e35145b1f299805308f28f8611384c94f226
|
7
|
+
data.tar.gz: f0abd0dbf4138e2bd681738b094b2a2e869243dfc8aaf8da47ad980de05e1eca6be8d1fd6a91bbb765f58c8b7f7a39e0586c418c02c596b349579da98e5c453d
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
require_relative "../result/data_set"
|
5
|
+
|
6
|
+
module Kusto
|
7
|
+
module Rest
|
8
|
+
class Context
|
9
|
+
attr_reader :path
|
10
|
+
|
11
|
+
class Error < StandardError; end
|
12
|
+
|
13
|
+
def initialize(url:, token:)
|
14
|
+
@url = url
|
15
|
+
@token = token
|
16
|
+
@connector = Faraday.new(url:)
|
17
|
+
end
|
18
|
+
|
19
|
+
def post(query)
|
20
|
+
response = @connector.post(@path) do |req|
|
21
|
+
req.headers["Content-Type"] = "application/json"
|
22
|
+
req.headers["Authorization"] = "Bearer #{@token}"
|
23
|
+
req.body = query.request_body.to_json
|
24
|
+
end
|
25
|
+
|
26
|
+
unless response.success?
|
27
|
+
raise Error, "Request failed with status #{response.status} - #{response.reason_phrase} #{response.body}"
|
28
|
+
end
|
29
|
+
|
30
|
+
if response.body.empty? || response.body.nil?
|
31
|
+
raise Error, "Request with status #{response.status} returned an empty response body"
|
32
|
+
end
|
33
|
+
|
34
|
+
Kusto::Rest::DataSet.new(response.body)
|
35
|
+
end
|
36
|
+
|
37
|
+
def endpoint
|
38
|
+
@connector.url_prefix.to_s + @path
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "context"
|
4
|
+
|
5
|
+
module Kusto
|
6
|
+
module Rest
|
7
|
+
class ManagementContext < Context
|
8
|
+
attr_reader :path
|
9
|
+
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
def initialize(url:, token:)
|
13
|
+
super(url:, token:)
|
14
|
+
@path = "v1/rest/mgmt"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "context"
|
4
|
+
|
5
|
+
module Kusto
|
6
|
+
module Rest
|
7
|
+
class QueryContext < Context
|
8
|
+
attr_reader :path
|
9
|
+
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
def initialize(url:, token:)
|
13
|
+
super(url:, token:)
|
14
|
+
@path = "v2/rest/query"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "securerandom"
|
4
|
+
require_relative "query"
|
5
|
+
|
6
|
+
module Kusto
|
7
|
+
module Rest
|
8
|
+
class DataQuery < Query
|
9
|
+
def initialize(db:, statement:, parameters: {}, options: {}, request_id: nil)
|
10
|
+
default_options = { "results_progressive_enabled": false }
|
11
|
+
@options = default_options.merge!(options)
|
12
|
+
@parameters = parameters
|
13
|
+
@db = db
|
14
|
+
super(statement:, request_id:)
|
15
|
+
end
|
16
|
+
|
17
|
+
def request_body
|
18
|
+
@request_body ||= {
|
19
|
+
db: @db,
|
20
|
+
properties:,
|
21
|
+
csl: @statement
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "securerandom"
|
4
|
+
|
5
|
+
module Kusto
|
6
|
+
module Rest
|
7
|
+
class Query
|
8
|
+
def initialize(statement:, options: {}, parameters: {}, request_id: nil)
|
9
|
+
@options = options
|
10
|
+
@parameters = parameters
|
11
|
+
@request_id = request_id || get_request_id
|
12
|
+
@statement = statement
|
13
|
+
end
|
14
|
+
|
15
|
+
def properties
|
16
|
+
@properties ||= {
|
17
|
+
"Options": @options,
|
18
|
+
"Parameters": @parameters,
|
19
|
+
"ClientRequestId": @request_id
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def request_body
|
24
|
+
@request_body ||= {
|
25
|
+
properties:,
|
26
|
+
csl: @statement
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def get_request_id
|
33
|
+
@request_id ||= "#{self.class.name}::#{SecureRandom.uuid}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "date"
|
4
|
+
|
5
|
+
module Kusto
|
6
|
+
module Rest
|
7
|
+
class DataFrame
|
8
|
+
def initialize(data)
|
9
|
+
@data = data
|
10
|
+
end
|
11
|
+
|
12
|
+
def type
|
13
|
+
@data["FrameType"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def kind
|
17
|
+
@data["TableKind"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def name
|
21
|
+
@data["TableName"]
|
22
|
+
end
|
23
|
+
|
24
|
+
def cast(value, type)
|
25
|
+
case type
|
26
|
+
when "datetime"
|
27
|
+
value ? DateTime.parse(value) : nil
|
28
|
+
else
|
29
|
+
value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require_relative "data_set_completion"
|
5
|
+
require_relative "data_set_header"
|
6
|
+
require_relative "data_table"
|
7
|
+
|
8
|
+
module Kusto
|
9
|
+
module Rest
|
10
|
+
class DataSet
|
11
|
+
attr_reader :data
|
12
|
+
|
13
|
+
def initialize(response)
|
14
|
+
@data = JSON.parse(response)
|
15
|
+
end
|
16
|
+
|
17
|
+
def rows
|
18
|
+
primary_result.rows
|
19
|
+
end
|
20
|
+
|
21
|
+
def primary_result
|
22
|
+
@primary_result ||= frames.find_all do |frame|
|
23
|
+
frame.type == "DataTable" &&
|
24
|
+
frame.kind == "PrimaryResult" &&
|
25
|
+
frame.name == "PrimaryResult"
|
26
|
+
end.first
|
27
|
+
end
|
28
|
+
|
29
|
+
def header
|
30
|
+
@header ||= frames.find_all { |frame| frame.type == "DataSetHeader" }.first
|
31
|
+
end
|
32
|
+
|
33
|
+
def completion
|
34
|
+
@completion ||= frames.find_all do |frame|
|
35
|
+
frame.type == "DataSetCompletion"
|
36
|
+
end.first
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.parse_frame(frame)
|
40
|
+
case frame["FrameType"]
|
41
|
+
when "DataSetHeader"
|
42
|
+
Kusto::Rest::DataSetHeader.new(frame)
|
43
|
+
when "DataTable"
|
44
|
+
Kusto::Rest::DataTable.new(frame)
|
45
|
+
when "DataSetCompletion"
|
46
|
+
Kusto::Rest::DataSetCompletion.new(frame)
|
47
|
+
else
|
48
|
+
Kusto::Result::DataFrame.new(frame)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def frames
|
55
|
+
@frames ||= @data.map do |frame|
|
56
|
+
self.class.parse_frame(frame)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "data_frame"
|
4
|
+
|
5
|
+
module Kusto
|
6
|
+
module Rest
|
7
|
+
class DataSetHeader < DataFrame
|
8
|
+
def progressive?
|
9
|
+
@data["IsProgressive"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def fragmented?
|
13
|
+
@data["IsFragmented"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def version
|
17
|
+
@data["Version"]
|
18
|
+
end
|
19
|
+
|
20
|
+
def error_reporting_placement
|
21
|
+
@data["ErrorReportingPlacement"]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "data_frame"
|
4
|
+
|
5
|
+
module Kusto
|
6
|
+
module Rest
|
7
|
+
class DataTable < DataFrame
|
8
|
+
def rows
|
9
|
+
columns = @data["Columns"]
|
10
|
+
row_data = @data["Rows"]
|
11
|
+
row_data.map do |row|
|
12
|
+
columns.each_with_index.to_h do |column, index|
|
13
|
+
[column["ColumnName"], cast(row[index], column["ColumnType"])]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/kusto/rest.rb
ADDED
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: azure-kusto-ruby
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Carlton Brown
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-05-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/kusto/rest.rb
|
20
|
+
- lib/kusto/rest/context.rb
|
21
|
+
- lib/kusto/rest/context/context.rb
|
22
|
+
- lib/kusto/rest/context/management_context.rb
|
23
|
+
- lib/kusto/rest/context/query_context.rb
|
24
|
+
- lib/kusto/rest/query.rb
|
25
|
+
- lib/kusto/rest/query/data.rb
|
26
|
+
- lib/kusto/rest/query/query.rb
|
27
|
+
- lib/kusto/rest/result.rb
|
28
|
+
- lib/kusto/rest/result/data_frame.rb
|
29
|
+
- lib/kusto/rest/result/data_set.rb
|
30
|
+
- lib/kusto/rest/result/data_set_completion.rb
|
31
|
+
- lib/kusto/rest/result/data_set_header.rb
|
32
|
+
- lib/kusto/rest/result/data_table.rb
|
33
|
+
- lib/version.rb
|
34
|
+
homepage: https://github.com/carltonbrown/azure-kusto-ruby
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata:
|
38
|
+
github_repo: https://github.com/carltonbrown/azure-kusto-ruby
|
39
|
+
rubygems_mfa_required: 'true'
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 3.1.0
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubygems_version: 3.5.3
|
56
|
+
signing_key:
|
57
|
+
specification_version: 4
|
58
|
+
summary: A client for the Kusto REST API
|
59
|
+
test_files: []
|