Class: GrafanaAnnotations::ApiClient

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer
Includes:
Dry::Monads::Result::Mixin
Defined in:
lib/grafana_annotations/api_client.rb

Overview

Instance Method Summary collapse

Instance Method Details

#create(annotation) ⇒ Success<Integer>, Failure<Symbol>

Parameters:

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/grafana_annotations/api_client.rb', line 24

def create(annotation)
  annotation = GrafanaAnnotations::Annotation.new(annotation)

  result = with_error_handler { connection.post('/api/annotations', annotation.to_json) }
  result.bind do |resp|
    parse_json_body(resp.body).bind do |resp_body|
      annotation_id = resp_body['id']
      annotation_id = nil if annotation_id == ''

      annotation_id ? Success(annotation_id) : Failure(:invalid_response_format)
    end
  end
end

#patch(id, params) ⇒ Success<Integer>, Failure<Symbol>

Parameters:

Returns:



41
42
43
44
45
46
47
48
49
50
# File 'lib/grafana_annotations/api_client.rb', line 41

def patch(id, params)
  result = with_error_handler do
    struct = PatchAnnotationRequest.new(params)
    return Failure(:empty_changeset) if struct.to_h.empty?

    connection.patch("/api/annotations/#{id}", struct.to_h.to_json)
  end

  result.bind { Success(id) }
end