Class: DogWatch::Model::Response

Inherits:
Object
  • Object
show all
Extended by:
Mixin::Colorize
Defined in:
lib/dogwatch/model/response.rb

Overview

Takes DataDog client responses and formats them nicely

Constant Summary collapse

ERROR =
'400'.freeze
CREATED =
'200'.freeze
ACCEPTED =
'202'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mixin::Colorize

colorize

Constructor Details

#initialize(response, updated = false) ⇒ Response

Returns a new instance of Response.



21
22
23
24
# File 'lib/dogwatch/model/response.rb', line 21

def initialize(response, updated = false)
  @response = response
  @updated = updated
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



19
20
21
# File 'lib/dogwatch/model/response.rb', line 19

def response
  @response
end

Instance Method Details

#messageObject



33
34
35
36
37
38
# File 'lib/dogwatch/model/response.rb', line 33

def message
  attrs = @response[1]
  return attrs['errors'] if attrs.key?('errors')
  "#{status.to_s.capitalize} monitor #{attrs['name']}"\
  " with message #{attrs['message']}"
end

#statusObject



26
27
28
29
30
31
# File 'lib/dogwatch/model/response.rb', line 26

def status
  return :updated if @updated == true
  return :created if created?
  return :error if failed?
  return :accepted if accepted?
end

#to_thorObject



40
41
42
43
44
# File 'lib/dogwatch/model/response.rb', line 40

def to_thor
  action = status
  text = message
  [action, text, color]
end