Sha256: 4f974a333d8b30e3d72b457efc0eb77a648d9fef453da7ec7f84b49a1bf9c55c

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require 'dry/struct'

require_relative 'grafana_annotations/version'
require_relative 'grafana_annotations/utils/time'

require_relative 'grafana_annotations/types'
require_relative 'grafana_annotations/config'
require_relative 'grafana_annotations/config/dsl'
require_relative 'grafana_annotations/annotation'
require_relative 'grafana_annotations/patch_annotation_request'
require_relative 'grafana_annotations/api_client'
require_relative 'grafana_annotations/wrap'

module GrafanaAnnotations
  class Error < StandardError; end
  class ConfigurationError < Error; end

  class << self
    attr_reader :config
    include GrafanaAnnotations::Wrap

    def configure
      dsl = GrafanaAnnotations::Config::Dsl.new
      yield dsl
      @config = GrafanaAnnotations::Config.new(dsl.config)
    rescue StandardError => e
      raise ConfigurationError, e.message
    end

    def default_api_client
      @default_api_client ||= begin
        raise ConfigurationError, 'todo' unless config

        new_api_client({})
      end
    end

    def new_api_client(opts)
      return ApiClient.new(opts) unless config

      ApiClient.new(
        opts.merge(
          logger: config.logger,
          base_url: config.grafana_base_url,
          authorization: config.grafana_authorization
        )
      )
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grafana_annotations-0.1.0 lib/grafana_annotations.rb