Class: Kusto::Rest::Context
- Inherits:
-
Object
- Object
- Kusto::Rest::Context
- Defined in:
- lib/kusto/rest/context/context.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #endpoint ⇒ Object
-
#initialize(url:, token:) ⇒ Context
constructor
A new instance of Context.
- #post(query) ⇒ Object
Constructor Details
#initialize(url:, token:) ⇒ Context
Returns a new instance of Context.
13 14 15 16 17 |
# File 'lib/kusto/rest/context/context.rb', line 13 def initialize(url:, token:) @url = url @token = token @connector = Faraday.new(url:) end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/kusto/rest/context/context.rb', line 9 def path @path end |
Instance Method Details
#endpoint ⇒ Object
37 38 39 |
# File 'lib/kusto/rest/context/context.rb', line 37 def endpoint @connector.url_prefix.to_s + @path end |
#post(query) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kusto/rest/context/context.rb', line 19 def post(query) response = @connector.post(@path) do |req| req.headers["Content-Type"] = "application/json" req.headers["Authorization"] = "Bearer #{@token}" req.body = query.request_body.to_json end unless response.success? raise Error, "Request failed with status #{response.status} - #{response.reason_phrase} #{response.body}" end if response.body.empty? || response.body.nil? raise Error, "Request with status #{response.status} returned an empty response body" end Kusto::Rest::DataSet.new(response.body) end |