mackerel-client 0.10.0 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/VERSION +1 -1
- data/lib/mackerel/client.rb +2 -0
- data/lib/mackerel/downtime.rb +27 -0
- data/lib/mackerel/version.rb +1 -1
- data/spec/mackerel/downtime_spec.rb +192 -0
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68b096795c66861001227bf41e3cb6a7b940306dc404b555691a239031fd8fd6
|
4
|
+
data.tar.gz: e6516bd4b135f946b3198e5971fca264cfb3e66d8d35e695d5c49773252bb4b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd58f6dae6a96848018b4cdd5ba2686bb0ce96f4c521465f782dd45a016c6def438e90b7646a357bc5f93a5905f3e561bcf504124956205c54d9f03543495146
|
7
|
+
data.tar.gz: 1640a65f29e6641551769642cac689a3e7c1b9d497bb5ee0b33da1c6081c1083bed6c6dc4b225727f95c2ca4d74de6ea66bdf9eade658fb692c43fe6896ac3ee
|
data/CHANGELOG.md
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.11.0
|
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/version.rb
CHANGED
@@ -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.11.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-
|
11
|
+
date: 2021-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/mackerel/client.rb
|
103
103
|
- lib/mackerel/client/helper.rb
|
104
104
|
- lib/mackerel/dashboard.rb
|
105
|
+
- lib/mackerel/downtime.rb
|
105
106
|
- lib/mackerel/error.rb
|
106
107
|
- lib/mackerel/host.rb
|
107
108
|
- lib/mackerel/invitation.rb
|
@@ -123,6 +124,7 @@ files:
|
|
123
124
|
- spec/mackerel/client/helper_spec.rb
|
124
125
|
- spec/mackerel/client_spec.rb
|
125
126
|
- spec/mackerel/dashboard_spec.rb
|
127
|
+
- spec/mackerel/downtime_spec.rb
|
126
128
|
- spec/mackerel/invitation_spec.rb
|
127
129
|
- spec/mackerel/metric_spec.rb
|
128
130
|
- spec/mackerel/monitor_spec.rb
|
@@ -136,7 +138,7 @@ homepage: https://mackerel.io/
|
|
136
138
|
licenses:
|
137
139
|
- Apache 2
|
138
140
|
metadata: {}
|
139
|
-
post_install_message:
|
141
|
+
post_install_message:
|
140
142
|
rdoc_options: []
|
141
143
|
require_paths:
|
142
144
|
- lib
|
@@ -151,8 +153,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
151
153
|
- !ruby/object:Gem::Version
|
152
154
|
version: '0'
|
153
155
|
requirements: []
|
154
|
-
rubygems_version: 3.
|
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
|