opsgenie-heartbeat 0.1.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 90ab82ef80b3460608df4482d3cfec7854abe08d
4
- data.tar.gz: 860eef58b7f9ee13b7e4ed72734ac938987e878d
2
+ SHA256:
3
+ metadata.gz: da1c834d20e5005f05c6d801a5bd4f9dac5863731ff2955e797a03df77d0d84d
4
+ data.tar.gz: c289500bca6f19798e742f8a195fefc67b85836235e1f7f45fd8abfe645c24b8
5
5
  SHA512:
6
- metadata.gz: dd2e2930a0a5b714580839cdf235f27794e2d52175a643dc08a564ef9cb960f5213d790fe982517158eb7d98d199318d90e2797cfc4734eae6385fdb38d056d8
7
- data.tar.gz: 5d6dae499406c7c1f2e713c74ab8099e60059f6f55090ae48c251d5501c52b08ba417864a5e79315a1fa60c6246e0d8a81bc5ad314a873dc70712e1ffc0479c3
6
+ metadata.gz: 3a37ca5d1f7f334b01168188a2b250f726dd043489b4a77dcc9d495990256c426fabdd83d37300fc1cd7e7b907b0609d652ba133d14d01c56ff845bfa8b64cac
7
+ data.tar.gz: 34bdfde8fa03e238692ddc8b3cdfc0c77389637008a23e67dcaab13b177c37f4cf71787ef4cd901e74b1f2ffd5305d30bee9b50aa2b93d5260869693ade50654
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
1
  --format documentation
2
2
  --color
3
- --warnings
@@ -1,7 +1,14 @@
1
- Updates in version 0.1.1:
1
+ ## Updates in version 0.2.0:
2
2
 
3
- No need to supply name_transformer in initializer file unless wanted.
4
- Now there is default value -> name itself.
3
+ - Allow updating of heartbeats
4
+ - Allow setting of team
5
5
 
6
- Updates in version 0.1.2:
7
- Instead of require 'opsgenie/heartbeat/heartbeat' now is require 'opsgenie/heartbeat'
6
+
7
+ ##Updates in version 0.1.2:
8
+
9
+ - Instead of require 'opsgenie/heartbeat/heartbeat' now is require 'opsgenie/heartbeat'
10
+
11
+ ## Updates in version 0.1.1:
12
+
13
+ - No need to supply name_transformer in initializer file unless wanted.
14
+ - Now there is default value -> name itself.
@@ -6,75 +6,96 @@ require 'rack'
6
6
 
7
7
  module Opsgenie
8
8
  module Heartbeat
9
+ class << self
10
+ def pulse(name)
11
+ return unless configuration.enabled
12
+ name = configuration.name_transformer.call(name)
13
+ begin
14
+ uri = URI.parse("https://api.opsgenie.com/v2/heartbeats/#{Rack::Utils.escape name}/ping")
15
+ http = Net::HTTP.new(uri.host, uri.port)
16
+ http.use_ssl = true
17
+ data = {name: name}
18
+ http.post(uri.path, data.to_json, {'Authorization': "GenieKey #{configuration.api_key}", "Content-Type": "application/json"})
19
+ rescue => e
20
+ resolve_exception e
21
+ end
22
+ end
23
+
24
+ def ensure(name:, interval:, unit: , description:, enabled: true, team: nil)
25
+ return unless configuration.enabled
26
+ original_name = name
27
+ name = configuration.name_transformer.call(name)
9
28
 
10
- def self.pulse(name)
11
- return unless configuration.enabled
12
- name = configuration.name_transformer.call(name)
13
- begin
14
- uri = URI.parse("https://api.opsgenie.com/v2/heartbeats/#{Rack::Utils.escape name}/ping")
29
+ uri = URI.parse(url_for_resource(:get, name))
15
30
  http = Net::HTTP.new(uri.host, uri.port)
16
31
  http.use_ssl = true
17
- data = {name: name}
18
- http.post(uri.path, data.to_json, {'Authorization': "GenieKey #{configuration.api_key}", "Content-Type": "application/json"})
19
- rescue => e
20
- resolve_exception e
32
+ response = http.get(uri.path)
33
+ unless response.is_a?(Net::HTTPSuccess)
34
+ create(name: original_name, description: description, interval: interval, unit: unit, enabled: enabled, team: team)
35
+ end
21
36
  end
22
- end
23
37
 
24
- def self.ensure(name:, interval:, unit: , description:, enabled: true)
25
- return unless configuration.enabled
26
- original_name = name
27
- name = configuration.name_transformer.call(name)
38
+ def delete(name)
39
+ return unless configuration.enabled
40
+ name = configuration.name_transformer.call(name)
28
41
 
