Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ monitor = Cronitor::Monitor.new('heartbeat-monitor')
monitor.pause(24) # pause alerting for 24 hours
monitor.unpause # alias for .pause(0)
monitor.ok # manually reset to a passing state alias for monitor.ping({state: ok})
monitor.delete # destroy the monitor
Cronitor::Monitor.delete('heartbeat-monitor') # destroy the monitor
```

## Package Configuration
Expand Down
14 changes: 5 additions & 9 deletions lib/cronitor/monitor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Monitor
attr_reader :key, :api_key, :api_version, :env

PING_RETRY_THRESHOLD = 3
API_URL = 'https://cronitor.io/api/monitors'.freeze
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a need to make this configurable? Something for internal testing/usage for example.


module Formats
ALL = [
Expand All @@ -30,7 +31,7 @@ def self.put(opts = {})
opts.delete(:rollback)

monitors = opts[:monitors] || [opts]
url = "https://cronitor.io/api/monitors"
url = Cronitor::Monitor::API_URL
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works in this class method because the string is hardcoded in here.

if opts[:format] == Cronitor::Monitor::Formats::YAML
url = "#{url}.yaml"
monitors['rollback'] = true if rollback
Expand Down Expand Up @@ -79,7 +80,7 @@ def self.put(opts = {})

def self.delete(key)
resp = HTTParty.delete(
"#{Cronitor.monitor_api_url}/#{key}",
"#{Cronitor::Monitor::API_URL}/#{key}",
timeout: Cronitor.timeout,
basic_auth: {
username: Cronitor.api_key,
Expand Down Expand Up @@ -158,7 +159,7 @@ def ok
end

def pause(hours = nil)
pause_url = "#{monitor_api_url}/#{key}/pause"
pause_url = "#{Cronitor::Monitor::API_URL}/#{key}/pause"
pause_url += "/#{hours}" unless hours.nil?

resp = HTTParty.get(
Expand Down Expand Up @@ -186,11 +187,6 @@ def fallback_ping_api_url
"https://cronitor.io/p/#{api_key}/#{key}"
end

def monitor_api_url
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed since instance and class methods now just utilize the constant.

"https://cronitor.io/api/monitors"
end


private

def fetch
Expand All @@ -202,7 +198,7 @@ def fetch
end

HTTParty.get(
monitor_api_url,
Cronitor::Monitor::API_URL,
basic_auth: {
username: api_key,
password: ''
Expand Down
Loading