mackerel-client 0.11.0 → 0.12.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
  SHA256:
3
- metadata.gz: 68b096795c66861001227bf41e3cb6a7b940306dc404b555691a239031fd8fd6
4
- data.tar.gz: e6516bd4b135f946b3198e5971fca264cfb3e66d8d35e695d5c49773252bb4b9
3
+ metadata.gz: 0b8f49f34db204737703ca6814bca0b82f66360060ef9658c31c9937189027a7
4
+ data.tar.gz: f5f98e1939a2f69794cb43dafb5fb8fd8e21f2784904cbfb8d97b754f8f32857
5
5
  SHA512:
6
- metadata.gz: dd58f6dae6a96848018b4cdd5ba2686bb0ce96f4c521465f782dd45a016c6def438e90b7646a357bc5f93a5905f3e561bcf504124956205c54d9f03543495146
7
- data.tar.gz: 1640a65f29e6641551769642cac689a3e7c1b9d497bb5ee0b33da1c6081c1083bed6c6dc4b225727f95c2ca4d74de6ea66bdf9eade658fb692c43fe6896ac3ee
6
+ metadata.gz: e120aac91332700d0ef14137b699bef524755c9a8c876bc675486865fd84a50eff070a19da00df18d79dc77e2a2dfbe814a7c3f55ca8fbd0b02423b7b4ab8f1a
7
+ data.tar.gz: 14a98ef43f4431615b7f2141a54790c5c4177d9126542fd42acffe6ce3d6bc3af05e8cecb95fd2958ee792f6e8a87d868f27643102d40d177b8e923eb2e324bd
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.12.0 (2021-12-15)
4
+
5
+ * Add get_alert to Alert API #65 (inommm, pyto86)
6
+ * Send query parameters to alerts api #64 (kenchan)
7
+
3
8
  ## v0.11.0 (2021-03-24)
4
9
 
5
10
  * Implements downtime API #61 (myoan)
data/RELEASE.md CHANGED
@@ -1,10 +1,10 @@
1
1
  RELEASE
2
2
  =======
3
3
 
4
- 1. Create release branch. (`git checkout -b version-<VERSION>`)
4
+ 1. Create release branch. (`git switch -c version-<VERSION>`)
5
5
  1. Bump version `VERSION` and `lib/mackerel/version.rb` files.
6
6
  1. Write changes in CHANGELOG.md
7
7
  1. Push release branch to upstream(GitHub). (`git push -u origin version-<VERSION>`)
8
- 1. Create Pull-Request on Github.
9
- 1. Merge Pull-Request to master branch on Github.
8
+ 1. Create Pull-Request on GitHub.
9
+ 1. Merge Pull-Request to master branch on GitHub.
10
10
  1. Tagging and Release. (`rake release`)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.0
1
+ 0.12.0
@@ -31,12 +31,21 @@ module Mackerel
31
31
 
32
32
  module REST
33
33
  module Alert
34
- def get_alerts()
34
+ def get_alerts(opts = {})
35
35
  command = ApiCommand.new(:get, "/api/v0/alerts", @api_key)
36
+ command.params['withClosed'] = opts[:with_closed] if opts[:with_closed]
37
+ command.params['nextId'] = opts[:next_id] if opts[:next_id]
38
+ command.params['limit'] = opts[:limit] if opts[:limit]
36
39
  data = command.execute(client)
37
40
  data["alerts"].map { |a| Mackerel::Alert.new(a) }
38
41
  end
39
42
 
43
+ def get_alert(alert_id)
44
+ command = ApiCommand.new(:get, "/api/v0/alerts/#{alert_id}", @api_key)
45
+ data = command.execute(client)
46
+ Mackerel::Alert.new(data)
47
+ end
48
+
40
49
  def close_alert(alertId, reason)
41
50
  command = ApiCommand.new(:post, "/api/v0/alerts/#{alertId}/close", @api_key)
42
51
  command.body = { reason: reason.to_s }.to_json
@@ -1,3 +1,3 @@
1
1
  module Mackerel
2
- VERSION = "0.11.0"
2
+ VERSION = "0.12.0"
3
3
  end
@@ -11,15 +11,6 @@ RSpec.describe Mackerel::Client do
11
11
  ]
12
12
  }
13
13
 
