cronitor 5.2.2 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2db87030650711fcc3d7c2cd27bc3621b5c4d236ed7b56e5ef5cd1e741b552ba
4
- data.tar.gz: 1b842d3a3afacbdb7a4616678104f0733e4dba902615c5e3db347a1e152b4bb6
3
+ metadata.gz: d786e1bcc6b048371b5a9ef9e2c9d4d0db9a7e8d65f30cfd1029cbd3409f9e0e
4
+ data.tar.gz: df00a0cfe1cd458146b892b145b2919caf51f384dbe4c89348a6f03b3afa4a83
5
5
  SHA512:
6
- metadata.gz: 1a8c6c3f4dac4a77d3833e4886eabe94f5e35da907647fdc06dfe0f60648fd234e4597417f4bbfb74d97da176f9cb6f8482b52ac2eb23c43efa7f49420ebea6d
7
- data.tar.gz: 91a365a74dceada5417865aa7d577ebc40cc12c22549d37d067c288a25507fb4b1df233f66772822b724ff1eddba73098e91d6a03ee5a7597e8edcb1e89d86c6
6
+ metadata.gz: aaf140a231580c70c6653795e4530f792384602e9c1c5ee6da3cc4da4de2f55fa73d4bdb920af72448be5dcce75963a68f2b3e660593334f64482d05198a8d18
7
+ data.tar.gz: 4b530de67e7d3f2fbb86fece1a9cdae10a01456d6707a9c4d92f76a09004bc0c9a1a907c665fb6e62006a13b3e5394f41b44946e6cc853754330fdb16a4500b3
@@ -77,6 +77,35 @@ module Cronitor
77
77
  end
78
78
  end
79
79
 
80
+ def self.as_yaml(api_key: nil, api_version: nil)
81
+ timeout = Cronitor.timeout || 10
82
+ api_key = api_key || Cronitor.api_key
83
+
84
+ unless api_key
85
+ raise Error.new('No API key detected. Set Cronitor.api_key or pass api_key parameter')
86
+ end
87
+
88
+ headers = Cronitor::Monitor::Headers::YAML.dup
89
+ headers[:'Cronitor-Version'] = api_version if api_version
90
+
91
+ resp = HTTParty.get(
92
+ "#{MONITOR_API_URL}.yaml",
93
+ basic_auth: {
94
+ username: api_key,
95
+ password: ''
96
+ },
97
+ headers: headers,
98
+ timeout: timeout
99
+ )
100
+
101
+ case resp.code
102
+ when 200
103
+ resp.body
104
+ else
105
+ raise Error.new("Unexpected error #{resp.code}: #{resp.body}")
106
+ end
107
+ end
108
+
80
109
  def delete
81
110
  resp = HTTParty.delete(
82
111
  "#{monitor_api_url}/#{key}",
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cronitor
4
- VERSION = '5.2.2'
4
+ VERSION = '5.3.0'
5
5
  end
data/lib/cronitor.rb CHANGED
@@ -49,6 +49,17 @@ module Cronitor
49
49
  apply_config(rollback: true)
50
50
  end
51
51
 
52
+ def self.generate_config(path = nil)
53
+ config_path = path || Cronitor.config || './cronitor.yaml'
54
+ yaml_content = Monitor.as_yaml
55
+
56
+ File.open(config_path, 'w') do |file|
57
+ file.write(yaml_content)
58
+ end
59
+
60
+ puts("Configuration saved to #{config_path}")
61
+ end
62
+
52
63
  def self.job(key, &block)
53
64
  monitor = Monitor.new(key)
54
65
  series = Time.now.to_f
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cronitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.2
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Byrnes