Sha256: 307f7bc97b3beab4b51debbb28c5a3a1a13203370f3dfc25837dea24b363224c

Contents?: true

Size: 1.51 KB

Versions: 7

Compression:

Stored size: 1.51 KB

Contents

module SnowmanIO
  module API
    class Checks < Grape::API
      before(&:authenticate!)

      namespace :checks do
        params do
          requires :check, type: Hash do
            requires :metric_id, type: String
            requires :template, type: String
            requires :cmp, type: String
            requires :value, type: Float
          end
        end
        post do
          metric = Metric.find(permitted_params[:check][:metric_id])
          { check: metric.checks.create!(
            permitted_params[:check].to_h.except("metric_id").merge("user_id" => current_user.id)
          ) }
        end

        route_param :id do
          before do
            @check = Check.find(params[:id])
          end

          params do
            requires :check, type: Hash do
              requires :metric_id, type: String
              requires :template, type: String
              requires :cmp, type: String
              requires :value, type: Float
            end
          end
          put do
            { check: @check.tap { |m| 
              m.update_attributes!(permitted_params[:check].to_h.except("metric_id").merge(
                "triggered" => false,
                "last_status" => Check::STATUS_NEVER_RUNNED
              ))
            } }
          end

          delete do
            Extra::Meteor.model_destroy(@check)
          end

          put 'resolve' do
            { check: @check.tap { |m| m.update_attributes!(triggered: false) } }
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
snowman-io-0.5.1 lib/snowman-io/api/checks.rb
snowman-io-0.5.0 lib/snowman-io/api/checks.rb
snowman-io-0.4.0 lib/snowman-io/api/checks.rb
snowman-io-0.3.1 lib/snowman-io/api/checks.rb
snowman-io-0.3.0 lib/snowman-io/api/checks.rb
snowman-io-0.2.0 lib/snowman-io/api/checks.rb
snowman-io-0.1.0 lib/snowman-io/api/checks.rb