14
- let(:test_client) {
15
- Faraday.new do |builder|
16
- builder.response :raise_error
17
- builder.adapter :test do |stubs|
18
- stubs.get(api_path) { stubbed_response }
19
- end
20
- end
21
- }
22
-
23
14
  let(:api_path) { '/api/v0/alerts' }
24
15
 
25
16
  let(:alertId) { 'abcdefg' }
@@ -42,16 +33,98 @@ RSpec.describe Mackerel::Client do
42
33
  { 'alerts' => alerts }
43
34
  }
44
35
 
36
+ context 'no parameters' do
37
+ let(:test_client) {
38
+ Faraday.new do |builder|
39
+ builder.response :raise_error
40
+ builder.adapter :test do |stubs|
41
+ stubs.get(api_path) { stubbed_response }
42
+ end
43
+ end
44
+ }
45
+
46
+ before do
47
+ allow(client).to receive(:http_client).and_return(test_client)
48
+ end
49
+
50
+ it "successfully get alerts" do
51
+ expect(client.get_alerts().map(&:to_h)).to eq(alerts)
52
+ end
53
+ end
54
+
55
+ context 'with parameters' do
56
+ let(:with_closed) { true }
57
+ let(:next_id) { alertId }
58
+ let(:limit) { 100 }
59
+
60
+ let(:test_client) {
61
+ Faraday.new do |builder|
62
+ builder.response :raise_error
63
+ builder.adapter :test do |stubs|
64
+ stubs.get("#{api_path}?limit=#{limit}&nextId=#{next_id}&withClosed=#{with_closed}") { stubbed_response }
65
+ end
66
+ end
67
+ }
68
+
69
+ before do
70
+ allow(client).to receive(:http_client).and_return(test_client)
71
+ end
72
+
73
+ it "successfully get alerts" do
74
+ expect(
75
+ client.get_alerts(with_closed: with_closed, next_id: next_id, limit: limit).map(&:to_h)
76
+ ).to eq(alerts)
77
+ end
78
+ end
79
+ end
80
+
81
+ describe '#get_alert' do
82
+ let(:stubbed_response) {
83
+ [
84
+ 200,
85
+ {},
86
+ JSON.dump(response_object)
87
+ ]
88
+ }
89
+
90
+ let(:test_client) {
91
+ Faraday.new do |builder|
92
+ builder.response :raise_error
93
+ builder.adapter :test do |stubs|
94
+ stubs.get(api_path) { stubbed_response }
95
+ end
96
+ end
97
+ }
98
+
99
+ let(:api_path) { "/api/v0/alerts/#{alert_id}" }
100
+ let(:alert_id) { 'abcdefg' }
101
+ let(:monitor_id) { 'hijklmnopqr' }
102
+ let(:reason) { 'Nantonaku' }
103
+
104
+ let(:alert) {
105
+ {
106
+ 'id' => alert_id,
107
+ 'status' => 'OK',
108
+ 'reason' => reason,
109
+ 'monitorId' => monitor_id,
110
+ 'type' => 'check',
111
+ 'openedAt' => 1234567890
112
+ }
113
+ }
114
+
115
+ let(:response_object) {
116
+ alert
117
+ }
118
+
45
119
  before do
46
120
  allow(client).to receive(:http_client).and_return(test_client)
47
121
  end
48
122
 
49
- it "successfully get alerts" do
50
- expect(client.get_alerts().map(&:to_h)).to eq(alerts)
123
+ it "successfully get alert" do
124
+ expect(client.get_alert(alert_id).to_h).to eq(response_object)
51
125
  end
52
126
  end
53
127
 
54
-
55
128
  describe '#close_alert' do
56
129
  let(:stubbed_response) {
57
130
  [
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mackerel-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mackerel developer team
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-25 00:00:00.000000000 Z
11
+ date: 2021-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -138,7 +138,7 @@ homepage: https://mackerel.io/
138
138
  licenses:
139
139
  - Apache 2
140
140
  metadata: {}
141
- post_install_message:
141
+ post_install_message:
142
142
  rdoc_options: []
143
143
  require_paths:
144
144
  - lib
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  version: '0'
155
155
  requirements: []
156
156
  rubygems_version: 3.0.3
157
- signing_key:
157
+ signing_key:
158
158
  specification_version: 4
159
159
  summary: Mackerel client implemented by Ruby.
160
160
  test_files: