cronitor 0.1.0 → 0.2.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 +4 -4
- data/lib/cronitor.rb +15 -9
- data/lib/cronitor/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 66fc4f90a580d921f2ccf33198de4a56e535a1bb
|
4
|
+
data.tar.gz: c8b2c3ac8a1f17a9313ad4b2e058b64825fb1a74
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06318c62b1c8d73a08a89b3c9606a19df6b11430cbbda104f05b8e4ce5f9ab71d2377deb82cb6a2357d1fc68db24ffc336bc6839c21979ffbf757498add34552
|
7
|
+
data.tar.gz: a56512e5daf6733ee8580f81c587beaf7b17aaed36b97692bc81dafb6ed9efe1552143c8f5a78e038208fe0d5293350e2124e70a2eceaebc781f69fca3f0a562
|
data/lib/cronitor.rb
CHANGED
@@ -9,6 +9,7 @@ Unirest.default_header 'Content-Type', 'application/json'
|
|
9
9
|
class Cronitor
|
10
10
|
attr_accessor :token, :opts, :code
|
11
11
|
API_URL = 'https://cronitor.io/v1'
|
12
|
+
PING_URL = 'https://cronitor.link'
|
12
13
|
|
13
14
|
def initialize(token: nil, opts: {}, code: nil)
|
14
15
|
@token = token
|
@@ -29,22 +30,27 @@ class Cronitor
|
|
29
30
|
parameters: opts.to_json
|
30
31
|
)
|
31
32
|
|
32
|
-
|
33
|
-
@code = response.body['code']
|
33
|
+
@code = response.body['code'] if valid? response
|
34
34
|
end
|
35
35
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
36
|
+
def ping(type, msg = nil)
|
37
|
+
url = "#{PING_URL}/#{code}/#{type}"
|
38
|
+
url += "?msg=#{URI.escape msg}" if type == 'fail' && !msg.nil?
|
39
39
|
|
40
|
-
|
40
|
+
response = Unirest.get url
|
41
|
+
valid? response
|
41
42
|
end
|
42
43
|
|
43
44
|
private
|
44
45
|
|
45
|
-
def
|
46
|
-
|
46
|
+
def valid?(response)
|
47
|
+
return true if [200, 201].include? response.code
|
48
|
+
server_error? response
|
49
|
+
|
50
|
+
fail Cronitor::Error, error_msg(response.body)
|
51
|
+
end
|
47
52
|
|
53
|
+
def error_msg(body, msg = [])
|
48
54
|
body.each do |opt, value|
|
49
55
|
if value.respond_to? 'each'
|
50
56
|
value.each do |error_msg|
|
@@ -59,7 +65,7 @@ class Cronitor
|
|
59
65
|
end
|
60
66
|
|
61
67
|
def server_error?(response)
|
62
|
-
return unless [301, 302, 500, 502, 503, 504].include? response.code
|
68
|
+
return unless [301, 302, 404, 500, 502, 503, 504].include? response.code
|
63
69
|
|
64
70
|
fail(
|
65
71
|
Cronitor::Error,
|
data/lib/cronitor/version.rb
CHANGED