uppityrobot 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9397823fd8a288fb052f7a4dcc0278279e16375e9182183298334a6c7228ae77
4
- data.tar.gz: 819f188c12700edbbfc415619f603b8a1ba73fdbc24e4dc7346aa55a580d501e
3
+ metadata.gz: c6413d2b0150549b68586c168ef6d6a7976254bbeae5b45c6b633d2df3e0d012
4
+ data.tar.gz: c92eafba695a8dba78ecb4a3a5a885db86a263aa43cdd81965f36877cc1bd326
5
5
  SHA512:
6
- metadata.gz: '08f3bd70fc1565abed8e97987db929e3e9146f57f36ff751cde51111b9e3d238bfd787fb13be27d736a5eaedf870434f648d301c43822f3daeebbf513b57ee6d'
7
- data.tar.gz: 44b1f4ba2c5f16520805fe8bf658996d324760e86fe956c9e9778afe19f63249db476e8f6692d757fdd544b88202bcc9cd538819895b05991f2d13d041843f52
6
+ metadata.gz: 8f1c839b6cb1e08466e5a7eb1f78e6decb0d3256e37fab2aab655d9e66ef421e5e1e2c42e40ca63257517504ce2262ce03cf3cfc18cff2febb28cc4fe2f5bf4f
7
+ data.tar.gz: d7fc01dbfb3baf5452150267a86d6127bb4c303d2e96262646111479c3a20bb18a96ca86c7524a800e386a5d3ae177402f9c44b061d5f1391fb5a91fd10a26ff
@@ -7,10 +7,15 @@ jobs:
7
7
  runs-on: ubuntu-latest
8
8
  steps:
9
9
  - uses: actions/checkout@v2
10
+
10
11
  - name: Set up Ruby
11
12
  uses: ruby/setup-ruby@v1
12
13
  with:
13
14
  ruby-version: 2.7.4
14
15
  bundler-cache: true
16
+
17
+ - name: Lint
18
+ run: bundle exec standardrb
19
+
15
20
  - name: Run the default task
16
21
  run: bundle exec rake
data/.rubocop.yml CHANGED
@@ -1,20 +1,4 @@
1
- AllCops:
2
- NewCops: enable
3
- TargetRubyVersion: 2.7
1
+ require: standard
4
2
 
5
- Style/StringLiterals:
6
- Enabled: true
7
- EnforcedStyle: double_quotes
8
-
9
- Style/StringLiteralsInInterpolation:
10
- Enabled: true
11
- EnforcedStyle: double_quotes
12
-
13
- Layout/LineLength:
14
- Max: 120
15
-
16
- Metrics/BlockLength:
17
- IgnoredMethods: ['describe', 'context']
18
-
19
- Metrics/MethodLength:
20
- Max: 20
3
+ inherit_gem:
4
+ standard: config/base.yml
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- uppityrobot (0.4.0)
4
+ uppityrobot (0.4.1)
5
5
  dry-cli (~> 0.7)
6
6
  json (~> 2.5)
7
7
  uptimerobot (~> 0.2)
@@ -68,7 +68,7 @@ GEM
68
68
  cucumber-messages (~> 17.0, >= 17.0.1)
69
69
  diff-lcs (1.4.4)
70
70
  dry-cli (0.7.0)
71
- faraday (1.10.0)
71
+ faraday (1.10.2)
72
72
  faraday-em_http (~> 1.0)
73
73
  faraday-em_synchrony (~> 1.0)
74
74
  faraday-excon (~> 1.1)
@@ -156,6 +156,9 @@ GEM
156
156
  unicode-display_width (>= 1.4.0, < 3.0)
157
157
  rubocop-ast (1.11.0)
158
158
  parser (>= 3.0.1.1)
159
+ rubocop-performance (1.11.5)
160
+ rubocop (>= 1.7.0, < 2.0)
161
+ rubocop-ast (>= 0.4.0)
159
162
  ruby-progressbar (1.11.0)
160
163
  ruby2_keywords (0.0.5)
161
164
  sinatra (2.1.0)
@@ -163,6 +166,9 @@ GEM
163
166
  rack (~> 2.2)
164
167
  rack-protection (= 2.1.0)
165
168
  tilt (~> 2.0)
169
+ standard (1.3.0)
170
+ rubocop (= 1.20.0)
171
+ rubocop-performance (= 1.11.5)
166
172
  sys-uname (1.2.2)