29
- uri = URI.parse("https://api.opsgenie.com/v2/heartbeats/#{Rack::Utils.escape name}")
30
- http = Net::HTTP.new(uri.host, uri.port)
31
- http.use_ssl = true
32
- response = http.get(uri.path)
33
- unless response.is_a?(Net::HTTPSuccess)
34
- create(name: original_name, description: description, interval: interval, unit: unit, enabled: enabled)
35
- end
36
- end
42
+ begin
43
+ uri = URI.parse(url_for_resource(:delete, name))
44
+ http = Net::HTTP.new(uri.host, uri.port)
45
+ http.use_ssl = true
37
46
 
38
- def self.delete(name)
39
- return unless configuration.enabled
40
- name = configuration.name_transformer.call(name)
47
+ http.delete(uri.path, {'Authorization': "GenieKey #{configuration.api_key}", "Content-Type": "application/json"})
48
+ rescue => e
49
+ resolve_exception e
50
+ end
51
+ end
41
52
 
42
- begin
43
- uri = URI.parse("https://api.opsgenie.com/v2/heartbeats/#{Rack::Utils.escape name}")
44
- http = Net::HTTP.new(uri.host, uri.port)
45
- http.use_ssl = true
53
+ def update(name:, interval: nil, unit: nil, description: nil, enabled: nil, team: nil)
54
+ return unless configuration.enabled
55
+ create_or_update(:patch, name: name, description: description, interval: interval, unit: unit, enabled: enabled, team: team)
56
+ end
46
57
 
47
- http.delete(uri.path, {'Authorization': "GenieKey #{configuration.api_key}", "Content-Type": "application/json"})
48
- rescue => e
49
- resolve_exception e
58
+ def create(name:, interval: nil, unit: nil, description: nil, enabled: nil, team: nil)
59
+ return unless configuration.enabled
60
+ create_or_update(:post, name: name, description: description, interval: interval, unit: unit, enabled: enabled, team: team)
50
61
  end
51
- end
52
62
 
53
- private
54
63
 
55
- def self.create(name:,description:,interval:,unit:, enabled:)
56
- name = configuration.name_transformer.call(name)
64
+ private
57
65
 
58
- begin
59
- uri = URI.parse('https://api.opsgenie.com/v2/heartbeats')
60
- http = Net::HTTP.new(uri.host, uri.port)
61
- http.use_ssl = true
62
- doc = {
63
- name: name,
64
- description: description,
65
- interval: interval,
66
- intervalUnit: unit,
67
- enabled: enabled
68
- }
69
- http.post(uri.path, doc.to_json, {'Authorization': "GenieKey #{configuration.api_key}", "Content-Type": "application/json"})
70
- rescue => e
71
- resolve_exception e
66
+ def url_for_resource(verb, name)
67
+ if verb == :post
68
+ 'https://api.opsgenie.com/v2/heartbeats'
69
+ else
70
+ "https://api.opsgenie.com/v2/heartbeats/#{Rack::Utils.escape name}"
71
+ end
72
72
  end
73
- end
74
73
 
75
- def self.resolve_exception e
76
- configuration.logger.info("Exception raised during heartbeat: #{e.message} #{e.backtrace}") if configuration.logger
77
- raise if configuration.raise_error
74
+ def create_or_update(verb, name:,description:,interval:,unit:, enabled:, team:)
75
+ name = configuration.name_transformer.call(name)
76
+
77
+ begin
78
+ uri = URI.parse(url_for_resource(verb, name))
79
+ http = Net::HTTP.new(uri.host, uri.port)
80
+ http.use_ssl = true
81
+ doc = {
82
+ name: name,
83
+ description: description,
84
+ interval: interval,
85
+ intervalUnit: unit,
86
+ enabled: enabled,
87
+ ownerTeam: team
88
+ }.reject {|_, value| value.nil?}
89
+ http.public_send(verb, uri.path, doc.to_json, {'Authorization': "GenieKey #{configuration.api_key}", "Content-Type": "application/json"})
90
+ rescue => e
91
+ resolve_exception e
92
+ end
93
+ end
94
+
95
+ def resolve_exception e
96
+ configuration.logger.info("Exception raised during heartbeat: #{e.message} #{e.backtrace}") if configuration.logger
97
+ raise if configuration.raise_error
98
+ end
78
99
  end
79
100
  end
80
101
  end
@@ -1,5 +1,5 @@
1
1
  module Opsgenie
2
2
  module Heartbeat
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opsgenie-heartbeat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dressipi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-09-07 00:00:00.000000000 Z
11
+ date: 2018-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -96,7 +96,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
96
96
  version: '0'
97
97
  requirements: []
98
98
  rubyforge_project:
99
- rubygems_version: 2.5.2
99
+ rubygems_version: 2.7.3
100
100
  signing_key:
101
101
  specification_version: 4
102
102
  summary: OpsGenie Heartbeat version 2