cronitor 0.1.0 → 0.2.0

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
  SHA1:
3
- metadata.gz: c1325aef8ddc179aaa172908cfce6f00fe3f4fa6
4
- data.tar.gz: ac5be4a04f28f3adf09ea31df6e19f0c38aad83e
3
+ metadata.gz: 66fc4f90a580d921f2ccf33198de4a56e535a1bb
4
+ data.tar.gz: c8b2c3ac8a1f17a9313ad4b2e058b64825fb1a74
5
5
  SHA512:
6
- metadata.gz: 7ce111c27528f60d5bee4eba5022cd53b7a9c3c0850a5912e321135a1dd8d021f44b06b93c8b5815c27dc1762e7e5c30fb3a940a308d78e987899dc54e5759e3
7
- data.tar.gz: ed7571b3ba8bddba5fdf3c9a5c6067b1f370ce1965dcb17a8ebb2e8b35280e8524332004c4e1b8cfe6f509f26e812e31a54482c223b6b294743b2250084b1008
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
- validate response
33
- @code = response.body['code']
33
+ @code = response.body['code'] if valid? response
34
34
  end
35
35
 
36
- def validate(response)
37
- return if response.code == 200
38
- server_error? response
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
- fail Cronitor::Error, error_msg(response.body)
40
+ response = Unirest.get url
41
+ valid? response
41
42
  end
42
43
 
43
44
  private
44
45
 
45
- def error_msg(body)
46
- msg = []
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,
@@ -1,3 +1,3 @@
1
1
  class Cronitor
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
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: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Byrnes