167
173
  ffi (~> 1.1)
168
174
  thor (1.1.0)
@@ -192,6 +198,7 @@ DEPENDENCIES
192
198
  rspec (~> 3.2)
193
199
  rubocop (~> 1.7)
194
200
  sinatra
201
+ standard
195
202
  uppityrobot!
196
203
  webmock
197
204
 
data/Rakefile CHANGED
@@ -11,7 +11,9 @@ RuboCop::RakeTask.new
11
11
  require "cucumber/rake/task"
12
12
  Cucumber::Rake::Task.new
13
13
 
14
- task default: %i[spec cucumber rubocop]
14
+ require "standard/rake"
15
+
16
+ task default: %i[spec cucumber]
15
17
 
16
18
  load File.join("lib", "uppityrobot", "Rakefile")
17
19
 
@@ -9,8 +9,8 @@ module UppityRobot
9
9
 
10
10
  argument :task, required: true, values: UptimeRobot::Client::METHODS, desc: "API task to be executed"
11
11
 
12
- option :data, type: :string, desc: "JSON data file"
13
- option :params, type: :string, default: "{}", desc: "JSON params"
12
+ option :data, type: :string, desc: "JSON data file"
13
+ option :params, type: :string, default: "{}", desc: "JSON params"
14
14
 
15
15
  example [
16
16
  "getMonitors --data $json_data_file",
@@ -18,11 +18,11 @@ module UppityRobot
18
18
  ]
19
19
 
20
20
  def call(task:, data: nil, params: "{}", **)
21
- task = task.to_sym
21
+ task = task.to_sym
22
22
  params = data.nil? ? JSON.parse(params) : parse_file(data)
23
23
  puts UppityRobot::Client.new(task, params).execute.to_json
24
24
  rescue JSON::ParserError => e
25
- puts JSON.generate({ stat: "fail", error: "JSON parser #{e.message}" })
25
+ puts JSON.generate({stat: "fail", error: "JSON parser #{e.message}"})
26
26
  end
27
27
 
28
28
  def parse_file(file)
@@ -30,7 +30,7 @@ module UppityRobot
30
30
  response = UppityRobot::Client.new(:newMonitor, data).execute
31
31
  puts response.to_json
32
32
  rescue URI::InvalidURIError => e
33
- puts JSON.generate({ stat: "fail", error: "URI parser #{e.message}" })
33
+ puts JSON.generate({stat: "fail", error: "URI parser #{e.message}"})
34
34
  end
35
35
 
36
36
  def check_subtype(uri)
@@ -39,8 +39,8 @@ module UppityRobot
39
39
  elsif uri.instance_of?(URI::HTTPS)
40
40
  UptimeRobot::Monitor::SubType::HTTPS
41
41
  else
42
- abort({ stat: "fail",
43
- error: "Monitor URL must be HTTP/S" }.to_json)
42
+ abort({stat: "fail",
43
+ error: "Monitor URL must be HTTP/S"}.to_json)
44
44
  end
45
45
  end
46
46
  end
@@ -19,15 +19,15 @@ module UppityRobot
19
19
  def call(field:, value:, **)
20
20
  check_field(field)
21
21
  monitor = find_monitor(field, value)
22
- response = UppityRobot::Client.new(:deleteMonitor, { id: monitor["id"] }).execute
22
+ response = UppityRobot::Client.new(:deleteMonitor, {id: monitor["id"]}).execute
23
23
  puts response.to_json
24
24
  end
25
25
 
26
26
  def check_field(field)
27
27
  return if %w[id name].include? field
28
28
 
29
- abort({ stat: "fail",
30
- error: "Field not recognized, must be one of: [id, name]" }.to_json)
29
+ abort({stat: "fail",
30
+ error: "Field not recognized, must be one of: [id, name]"}.to_json)
31
31
  end
32
32
 
33
33
  def find_monitor(field, value)
@@ -20,14 +20,14 @@ module UppityRobot
20
20
 
21
21
  # rubocop:disable Metrics/AbcSize
22
22
  def call(task:, search:, filter: "{}", **)
23
- status = check_task(task)
24
- filter = JSON.parse(filter)
25
- filtered = { stat: "ok", total: 0, monitors: [] }
26
- params = { search: search }
27
- total = 0
23
+ status = check_task(task)
24
+ filter = JSON.parse(filter)
25
+ filtered = {stat: "ok", total: 0, monitors: []}
26
+ params = {search: search}
27
+ total = 0
28
28
 
