cronitor 1.1.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -2
- data/cronitor.gemspec +2 -5
- data/lib/cronitor.rb +54 -34
- data/lib/cronitor/version.rb +1 -1
- metadata +7 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 67371ddbb668fc2c736994aadb6b1610bd807aa4
|
4
|
+
data.tar.gz: 22381ccb4ee4157fe32c3d518642976aa58a63d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fde7ed9489dd3b82435766ed0013dcef88fb2fe7f67ecca2e3cd7d954c3fff2c164df8e5af2a9b59343b5587c5d287df4a229968d1b4d306ea916605b81a0329
|
7
|
+
data.tar.gz: 0e342c25712223f1b1f8e67c11b606bf75369a494c00f0bd3aacb6bc0c87272b8b6b44f5b2e0f81d5613779eabdaf95289716a0e2d639f20ba2e0453c252cad3
|
data/.travis.yml
CHANGED
data/cronitor.gemspec
CHANGED
@@ -18,14 +18,11 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'unirest', '~> 1.1'
|
22
|
-
spec.add_dependency 'hashie', '~> 3.4'
|
23
|
-
|
24
21
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
25
22
|
spec.add_development_dependency 'rake', '~> 10.0'
|
26
23
|
spec.add_development_dependency 'rspec', '~> 3.3'
|
27
24
|
spec.add_development_dependency 'pry', '~> 0.10'
|
28
|
-
spec.add_development_dependency 'webmock', '~> 1
|
29
|
-
spec.add_development_dependency 'sinatra', '~>
|
25
|
+
spec.add_development_dependency 'webmock', '~> 3.1'
|
26
|
+
spec.add_development_dependency 'sinatra', '~> 2.0'
|
30
27
|
spec.add_development_dependency 'bump', '~> 0.1'
|
31
28
|
end
|
data/lib/cronitor.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
require 'cronitor/version'
|
2
2
|
require 'cronitor/error'
|
3
|
+
require 'json'
|
3
4
|
require 'net/http'
|
4
|
-
require '
|
5
|
-
require 'hashie'
|
5
|
+
require 'uri'
|
6
6
|
|
7
7
|
class Cronitor
|
8
8
|
attr_accessor :token, :opts, :code
|
9
9
|
API_URL = 'https://cronitor.io/v1'.freeze
|
10
10
|
PING_URL = 'https://cronitor.link'.freeze
|
11
11
|
|
12
|
-
def initialize(token:
|
12
|
+
def initialize(token: ENV['CRONITOR_TOKEN'], opts: {}, code: nil)
|
13
13
|
@token = token
|
14
14
|
@opts = opts
|
15
15
|
@code = code
|
@@ -23,7 +23,7 @@ class Cronitor
|
|
23
23
|
end
|
24
24
|
|
25
25
|
if @opts
|
26
|
-
|
26
|
+
@opts = symbolize_keys @opts
|
27
27
|
exists? @opts[:name] if @opts.key? :name
|
28
28
|
human_readable @opts[:rules] if @opts.key? :rules
|
29
29
|
end
|
@@ -32,34 +32,52 @@ class Cronitor
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def create
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
35
|
+
uri = URI.parse "#{API_URL}/monitors"
|
36
|
+
|
37
|
+
http = Net::HTTP.new uri.host, uri.port
|
38
|
+
http.use_ssl = uri.scheme == 'https'
|
39
|
+
|
40
|
+
request = Net::HTTP::Post.new uri.path, default_headers
|
41
|
+
request.basic_auth token, nil
|
42
|
+
request.content_type = 'application/json'
|
43
|
+
request.body = JSON.generate opts
|
44
|
+
|
45
|
+
response = http.request request
|
46
|
+
|
47
|
+
@code = JSON.parse(response.body).fetch 'code' if valid? response
|
43
48
|
end
|
44
49
|
|
45
50
|
def exists?(name)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
)
|
51
|
-
return false unless response.code == 200
|
51
|
+
uri = URI.parse "#{API_URL}/monitors/#{URI.escape name}"
|
52
|
+
|
53
|
+
http = Net::HTTP.new uri.host, uri.port
|
54
|
+
http.use_ssl = uri.scheme == 'https'
|
52
55
|
|
53
|
-
|
56
|
+
request = Net::HTTP::Get.new uri.path, default_headers
|
57
|
+
request.basic_auth token, nil
|
58
|
+
|
59
|
+
response = http.request request
|
60
|
+
|
61
|
+
return false unless response.is_a? Net::HTTPSuccess
|
62
|
+
|
63
|
+
@code = JSON.parse(response.body).fetch 'code'
|
54
64
|
|
55
65
|
true
|
56
66
|
end
|
57
67
|
|
58
68
|
def ping(type, msg = nil)
|
59
|
-
|
60
|
-
|
69
|
+
uri = URI.parse "#{PING_URL}/#{URI.escape code}/#{URI.escape type}"
|
70
|
+
if %w[run complete fail].include?(type) && !msg.nil?
|
71
|
+
uri.query = URI.encode_www_form 'msg' => msg
|
72
|
+
end
|
73
|
+
|
74
|
+
http = Net::HTTP.new uri.host, uri.port
|
75
|
+
http.use_ssl = uri.scheme == 'https'
|
76
|
+
|
77
|
+
request = Net::HTTP::Get.new uri, default_headers
|
78
|
+
|
79
|
+
response = http.request request
|
61
80
|
|
62
|
-
response = Unirest.get url
|
63
81
|
valid? response
|
64
82
|
end
|
65
83
|
|
@@ -75,10 +93,15 @@ class Cronitor
|
|
75
93
|
private
|
76
94
|
|
77
95
|
def valid?(response)
|
78
|
-
return true if
|
79
|
-
|
96
|
+
return true if response.is_a? Net::HTTPSuccess
|
97
|
+
|
98
|
+
msg = if response.content_type.match? 'json'
|
99
|
+
error_msg JSON.parse(response.body)
|
100
|
+
else
|
101
|
+
"Something else has gone awry. HTTP status: #{response.code}"
|
102
|
+
end
|
80
103
|
|
81
|
-
raise Cronitor::Error,
|
104
|
+
raise Cronitor::Error, msg
|
82
105
|
end
|
83
106
|
|
84
107
|
def error_msg(body, msg = [])
|
@@ -95,16 +118,13 @@ class Cronitor
|
|
95
118
|
msg.join ' '
|
96
119
|
end
|
97
120
|
|
98
|
-
def server_error?(response)
|
99
|
-
return unless [301, 302, 404, 500, 502, 503, 504].include? response.code
|
100
|
-
|
101
|
-
raise(
|
102
|
-
Cronitor::Error,
|
103
|
-
"Something else has gone awry. HTTP status: #{response.code}"
|
104
|
-
)
|
105
|
-
end
|
106
|
-
|
107
121
|
def default_headers
|
108
122
|
{ 'Accept' => 'application/json' }
|
109
123
|
end
|
124
|
+
|
125
|
+
def symbolize_keys(hash)
|
126
|
+
hash.each_with_object({}) do |(k, v), h|
|
127
|
+
h[k.to_sym] = v.is_a?(Hash) ? symbolize_keys(v) : v
|
128
|
+
end
|
129
|
+
end
|
110
130
|
end
|
data/lib/cronitor/version.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cronitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Byrnes
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: unirest
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.1'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.1'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: hashie
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.4'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '3.4'
|
41
13
|
- !ruby/object:Gem::Dependency
|
42
14
|
name: bundler
|
43
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,28 +72,28 @@ dependencies:
|
|
100
72
|
requirements:
|
101
73
|
- - "~>"
|
102
74
|
- !ruby/object:Gem::Version
|
103
|
-
version: '1
|
75
|
+
version: '3.1'
|
104
76
|
type: :development
|
105
77
|
prerelease: false
|
106
78
|
version_requirements: !ruby/object:Gem::Requirement
|
107
79
|
requirements:
|
108
80
|
- - "~>"
|
109
81
|
- !ruby/object:Gem::Version
|
110
|
-
version: '1
|
82
|
+
version: '3.1'
|
111
83
|
- !ruby/object:Gem::Dependency
|
112
84
|
name: sinatra
|
113
85
|
requirement: !ruby/object:Gem::Requirement
|
114
86
|
requirements:
|
115
87
|
- - "~>"
|
116
88
|
- !ruby/object:Gem::Version
|
117
|
-
version: '
|
89
|
+
version: '2.0'
|
118
90
|
type: :development
|
119
91
|
prerelease: false
|
120
92
|
version_requirements: !ruby/object:Gem::Requirement
|
121
93
|
requirements:
|
122
94
|
- - "~>"
|
123
95
|
- !ruby/object:Gem::Version
|
124
|
-
version: '
|
96
|
+
version: '2.0'
|
125
97
|
- !ruby/object:Gem::Dependency
|
126
98
|
name: bump
|
127
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
148
|
version: '0'
|
177
149
|
requirements: []
|
178
150
|
rubyforge_project:
|
179
|
-
rubygems_version: 2.6.
|
151
|
+
rubygems_version: 2.6.13
|
180
152
|
signing_key:
|
181
153
|
specification_version: 4
|
182
154
|
summary: An interface for the Cronitor API
|