class Grafana::BaseClient

Public Class Methods

new(grafana_url: Grafana::Client.grafana_url, api_key: Grafana::Client.api_key) click to toggle source
# File lib/grafana/client/base_client.rb, line 10
def initialize(grafana_url: Grafana::Client.grafana_url, api_key: Grafana::Client.api_key)
  retry_options = {
    max: 2,
    retry_statuses: [429]
  }

  @conn = Faraday.new(url: grafana_url) do |f|
    f.request :authorization, :Bearer, api_key
    f.request :json # encode req bodies as JSON
    f.request :retry, retry_options # retry transient failures
    f.response :follow_redirects # follow redirects
    f.response :json, content_type: /\bjson$/ # decode response bodies as JSON
  end
end

Public Instance Methods

delete(url, **options) click to toggle source
# File lib/grafana/client/base_client.rb, line 37
def delete(url, **options)
  response = @conn.delete(url, **options)

  response.body
end
get(url, **options) click to toggle source
# File lib/grafana/client/base_client.rb, line 25
def get(url, **options)
  # TODO: error handling
  @conn.get(url, **options).body
end
post(url, body, **options) click to toggle source
# File lib/grafana/client/base_client.rb, line 30
def post(url, body, **options)
  response = @conn.post(url, body, **options)

  # TODO: handle errors in the response
  response.body
end