mackerel-client 0.8.0 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/dependabot.yml +9 -0
- data/.github/workflows/ci.yml +22 -0
- data/CHANGELOG.md +21 -0
- data/README.md +1 -1
- data/RELEASE.md +3 -3
- data/VERSION +1 -1
- data/example/03_host.rb +0 -15
- data/lib/mackerel/alert.rb +10 -1
- data/lib/mackerel/api_command.rb +1 -1
- data/lib/mackerel/client.rb +2 -0
- data/lib/mackerel/downtime.rb +27 -0
- data/lib/mackerel/host.rb +2 -2
- data/lib/mackerel/version.rb +1 -1
- data/mackerel-client.gemspec +1 -1
- data/spec/mackerel/alert_spec.rb +85 -12
- data/spec/mackerel/client_spec.rb +2 -2
- data/spec/mackerel/downtime_spec.rb +192 -0
- metadata +13 -10
- data/.travis.yml +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 0b8f49f34db204737703ca6814bca0b82f66360060ef9658c31c9937189027a7
|
4
|
+
data.tar.gz: f5f98e1939a2f69794cb43dafb5fb8fd8e21f2784904cbfb8d97b754f8f32857
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e120aac91332700d0ef14137b699bef524755c9a8c876bc675486865fd84a50eff070a19da00df18d79dc77e2a2dfbe814a7c3f55ca8fbd0b02423b7b4ab8f1a
|
7
|
+
data.tar.gz: 14a98ef43f4431615b7f2141a54790c5c4177d9126542fd42acffe6ce3d6bc3af05e8cecb95fd2958ee792f6e8a87d868f27643102d40d177b8e923eb2e324bd
|
@@ -0,0 +1,22 @@
|
|
1
|
+
name: CI
|
2
|
+
on:
|
3
|
+
push:
|
4
|
+
branches:
|
5
|
+
- master
|
6
|
+
pull_request:
|
7
|
+
jobs:
|
8
|
+
test:
|
9
|
+
strategy:
|
10
|
+
fail-fast: false
|
11
|
+
matrix:
|
12
|
+
os: ['ubuntu-20.04', 'macOS-10.15']
|
13
|
+
# See https://github.com/actions/runner/issues/849 for quoting '3.0'
|
14
|
+
ruby: [2.6, 2.7, '3.0']
|
15
|
+
runs-on: ${{ matrix.os }}
|
16
|
+
steps:
|
17
|
+
- uses: actions/checkout@v2
|
18
|
+
- uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: ${{ matrix.ruby }}
|
21
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
22
|
+
- run: bundle exec rake
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,26 @@
|
|
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
|
+
|
8
|
+
## v0.11.0 (2021-03-24)
|
9
|
+
|
10
|
+
* Implements downtime API #61 (myoan)
|
11
|
+
|
12
|
+
## v0.10.0 (2021-03-15)
|
13
|
+
|
14
|
+
## Breaking change
|
15
|
+
|
16
|
+
Previously `Host` has `type` attribute, but it is removed.
|
17
|
+
|
18
|
+
* Drop `type` attribute from `Host` and introduce `size` instead #58 (astj)
|
19
|
+
|
20
|
+
## v0.9.0 (2020-01-23)
|
21
|
+
|
22
|
+
* Use Faraday v1.0 #54 (onk)
|
23
|
+
|
3
24
|
## v0.8.0 (2019-06-26)
|
4
25
|
|
5
26
|
### Breaking change
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# mackerel-client [![
|
1
|
+
# mackerel-client [![CI](https://github.com/mackerelio/mackerel-client-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/mackerelio/mackerel-client-ruby/actions/workflows/ci.yml) [![Gem Version](https://badge.fury.io/rb/mackerel-client.svg)](https://badge.fury.io/rb/mackerel-client)
|
2
2
|
|
3
3
|
mackerel-client is a ruby library to access Mackerel (https://mackerel.io/).
|
4
4
|
|
data/RELEASE.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
RELEASE
|
2
2
|
=======
|
3
3
|
|
4
|
-
1. Create release branch. (`git
|
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
|
9
|
-
1. Merge Pull-Request to master branch on
|
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.
|
1
|
+
0.12.0
|
data/example/03_host.rb
CHANGED
@@ -14,11 +14,7 @@ pp mc.post_host({
|
|
14
14
|
'agent-revision' => 'bc2f9f6',
|
15
15
|
'agent-version' => '0.6.1',
|
16
16
|
},
|
17
|
-
'type' => 'unknown',
|
18
|
-
'status' => 'working',
|
19
17
|
'memo' => 'test web host',
|
20
|
-
'isRetired' => false,
|
21
|
-
'createdAt' => '1401291970',
|
22
18
|
'roleFullnames' => [
|
23
19
|
'mackerel:web'
|
24
20
|
],
|
@@ -35,11 +31,7 @@ pp mc.post_host({
|
|
35
31
|
'agent-revision' => 'bc2f9f6',
|
36
32
|
'agent-version' => '0.6.1',
|
37
33
|
},
|
38
|
-
'type' => 'unknown',
|
39
|
-
'status' => 'working',
|
40
34
|
'memo' => 'test db host',
|
41
|
-
'isRetired' => false,
|
42
|
-
'createdAt' => '1401291976',
|
43
35
|
'roleFullnames' => [
|
44
36
|
'mackerel:db'
|
45
37
|
],
|
@@ -75,12 +67,7 @@ pp mc.update_host(target_host.id,{
|
|
75
67
|
'agent-revision' => 'bc2f9f6',
|
76
68
|
'agent-version' => '0.6.1',
|
77
69
|
},
|
78
|
-
'type' => 'unknown',
|
79
|
-
'status' => 'working',
|
80
70
|
'memo' => 'test host',
|
81
|
-
'isRetired' => false,
|
82
|
-
'createdAt' => '1401291976',
|
83
|
-
'id' => target_host.id,
|
84
71
|
'roleFullnames' => [
|
85
72
|
'mackerel:db'
|
86
73
|
],
|
@@ -93,5 +80,3 @@ pp mc.update_host(target_host.id,{
|
|
93
80
|
|
94
81
|
# retire the host
|
95
82
|
pp mc.retire_host(target_host.id)
|
96
|
-
|
97
|
-
|
data/lib/mackerel/alert.rb
CHANGED
@@ -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
|
data/lib/mackerel/api_command.rb
CHANGED
@@ -34,7 +34,7 @@ module Mackerel
|
|
34
34
|
req.body = @body
|
35
35
|
end
|
36
36
|
JSON.parse(response.body)
|
37
|
-
rescue Faraday::
|
37
|
+
rescue Faraday::ClientError, Faraday::ServerError => e
|
38
38
|
begin
|
39
39
|
body = JSON.parse(e.response[:body])
|
40
40
|
message = body["error"].is_a?(Hash) ? body["error"]["message"] : body["error"]
|
data/lib/mackerel/client.rb
CHANGED
@@ -21,6 +21,7 @@ require 'mackerel/metric'
|
|
21
21
|
require 'mackerel/metadata'
|
22
22
|
require 'mackerel/notification_group'
|
23
23
|
require 'mackerel/channel'
|
24
|
+
require 'mackerel/downtime'
|
24
25
|
|
25
26
|
module Mackerel
|
26
27
|
class Client
|
@@ -38,6 +39,7 @@ module Mackerel
|
|
38
39
|
include Mackerel::REST::Metadata
|
39
40
|
include Mackerel::REST::Channel
|
40
41
|
include Mackerel::REST::NotificationGroup
|
42
|
+
include Mackerel::REST::Downtime
|
41
43
|
|
42
44
|
def initialize(args = {})
|
43
45
|
@origin = args[:mackerel_origin] || 'https://api.mackerelio.com'
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Mackerel
|
2
|
+
module REST
|
3
|
+
module Downtime
|
4
|
+
def post_downtime(downtime)
|
5
|
+
command = ApiCommand.new(:post, "/api/v0/downtimes", @api_key)
|
6
|
+
command.body = downtime.to_json
|
7
|
+
command.execute(client)
|
8
|
+
end
|
9
|
+
|
10
|
+
def get_downtimes()
|
11
|
+
command = ApiCommand.new(:get, "/api/v0/downtimes", @api_key)
|
12
|
+
command.execute(client)
|
13
|
+
end
|
14
|
+
|
15
|
+
def update_downtime(downtime_id, downtime)
|
16
|
+
command = ApiCommand.new(:put, "/api/v0/downtimes/#{downtime_id}", @api_key)
|
17
|
+
command.body = downtime.to_json
|
18
|
+
command.execute(client)
|
19
|
+
end
|
20
|
+
|
21
|
+
def delete_downtime(downtime_id)
|
22
|
+
command = ApiCommand.new(:delete, "/api/v0/downtimes/#{downtime_id}", @api_key)
|
23
|
+
command.execute(client)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/mackerel/host.rb
CHANGED
@@ -3,13 +3,13 @@ module Mackerel
|
|
3
3
|
class Host
|
4
4
|
|
5
5
|
MACKEREL_INTERFACE_NAME_PATTERN = /^eth\d/
|
6
|
-
attr_accessor :name, :
|
6
|
+
attr_accessor :name, :size, :status, :memo, :isRetired, :id, :createdAt, :roles, :interfaces, :customIdentifier
|
7
7
|
|
8
8
|
def initialize(args = {})
|
9
9
|
@hash = args
|
10
10
|
@name = args["name"]
|
11
11
|
@meta = args["meta"]
|
12
|
-
@
|
12
|
+
@size = args["size"]
|
13
13
|
@status = args["status"]
|
14
14
|
@memo = args["memo"]
|
15
15
|
@isRetired = args["isRetired"]
|
data/lib/mackerel/version.rb
CHANGED
data/mackerel-client.gemspec
CHANGED
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
-
spec.add_dependency 'faraday', '~> 0
|
19
|
+
spec.add_dependency 'faraday', '~> 1.0'
|
20
20
|
|
21
21
|
spec.add_development_dependency "rake"
|
22
22
|
spec.add_development_dependency "bundler"
|
data/spec/mackerel/alert_spec.rb
CHANGED
@@ -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
|
50
|
-
expect(client.
|
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
|
[
|
@@ -125,7 +125,7 @@ RSpec.describe Mackerel::Client do
|
|
125
125
|
'agent-revision' => 'bc2f9f6',
|
126
126
|
'agent-version' => '0.6.1',
|
127
127
|
},
|
128
|
-
'
|
128
|
+
'size' => 'standard',
|
129
129
|
'status' => 'working',
|
130
130
|
'memo' => 'test host',
|
131
131
|
'isRetired' => false,
|
@@ -354,7 +354,7 @@ RSpec.describe Mackerel::Client do
|
|
354
354
|
'agent-revision' => 'bc2f9f6',
|
355
355
|
'agent-version' => '0.6.1',
|
356
356
|
},
|
357
|
-
'
|
357
|
+
'size' => 'standard',
|
358
358
|
'status' => 'working',
|
359
359
|
'memo' => 'test host',
|
360
360
|
'isRetired' => false,
|
@@ -0,0 +1,192 @@
|
|
1
|
+
RSpec.describe Mackerel::Client do
|
2
|
+
let(:api_key) { 'xxxxxxxx' }
|
3
|
+
let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
|
4
|
+
|
5
|
+
describe '#post_downtime' do
|
6
|
+
let(:stubbed_response) {
|
7
|
+
[
|
8
|
+
200,
|
9
|
+
{},
|
10
|
+
JSON.dump(response_object)
|
11
|
+
]
|
12
|
+
}
|
13
|
+
|
14
|
+
let(:test_client) {
|
15
|
+
Faraday.new do |builder|
|
16
|
+
builder.response :raise_error
|
17
|
+
builder.adapter :test do |stubs|
|
18
|
+
stubs.post(api_path) { stubbed_response }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
}
|
22
|
+
|
23
|
+
let(:api_path) { '/api/v0/downtimes' }
|
24
|
+
let(:downtime_id) { 'abcxyz' }
|
25
|
+
let(:name) { 'HogeHoge' }
|
26
|
+
let(:start) { 1234567890 }
|
27
|
+
let(:duration) { 10 }
|
28
|
+
|
29
|
+
let(:response_object) {
|
30
|
+
{
|
31
|
+
'id' => downtime_id,
|
32
|
+
'name' => name,
|
33
|
+
'start' => start,
|
34
|
+
'duration' => duration
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
let(:downtime) {
|
39
|
+
{
|
40
|
+
'name' => name,
|
41
|
+
'start' => start,
|
42
|
+
'duration' => duration
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
before do
|
47
|
+
allow(client).to receive(:http_client).and_return(test_client)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "successfully post downtime" do
|
51
|
+
expect(client.post_downtime(downtime).to_h).to eq(response_object)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#get_downtimes' do
|
56
|
+
let(:stubbed_response) {
|
57
|
+
[
|
58
|
+
200,
|
59
|
+
{},
|
60
|
+
JSON.dump(response_object)
|
61
|
+
]
|
62
|
+
}
|
63
|
+
|
64
|
+
let(:test_client) {
|
65
|
+
Faraday.new do |builder|
|
66
|
+
builder.response :raise_error
|
67
|
+
builder.adapter :test do |stubs|
|
68
|
+
stubs.get(api_path) { stubbed_response }
|
69
|
+
end
|
70
|
+
end
|
71
|
+
}
|
72
|
+
|
73
|
+
let(:api_path) { '/api/v0/downtimes' }
|
74
|
+
let(:downtime_id) { 'abcxyz' }
|
75
|
+
let(:name) { 'HogeHoge' }
|
76
|
+
let(:start) { 1234567890 }
|
77
|
+
let(:duration) { 10 }
|
78
|
+
|
79
|
+
let(:response_object) {
|
80
|
+
{
|
81
|
+
'downtimes' => [
|
82
|
+
{
|
83
|
+
'id' => downtime_id,
|
84
|
+
'name' => name,
|
85
|
+
'start' => start,
|
86
|
+
'duration' => duration
|
87
|
+
}
|
88
|
+
]
|
89
|
+
}
|
90
|
+
}
|
91
|
+
|
92
|
+
before do
|
93
|
+
allow(client).to receive(:http_client).and_return(test_client)
|
94
|
+
end
|
95
|
+
|
96
|
+
it "successfully get downtimes" do
|
97
|
+
expect(client.get_downtimes.to_h).to eq(response_object)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#update_downtime' do
|
102
|
+
let(:stubbed_response) {
|
103
|
+
[
|
104
|
+
200,
|
105
|
+
{},
|
106
|
+
JSON.dump(response_object)
|
107
|
+
]
|
108
|
+
}
|
109
|
+
|
110
|
+
let(:test_client) {
|
111
|
+
Faraday.new do |builder|
|
112
|
+
builder.response :raise_error
|
113
|
+
builder.adapter :test do |stubs|
|
114
|
+
stubs.put(api_path) { stubbed_response }
|
115
|
+
end
|
116
|
+
end
|
117
|
+
}
|
118
|
+
|
119
|
+
let(:api_path) { "/api/v0/downtimes/#{downtime_id}" }
|
120
|
+
let(:downtime_id) { 'abcxyz' }
|
121
|
+
let(:name) { 'HogeHoge' }
|
122
|
+
let(:start) { 1234567890 }
|
123
|
+
let(:duration) { 10 }
|
124
|
+
|
125
|
+
let(:response_object) {
|
126
|
+
{
|
127
|
+
'id' => downtime_id,
|
128
|
+
'name' => name,
|
129
|
+
'start' => start,
|
130
|
+
'duration' => duration
|
131
|
+
}
|
132
|
+
}
|
133
|
+
|
134
|
+
let(:downtime) {
|
135
|
+
{
|
136
|
+
'name' => name,
|
137
|
+
'start' => start,
|
138
|
+
'duration' => duration
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
before do
|
143
|
+
allow(client).to receive(:http_client).and_return(test_client)
|
144
|
+
end
|
145
|
+
|
146
|
+
it "successfully update downtime" do
|
147
|
+
expect(client.update_downtime(downtime_id, downtime).to_h).to eq(response_object)
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe '#delete_downtime' do
|
152
|
+
let(:stubbed_response) {
|
153
|
+
[
|
154
|
+
200,
|
155
|
+
{},
|
156
|
+
JSON.dump(response_object)
|
157
|
+
]
|
158
|
+
}
|
159
|
+
|
160
|
+
let(:test_client) {
|
161
|
+
Faraday.new do |builder|
|
162
|
+
builder.response :raise_error
|
163
|
+
builder.adapter :test do |stubs|
|
164
|
+
stubs.delete(api_path) { stubbed_response }
|
165
|
+
end
|
166
|
+
end
|
167
|
+
}
|
168
|
+
|
169
|
+
let(:api_path) { "/api/v0/downtimes/#{downtime_id}" }
|
170
|
+
let(:downtime_id) { 'abcxyz' }
|
171
|
+
let(:name) { 'HogeHoge' }
|
172
|
+
let(:start) { 1234567890 }
|
173
|
+
let(:duration) { 10 }
|
174
|
+
|
175
|
+
let(:response_object) {
|
176
|
+
{
|
177
|
+
'id' => downtime_id,
|
178
|
+
'name' => name,
|
179
|
+
'start' => start,
|
180
|
+
'duration' => duration
|
181
|
+
}
|
182
|
+
}
|
183
|
+
|
184
|
+
before do
|
185
|
+
allow(client).to receive(:http_client).and_return(test_client)
|
186
|
+
end
|
187
|
+
|
188
|
+
it "successfully delete downtime" do
|
189
|
+
expect(client.delete_downtime(downtime_id).to_h).to eq(response_object)
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
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.
|
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:
|
11
|
+
date: 2021-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -73,9 +73,10 @@ executables: []
|
|
73
73
|
extensions: []
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
|
+
- ".github/dependabot.yml"
|
77
|
+
- ".github/workflows/ci.yml"
|
76
78
|
- ".gitignore"
|
77
79
|
- ".rspec"
|
78
|
-
- ".travis.yml"
|
79
80
|
- CHANGELOG.md
|
80
81
|
- Gemfile
|
81
82
|
- LICENSE.txt
|
@@ -101,6 +102,7 @@ files:
|
|
101
102
|
- lib/mackerel/client.rb
|
102
103
|
- lib/mackerel/client/helper.rb
|
103
104
|
- lib/mackerel/dashboard.rb
|
105
|
+
- lib/mackerel/downtime.rb
|
104
106
|
- lib/mackerel/error.rb
|
105
107
|
- lib/mackerel/host.rb
|
106
108
|
- lib/mackerel/invitation.rb
|
@@ -122,6 +124,7 @@ files:
|
|
122
124
|
- spec/mackerel/client/helper_spec.rb
|
123
125
|
- spec/mackerel/client_spec.rb
|
124
126
|
- spec/mackerel/dashboard_spec.rb
|
127
|
+
- spec/mackerel/downtime_spec.rb
|
125
128
|
- spec/mackerel/invitation_spec.rb
|
126
129
|
- spec/mackerel/metric_spec.rb
|
127
130
|
- spec/mackerel/monitor_spec.rb
|
@@ -135,7 +138,7 @@ homepage: https://mackerel.io/
|
|
135
138
|
licenses:
|
136
139
|
- Apache 2
|
137
140
|
metadata: {}
|
138
|
-
post_install_message:
|
141
|
+
post_install_message:
|
139
142
|
rdoc_options: []
|
140
143
|
require_paths:
|
141
144
|
- lib
|
@@ -150,9 +153,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
153
|
- !ruby/object:Gem::Version
|
151
154
|
version: '0'
|
152
155
|
requirements: []
|
153
|
-
|
154
|
-
|
155
|
-
signing_key:
|
156
|
+
rubygems_version: 3.0.3
|
157
|
+
signing_key:
|
156
158
|
specification_version: 4
|
157
159
|
summary: Mackerel client implemented by Ruby.
|
158
160
|
test_files:
|
@@ -163,6 +165,7 @@ test_files:
|
|
163
165
|
- spec/mackerel/client/helper_spec.rb
|
164
166
|
- spec/mackerel/client_spec.rb
|
165
167
|
- spec/mackerel/dashboard_spec.rb
|
168
|
+
- spec/mackerel/downtime_spec.rb
|
166
169
|
- spec/mackerel/invitation_spec.rb
|
167
170
|
- spec/mackerel/metric_spec.rb
|
168
171
|
- spec/mackerel/monitor_spec.rb
|