Sha256: 6211ffec1b199ecb01e343cc9310ac35dc0f244b99e23a12f1673f93ce1a046e

Contents?: true

Size: 1.92 KB

Versions: 15

Compression:

Stored size: 1.92 KB

Contents

class Ey::Core::Client
  class Real
    def create_alert(params={})
      url = params.delete("url")

      request(
        :method => :post,
        :path   => "/alerts",
        :body   => params,
        :url    => url,
      )
    end
  end # Real

  class Mock
    def create_alert(_params={})
      params = Cistern::Hash.stringify_keys(_params)
      extract_url_params!(params)

      database_server_id = resource_identity(params["database_server"] || params["database_server_id"])
      server_id          = resource_identity(params["server"]          || params["server_id"])

      alert_params = require_parameters(params, "alert")
      name, external_id, message, severity = require_parameters(alert_params, *%w[name external_id message severity])
      resource_id = self.uuid

      alert = {
        "id"           => resource_id,
        "created_at"   => Time.now,
        "updated_at"   => Time.now,
        "deleted_at"   => nil,
        "severity"     => severity,
        "acknowledged" => alert_params.fetch("acknowledged", false),
        "ignored"      => alert_params.fetch("ignored", false),
        "message"      => message,
        "description"  => alert_params["description"],
        "external_id"  => external_id,
        "name"         => name,
        "finished_at"  => alert_params["finished_at"],
        "started_at"   => alert_params["started_at"],
      }

      alert.merge!("resource" =>
                   if database_server_id
                     url_for("/database-servers/#{database_server_id}")
                   elsif server_id
                     url_for("/servers/#{server_id}")
                   else
                     raise response(status: 422, body: "Requires either server or database_server")
                   end
                  )

      self.data[:alerts][resource_id] = alert
      response(
        :body   => {"alert" => alert},
        :status => 201,
      )
    end
  end # Mock
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ey-pro-cli-0.0.17 lib/vendor/core/ey-core/requests/create_alert.rb
ey-pro-cli-0.0.16 lib/vendor/core/ey-core/requests/create_alert.rb
ey-pro-cli-0.0.15 lib/vendor/core/ey-core/requests/create_alert.rb
ey-pro-cli-0.0.14 lib/vendor/core/ey-core/requests/create_alert.rb
ey-pro-cli-0.0.13 lib/vendor/core/ey-core/requests/create_alert.rb
ey-pro-cli-0.0.12 lib/vendor/core/ey-core/requests/create_alert.rb
ey-pro-cli-0.0.11 lib/vendor/core/ey-core/requests/create_alert.rb
ey-pro-cli-0.0.10 lib/vendor/core/ey-core/requests/create_alert.rb
ey-pro-cli-0.0.9 lib/vendor/core/ey-core/requests/create_alert.rb
ey-pro-cli-0.0.8 lib/vendor/core/ey-core/requests/create_alert.rb
ey-pro-cli-0.0.7 lib/vendor/core/ey-core/requests/create_alert.rb
ey-pro-cli-0.0.6 lib/vendor/core/ey-core/requests/create_alert.rb
ey-pro-cli-0.0.5 lib/vendor/core/ey-core/requests/create_alert.rb
ey-pro-cli-0.0.4 lib/vendor/core/ey-core/requests/create_alert.rb
ey-pro-cli-0.0.3 lib/vendor/core/ey-core/requests/create_alert.rb