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, name, updated = false) ⇒ DogWatch::Model::Response

Parameters:

  • response (Array)
  • name (String)
  • updated (Boolean) (defaults to: false)


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

def initialize(response, name, updated = false)
  @response = response
  @updated = updated
  @name = if response[1]['name'].nil?
            name
          else
            response[1]['name']
          end
end

Instance Attribute Details

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#messageString

Returns:

  • (String)


45
46
47
# File 'lib/dogwatch/model/response.rb', line 45

def message
  send(status, @response[1])
end

#statusSymbol

Returns:

  • (Symbol)


37
38
39
40
41
42
# File 'lib/dogwatch/model/response.rb', line 37

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

#to_thorArray

Returns:

  • (Array)


50
51
52
53
54
# File 'lib/dogwatch/model/response.rb', line 50

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