class DogWatch::Model::Response
Takes DataDog client responses and formats them nicely
Constants
- ACCEPTED
- CREATED
- ERROR
Attributes
response[RW]
Public Class Methods
new(response, name, updated = false)
click to toggle source
@param [Array] response @param [String] name @param [Boolean] updated @return [DogWatch::Model::Response]
# 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
Public Instance Methods
message()
click to toggle source
@return [String]
# File lib/dogwatch/model/response.rb, line 45 def message send(status, @response[1]) end
status()
click to toggle source
@return [Symbol]
# 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_thor()
click to toggle source
@return [Array]
# File lib/dogwatch/model/response.rb, line 50 def to_thor action = status text = message [action, text, color] end
Private Instance Methods
accepted(attrs)
click to toggle source
# File lib/dogwatch/model/response.rb, line 73 def accepted(attrs) "Accepted monitor #{@name} with message #{attrs['message']}" end
accepted?()
click to toggle source
# File lib/dogwatch/model/response.rb, line 77 def accepted? @response[0] == ACCEPTED end
created(attrs)
click to toggle source
# File lib/dogwatch/model/response.rb, line 63 def created(attrs) "Created monitor #{@name} with message #{attrs['message']}" end
created?()
click to toggle source
# File lib/dogwatch/model/response.rb, line 81 def created? @response[0] == CREATED end
error(attrs)
click to toggle source
# File lib/dogwatch/model/response.rb, line 58 def error(attrs) err = attrs['errors'].join(', ') "The following errors occurred when creating monitor #{@name}: #{err}" end
failed?()
click to toggle source
# File lib/dogwatch/model/response.rb, line 85 def failed? @response[0] == ERROR end
updated(attrs)
click to toggle source
# File lib/dogwatch/model/response.rb, line 67 def updated(attrs) # TODO: Use some kind of statefile to determine diffs between # previously saved model and new version "Updated monitor #{@name} with message #{attrs['message']}" end