Class: Reactio::Service

Inherits:
Object
  • Object
show all
Includes:
Utils
Defined in:
lib/reactio/service.rb

Constant Summary

Constants included from Utils

Utils::NIL_STRING

Instance Method Summary collapse

Methods included from Utils

#to_option_string

Constructor Details

#initialize(options) ⇒ Service

Returns a new instance of Service.



7
8
9
10
11
12
# File 'lib/reactio/service.rb', line 7

def initialize(options)
  @api = APIClient.build(
    options[:api_key],
    options[:organization]
  )
end

Instance Method Details

#create_incident(name, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/reactio/service.rb', line 14

def create_incident(name, options = {})
  payload = { name: name }.tap do |me|
    me[:detection] = to_option_string(options.delete(:detection)) if options.key?(:detection)
    me[:cause] = to_option_string(options.delete(:cause)) if options.key?(:cause)
    me[:point] = to_option_string(options.delete(:point)) if options.key?(:point)
    me[:scale] = to_option_string(options.delete(:scale)) if options.key?(:scale)
  end
    .merge!(options)
  @api.request(:post, "/api/v1/incidents", body: payload)
end

#describe_incident(incident_id) ⇒ Object



25
26
27
# File 'lib/reactio/service.rb', line 25

def describe_incident(incident_id)
  @api.request(:get, "/api/v1/incidents/#{incident_id}")
end

#list_incidents(options = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/reactio/service.rb', line 29

def list_incidents(options = {})
  payload = {}.tap do |me|
    me[:from] = options.delete(:from).to_i if options[:from]
    me[:to] = options.delete(:to).to_i if options[:to]
    me[:status] = options.delete(:status).to_s if options[:status]
  end
    .merge!(options)
  @api.request(:get, "/api/v1/incidents", body: payload)
end

#notify_incident(incident_id, options = {}) ⇒ Object



39
40
41
42
43
44
# File 'lib/reactio/service.rb', line 39

def notify_incident(incident_id, options = {})
  @api.request(
    :post, "/api/v1/notifications",
    body: { incident_id: incident_id }.merge(options)
  )
end