29
29
  UppityRobot::Client.new(:getMonitors, params).filter(filter).each do |m|
30
- data = { id: m["id"], status: status }
30
+ data = {id: m["id"], status: status}
31
31
  filtered[:monitors] << UppityRobot::Client.new(:editMonitor, data).execute
32
32
  total += 1
33
33
  end
@@ -35,7 +35,7 @@ module UppityRobot
35
35
  filtered[:total] = total
36
36
  puts filtered.to_json
37
37
  rescue JSON::ParserError => e
38
- puts JSON.generate({ stat: "fail", error: "JSON parser #{e.message}" })
38
+ puts JSON.generate({stat: "fail", error: "JSON parser #{e.message}"})
39
39
  end
40
40
  # rubocop:enable Metrics/AbcSize
41
41
 
@@ -46,8 +46,8 @@ module UppityRobot
46
46
  when "start"
47
47
  UptimeRobot::Monitor::Status::NotCheckedYet
48
48
  else
49
- abort({ stat: "fail",
50
- error: "Task not recognized, must be one of: [pause, start]" }.to_json)
49
+ abort({stat: "fail",
50
+ error: "Task not recognized, must be one of: [pause, start]"}.to_json)
51
51
  end
52
52
  end
53
53
  end
@@ -19,10 +19,10 @@ module UppityRobot
19
19
  ]
20
20
 
21
21
  def call(csv: nil, filter: "{}", search: nil, **)
22
- filter = JSON.parse(filter)
23
- filtered = { stat: "ok", total: 0, monitors: [] }
24
- params = search ? { search: search } : {}
25
- total = 0
22
+ filter = JSON.parse(filter)
23
+ filtered = {stat: "ok", total: 0, monitors: []}
24
+ params = search ? {search: search} : {}
25
+ total = 0
26
26
 
27
27
  UppityRobot::Client.new(:getMonitors, params).filter(filter).each do |m|
28
28
  filtered[:monitors] << m
@@ -33,7 +33,7 @@ module UppityRobot
33
33
  write_csv(csv, filtered[:monitors])
34
34
  puts filtered.to_json
35
35
  rescue JSON::ParserError => e
36
- puts JSON.generate({ stat: "fail", error: "JSON parser #{e.message}" })
36
+ puts JSON.generate({stat: "fail", error: "JSON parser #{e.message}"})
37
37
  end
38
38
 
39
39
  def write_csv(file, data)
@@ -23,11 +23,11 @@ module UppityRobot
23
23
  data = parse_data(format, data)
24
24
  unless data.is_a? Array
25
25
  abort(
26
- { stat: "fail", error: "Data must be an array: #{data.inspect}" }.to_json
26
+ {stat: "fail", error: "Data must be an array: #{data.inspect}"}.to_json
27
27
  )
28
28
  end
29
29
 
30
- updated = { stat: "ok", total: 0, updated: 0, monitors: [], errors: [] }
30
+ updated = {stat: "ok", total: 0, updated: 0, monitors: [], errors: []}
31
31
  data.each do |d|
32
32
  original = d.dup # UptimeRobot::Client modifies `d`, avoid this for errors
33
33
  updated[:total] += 1
@@ -39,15 +39,15 @@ module UppityRobot
39
39
 
40
40
  puts updated.to_json
41
41
  rescue CSV::MalformedCSVError, JSON::ParserError => e
42
- puts JSON.generate({ stat: "fail", error: "Invalid input: #{e.message}" })
42
+ puts JSON.generate({stat: "fail", error: "Invalid input: #{e.message}"})
43
43
  end
44
44
  # rubocop:enable Metrics/AbcSize
45
45
 
46
46
  def check_format(format)
47
47
  return if %w[csv json].include? format
48
48
 
49
- abort({ stat: "fail",
50
- error: "Format not recognized, must be one of: [csv, json]" }.to_json)
49
+ abort({stat: "fail",
50
+ error: "Format not recognized, must be one of: [csv, json]"}.to_json)
51
51
  end
52
52
 
53
53
  def parse_data(format, data)
@@ -62,7 +62,7 @@ module UppityRobot
62
62
  end
63
63
  rows
64
64
  else
