module LibratoAlerts

Constants

API_HOST
DEFAULT_VERSION

Attributes

token[W]
user[W]

Public Instance Methods

all() click to toggle source
# File lib/librato-alerts.rb, line 15
def all
  request(method: :get)[:alerts]
end
configure() { |self| ... } click to toggle source
# File lib/librato-alerts.rb, line 11
def configure
  yield self
end
delete(alert_id) click to toggle source
# File lib/librato-alerts.rb, line 33
def delete(alert_id)
  request(
    endpoint: "/#{alert_id}",
    method: :delete)
end
disable(alert_id) click to toggle source
# File lib/librato-alerts.rb, line 26
def disable(alert_id)
  request(
    endpoint: "/#{alert_id}",
    method: :put,
    active: false)
end
enable(alert_id) click to toggle source
# File lib/librato-alerts.rb, line 19
def enable(alert_id)
  request(
    endpoint: "/#{alert_id}",
    method: :put,
    active: true)
end

Private Instance Methods

default_parameters() click to toggle source
# File lib/librato-alerts.rb, line 58
def default_parameters
  { version: DEFAULT_VERSION }
end
request(endpoint: "", method:, **parameters) click to toggle source
# File lib/librato-alerts.rb, line 41
def request(endpoint: "", method:, **parameters)
  options = {
    method: method,
    params: default_parameters.merge(parameters),
    auth_type: :basic,
    user: @user,
    password: @token,
    format: :json
  }

  response = Nestful::Request.new("#{API_HOST}/alerts#{endpoint}", options).execute

  return if response.body.nil? || response.body.empty?

  JSON.parse(response.body, symbolize_names: true)
end