diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ef1cc51c..82e189ca 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-10-01 12:52:09 +0200 using RuboCop version 0.49.1. +# on 2019-11-25 14:34:01 -0500 using RuboCop version 0.49.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -51,14 +51,14 @@ Layout/EmptyLines: - 'lib/capistrano/datadog/v2.rb' - 'lib/dogapi/facade.rb' -# Offense count: 63 +# Offense count: 73 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: empty_lines, empty_lines_except_namespace, empty_lines_special, no_empty_lines Layout/EmptyLinesAroundClassBody: Enabled: false -# Offense count: 1 +# Offense count: 4 # Cop supports --auto-correct. Layout/EmptyLinesAroundMethodBody: Exclude: @@ -120,7 +120,7 @@ Layout/SpaceAfterComma: Exclude: - 'examples/custom_metric.rb' -# Offense count: 75 +# Offense count: 83 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: space, no_space @@ -201,44 +201,47 @@ Lint/UselessAssignment: Exclude: - 'lib/capistrano/datadog.rb' -# Offense count: 11 +# Offense count: 12 Metrics/AbcSize: Max: 51 -# Offense count: 18 +# Offense count: 24 # Configuration parameters: CountComments, ExcludedMethods. Metrics/BlockLength: - Max: 96 - Exclude: - - 'spec/integration/monitor_spec.rb' + Max: 114 -# Offense count: 2 +# Offense count: 1 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 105 + +# Offense count: 3 Metrics/CyclomaticComplexity: Max: 8 -# Offense count: 15 +# Offense count: 17 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 34 -# Offense count: 2 +# Offense count: 4 # Configuration parameters: CountKeywordArgs. Metrics/ParameterLists: Max: 7 -# Offense count: 1 +# Offense count: 2 Metrics/PerceivedComplexity: Max: 9 -# Offense count: 11 +# Offense count: 13 Style/AccessorMethodName: Exclude: - 'lib/dogapi/facade.rb' - 'lib/dogapi/v1/alert.rb' - 'lib/dogapi/v1/dash.rb' + - 'lib/dogapi/v1/dashboard.rb' - 'lib/dogapi/v1/embed.rb' - 'lib/dogapi/v1/screenboard.rb' - - 'lib/dogapi/v1/dashboard.rb' - 'lib/dogapi/v1/user.rb' # Offense count: 1 @@ -283,7 +286,7 @@ Style/ClassMethods: Exclude: - 'lib/dogapi/common.rb' -# Offense count: 2 +# Offense count: 3 Style/ClassVars: Exclude: - 'lib/dogapi/common.rb' @@ -295,13 +298,12 @@ Style/ColonMethodCall: - 'lib/capistrano/datadog.rb' - 'lib/capistrano/datadog/v2.rb' -# Offense count: 2 +# Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerBackticks. # SupportedStyles: backticks, percent_x, mixed Style/CommandLiteral: Exclude: - - 'lib/capistrano/datadog.rb' - 'lib/dogapi/common.rb' # Offense count: 1 @@ -312,7 +314,7 @@ Style/ConditionalAssignment: Exclude: - 'lib/capistrano/datadog.rb' -# Offense count: 20 +# Offense count: 21 # Cop supports --auto-correct. Style/DefWithParentheses: Exclude: @@ -322,28 +324,9 @@ Style/DefWithParentheses: - 'lib/dogapi/v1/metric.rb' - 'lib/dogapi/v1/screenboard.rb' -# Offense count: 21 +# Offense count: 23 Style/Documentation: - Exclude: - - 'spec/**/*' - - 'test/**/*' - - 'lib/capistrano/datadog.rb' - - 'lib/capistrano/datadog/v2.rb' - - 'lib/capistrano/datadog/v3.rb' - - 'lib/dogapi/common.rb' - - 'lib/dogapi/v1/alert.rb' - - 'lib/dogapi/v1/comment.rb' - - 'lib/dogapi/v1/dash.rb' - - 'lib/dogapi/v1/metadata.rb' - - 'lib/dogapi/v1/monitor.rb' - - 'lib/dogapi/v1/screenboard.rb' - - 'lib/dogapi/v1/search.rb' - - 'lib/dogapi/v1/service_check.rb' - - 'lib/dogapi/v1/snapshot.rb' - - 'lib/dogapi/v1/user.rb' - - 'lib/dogapi/v1/integration.rb' - - 'lib/dogapi/v1/usage.rb' - - 'lib/dogapi/v1/metric.rb' + Enabled: false # Offense count: 1 # Cop supports --auto-correct. @@ -351,7 +334,7 @@ Style/EmptyLiteral: Exclude: - 'lib/dogapi/v1/metric.rb' -# Offense count: 2 +# Offense count: 3 # Configuration parameters: MinBodyLength. Style/GuardClause: Exclude: @@ -399,7 +382,7 @@ Style/LineEndConcatenation: Exclude: - 'dogapi.gemspec' -# Offense count: 15 +# Offense count: 18 # Cop supports --auto-correct. Style/MethodCallWithoutArgsParentheses: Exclude: @@ -414,7 +397,7 @@ Style/MultilineIfThen: Exclude: - 'lib/capistrano/datadog.rb' -# Offense count: 21 +# Offense count: 29 # Cop supports --auto-correct. Style/MutableConstant: Enabled: false @@ -434,12 +417,11 @@ Style/Not: Exclude: - 'lib/dogapi/v1/metric.rb' -# Offense count: 5 +# Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: PreferredDelimiters. Style/PercentLiteralDelimiters: Exclude: - - 'lib/capistrano/datadog.rb' - 'lib/dogapi/common.rb' - 'spec/integration/event_spec.rb' - 'spec/integration/monitor_spec.rb' @@ -452,15 +434,14 @@ Style/PreferredHashMethods: Exclude: - 'lib/dogapi/common.rb' -# Offense count: 3 +# Offense count: 2 # Cop supports --auto-correct. Style/RedundantBegin: Exclude: - 'lib/capistrano/datadog.rb' - - 'lib/dogapi/common.rb' - 'lib/dogapi/v1/metric.rb' -# Offense count: 2 +# Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: AllowMultipleReturnValues. Style/RedundantReturn: @@ -497,7 +478,7 @@ Style/SpecialGlobalVars: Exclude: - 'dogapi.gemspec' -# Offense count: 22 +# Offense count: 25 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline. # SupportedStyles: single_quotes, double_quotes @@ -509,8 +490,9 @@ Style/StringLiterals: - 'examples/Capfile' - 'examples/custom_event.rb' - 'lib/dogapi/event.rb' + - 'lib/dogapi/v1/monitor.rb' -# Offense count: 10 +# Offense count: 9 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyleForMultiline, SupportedStylesForMultiline. # SupportedStylesForMultiline: comma, consistent_comma, no_comma @@ -526,11 +508,11 @@ Style/TrailingCommaInLiteral: # Offense count: 2 # Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, MinSize, WordRegex. +# Configuration parameters: SupportedStyles, WordRegex. # SupportedStyles: percent, brackets Style/WordArray: - Exclude: - - 'examples/custom_event.rb' + EnforcedStyle: percent + MinSize: 3 # Offense count: 1 # Cop supports --auto-correct. diff --git a/lib/dogapi/facade.rb b/lib/dogapi/facade.rb index c5e412a7..7de989bb 100644 --- a/lib/dogapi/facade.rb +++ b/lib/dogapi/facade.rb @@ -536,6 +536,10 @@ def get_monitor(monitor_id, options= {}) @monitor_svc.get_monitor(monitor_id, options) end + def can_delete_monitors(monitor_ids) + @monitor_svc.can_delete_monitors(monitor_ids) + end + def delete_monitor(monitor_id) @monitor_svc.delete_monitor(monitor_id) end diff --git a/lib/dogapi/v1/monitor.rb b/lib/dogapi/v1/monitor.rb index 6aaacc32..4893323a 100644 --- a/lib/dogapi/v1/monitor.rb +++ b/lib/dogapi/v1/monitor.rb @@ -2,9 +2,7 @@ module Dogapi class V1 # for namespacing - class MonitorService < Dogapi::APIService - API_VERSION = 'v1' def monitor(type, query, options = {}) @@ -42,6 +40,17 @@ def get_monitor(monitor_id, options = {}) request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/#{monitor_id}", extra_params, nil, false) end + def can_delete_monitors(monitor_ids) + extra_params = + if monitor_ids.respond_to?(:join) + { "monitor_ids" => monitor_ids.join(",") } + else + { "monitor_ids" => monitor_ids } + end + + request(Net::HTTP::Get, "/api/#{API_VERSION}/monitor/can_delete", extra_params, nil, false) + end + def delete_monitor(monitor_id) request(Net::HTTP::Delete, "/api/#{API_VERSION}/monitor/#{monitor_id}", nil, nil, false) end diff --git a/spec/integration/monitor_spec.rb b/spec/integration/monitor_spec.rb index 5e31364b..180a7795 100644 --- a/spec/integration/monitor_spec.rb +++ b/spec/integration/monitor_spec.rb @@ -27,6 +27,20 @@ :get, "/monitor/#{MONITOR_ID}", group_states: %w(custom all) end + describe '#can_delete_monitors' do + context 'with one id' do + it_behaves_like 'an api method', + :can_delete_monitors, [MONITOR_ID], + :get, '/monitor/can_delete' + end + + context 'with multiple ids' do + it_behaves_like 'an api method', + :can_delete_monitors, [[MONITOR_ID, MONITOR_ID + 1, MONITOR_ID + 2]], + :get, '/monitor/can_delete' + end + end + describe '#delete_monitor' do it_behaves_like 'an api method', :delete_monitor, [MONITOR_ID],