65
- abort({ stat: "fail", error: "Error parsing data: #{format}, #{data.inspect}" }.to_json)
65
+ abort({stat: "fail", error: "Error parsing data: #{format}, #{data.inspect}"}.to_json)
66
66
  end
67
67
  end
68
68
  end
@@ -12,8 +12,8 @@ module UppityRobot
12
12
  register "monitors", aliases: ["m"] do |prefix|
13
13
  prefix.register "create", Monitors::Create
14
14
  prefix.register "delete", Monitors::Delete
15
- prefix.register "exec", Monitors::Exec
16
- prefix.register "list", Monitors::List
15
+ prefix.register "exec", Monitors::Exec
16
+ prefix.register "list", Monitors::List
17
17
  prefix.register "update", Monitors::Update
18
18
  end
19
19
  end
@@ -11,9 +11,9 @@ module UppityRobot
11
11
  }.freeze
12
12
 
13
13
  def initialize(task, params)
14
- @client = client
15
- @task = verify_task(task)
16
- @params = params
14
+ @client = client
15
+ @task = verify_task(task)
16
+ @params = params
17
17
  @response = nil
18
18
  end
19
19
 
@@ -40,14 +40,14 @@ module UppityRobot
40
40
  Enumerator.new do |yielder|
41
41
  @params.delete :offset # we want to start from the beginning
42
42
  response = execute # initial connection
43
- offset = 0
44
- limit = response["pagination"]["limit"]
45
- total = response["pagination"]["total"]
43
+ offset = 0
44
+ limit = response["pagination"]["limit"]
45
+ total = response["pagination"]["total"]
46
46
 
47
47
  loop do
48
48
  raise StopIteration if offset >= total
49
49
 
50
- @params = @params.merge({ offset: offset })
50
+ @params = @params.merge({offset: offset})
51
51
  response = execute
52
52
  yielder << [response, offset, total]
53
53
  offset += limit
@@ -67,11 +67,11 @@ module UppityRobot
67
67
  private
68
68
 
69
69
  def client
70
- options = { api_key: ENV.fetch("UPTIMEROBOT_API_KEY") }
70
+ options = {api_key: ENV.fetch("UPTIMEROBOT_API_KEY")}
71
71
  options[:url] = ENV["UPTIMEROBOT_ENDPOINT"] if ENV["UPTIMEROBOT_ENDPOINT"]
72
72
  UptimeRobot::Client.new(options)
73
73
  rescue KeyError => e
74
- abort({ stat: "fail", error: "Error, #{e.message}" }.to_json)
74
+ abort({stat: "fail", error: "Error, #{e.message}"}.to_json)
75
75
  end
76
76
 
77
77
  def parse_total(response)
@@ -82,7 +82,7 @@ module UppityRobot
82
82
  return if @params.key?(:search) || @params.key?(RECORD_TYPES[@task].to_sym)
83
83
 
84
84
  abort(
85
- { stat: "fail", error: "Attempted fetch without required params" }.to_json
85
+ {stat: "fail", error: "Attempted fetch without required params"}.to_json
86
86
  )
87
87
  end
88
88
 
@@ -7,7 +7,7 @@ namespace :uppityrobot do
7
7
  def alert_contacts
8
8
  ENV.fetch("UPTIMEROBOT_ALERT_CONTACTS") do
9
9
  contacts = UppityRobot::Client.new(:getAlertContacts, {}).execute
10
- contact = contacts["alert_contacts"].find { |c| c["friendly_name"] == friendly_name }
10
+ contact = contacts["alert_contacts"].find { |c| c["friendly_name"] == friendly_name }
11
11
  raise "CONTACT NOT FOUND" unless contact
12
12
 
13
13
  contact["id"]
@@ -45,16 +45,16 @@ namespace :uppityrobot do
45
45
  raise "UPTIMEROBOT_API_KEY is required" unless ENV["UPTIMEROBOT_API_KEY"]
46
46
 
47
47
  prefix = args[:prefix]
48
- csv = args.fetch(:csv, File.join(Dir.getwd, "files", "monitors", "uptimerobot.csv"))
48
+ csv = args.fetch(:csv, File.join(Dir.getwd, "files", "monitors", "uptimerobot.csv"))
49
49
  raise "CSV not found" unless File.file? csv
50
50
 
51
- contacts = alert_contacts
51
+ contacts = alert_contacts
52
52
  current_monitors = monitors(prefix: prefix)
53
53
 
54
54
  CSV.read(csv, headers: true).each do |row|
55
- data = row.to_hash
56
- name = data["friendly_name"]
57
- url = data["url"]
55
+ data = row.to_hash
56
+ name = data["friendly_name"]
57
+ url = data["url"]
58
58
  interval = data.fetch("interval", 300)
59
59
 
60
60
  begin
@@ -70,10 +70,10 @@ namespace :uppityrobot do
70
70
  }
71
71
  UppityRobot::Client.new(:newMonitor, d).execute
72
72
  elsif current_monitors.key?(name) &&
73
- (current_monitors[name]["url"] != url || current_monitors[name]["interval"] != interval)
73
+ (current_monitors[name]["url"] != url || current_monitors[name]["interval"] != interval)
74
74
  puts "Updating monitor: #{current_monitors[name]["url"]} TO #{url} [#{interval}] WITH CONTACTS #{contacts}"
75
75
  # avoid uptimerobot client weirdness
76
- d = { id: current_monitors[name]["id"], url: url, interval: interval, alert_contacts: contacts }.dup
76
+ d = {id: current_monitors[name]["id"], url: url, interval: interval, alert_contacts: contacts}.dup
77
77
  UppityRobot::Client.new(:editMonitor, d).execute
78
78
  end
79
79
  rescue UptimeRobot::Error => e
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UppityRobot
4
- VERSION = "0.4.0"
4
+ VERSION = "0.4.1"
5
5
  end
data/uppityrobot.gemspec CHANGED
@@ -3,15 +3,15 @@
3
3
  require_relative "lib/uppityrobot/version"
4
4
 
5
5
  Gem::Specification.new do |spec|
6
- spec.name = "uppityrobot"
7
- spec.version = UppityRobot::VERSION
8
- spec.authors = ["Mark Cooper"]
9
- spec.email = ["mark.c.cooper@outlook.com"]
6
+ spec.name = "uppityrobot"
7
+ spec.version = UppityRobot::VERSION
8
+ spec.authors = ["Mark Cooper"]
9
+ spec.email = ["mark.c.cooper@outlook.com"]
10
10
 
11
- spec.summary = "Command line wrapper for the UptimeRobot API (wrapper)."
12
- spec.description = "Command line wrapper for the UptimeRobot API (wrapper)."
13
- spec.homepage = "https://github.com/lyrasis/uppityrobot.git"
14
- spec.license = "MIT"
11
+ spec.summary = "Command line wrapper for the UptimeRobot API (wrapper)."
12
+ spec.description = "Command line wrapper for the UptimeRobot API (wrapper)."
13
+ spec.homepage = "https://github.com/lyrasis/uppityrobot.git"
14
+ spec.license = "MIT"
15
15
  spec.required_ruby_version = ">= 2.7.0"
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
@@ -20,8 +20,8 @@ Gem::Specification.new do |spec|
20
20
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
21
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
22
22
  end
23
- spec.bindir = "exe"
24
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
25
25
  spec.require_paths = ["lib"]
26
26
 
27
27
  spec.add_dependency "dry-cli", "~> 0.7"
@@ -37,5 +37,6 @@ Gem::Specification.new do |spec|
37
37
  spec.add_development_dependency "rspec", "~> 3.2"
38
38
  spec.add_development_dependency "rubocop", "~> 1.7"
39
39
  spec.add_development_dependency "sinatra"
40
+ spec.add_development_dependency "standard"
40
41
  spec.add_development_dependency "webmock"
41
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uppityrobot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Cooper
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-19 00:00:00.000000000 Z
11
+ date: 2022-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-cli
@@ -178,6 +178,20 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
+ - !ruby/object:Gem::Dependency
182
+ name: standard
183
+ requirement: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ type: :development
189
+ prerelease: false
190
+ version_requirements: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
181
195
  - !ruby/object:Gem::Dependency
182
196
  name: webmock
183
197
  requirement: !ruby/object:Gem::Requirement
@@ -257,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
257
271
  - !ruby/object:Gem::Version
258
272
  version: '0'
259
273
  requirements: []
260
- rubygems_version: 3.3.18
274
+ rubygems_version: 3.3.26
261
275
  signing_key:
262
276
  specification_version: 4
263
277
  summary: Command line wrapper for the UptimeRobot API (wrapper).