mackerel-client 0.6.0 → 0.11.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: 31730bc25cb0a0b6def2d537096f4bbcc46af1de869df74a56115f91184c5126
4
- data.tar.gz: e96b732c979574df0b1f60721578e199decd2bb1f3fbb17b1d83006286d5a49d
3
+ metadata.gz: 68b096795c66861001227bf41e3cb6a7b940306dc404b555691a239031fd8fd6
4
+ data.tar.gz: e6516bd4b135f946b3198e5971fca264cfb3e66d8d35e695d5c49773252bb4b9
5
5
  SHA512:
6
- metadata.gz: bc4578bed917dbd28c5d866ca443b6390e157c38f63f9430217e6b657898f986378e86c0f91f5a1d557bbcc6e98adf68a8d3201974012d6fb61ae7bb81d356c7
7
- data.tar.gz: c45d14fe4d0225c5c8d3968aef9caa79ecc275a91ece1c24ae6230b9d133817046c1bd649a2c06b568b0831cdc29159aa801bdafa80005fa0c72249740873587
6
+ metadata.gz: dd58f6dae6a96848018b4cdd5ba2686bb0ce96f4c521465f782dd45a016c6def438e90b7646a357bc5f93a5905f3e561bcf504124956205c54d9f03543495146
7
+ data.tar.gz: 1640a65f29e6641551769642cac689a3e7c1b9d497bb5ee0b33da1c6081c1083bed6c6dc4b225727f95c2ca4d74de6ea66bdf9eade658fb692c43fe6896ac3ee
@@ -0,0 +1,9 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: bundler
4
+ directory: "/"
5
+ schedule:
6
+ interval: weekly
7
+ time: "01:00"
8
+ timezone: Asia/Tokyo
9
+ open-pull-requests-limit: 10
@@ -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 ADDED
@@ -0,0 +1,35 @@
1
+ # Changelog
2
+
3
+ ## v0.11.0 (2021-03-24)
4
+
5
+ * Implements downtime API #61 (myoan)
6
+
7
+ ## v0.10.0 (2021-03-15)
8
+
9
+ ## Breaking change
10
+
11
+ Previously `Host` has `type` attribute, but it is removed.
12
+
13
+ * Drop `type` attribute from `Host` and introduce `size` instead #58 (astj)
14
+
15
+ ## v0.9.0 (2020-01-23)
16
+
17
+ * Use Faraday v1.0 #54 (onk)
18
+
19
+ ## v0.8.0 (2019-06-26)
20
+
21
+ ### Breaking change
22
+
23
+ Now mackerel-client raises `Mackerel::Error` when HTTP requests failed.
24
+ Previously various exceptions (mainly `RuntimeError` or `NoMethodError`) happened in such cases.
25
+
26
+ * Use Faraday::Response::RaiseError middleware #49 (onk)
27
+
28
+ ## v0.7.0 (2018-10-22)
29
+
30
+ * fix unintended initializing http headers #47 (y_uuki)
31
+
32
+ ## v0.6.0 (2018-07-04)
33
+
34
+ * Use Rspec v3.x #43 (onk)
35
+
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # mackerel-client [![Build Status](https://travis-ci.org/mackerelio/mackerel-client-ruby.svg?branch=master)](https://travis-ci.org/mackerelio/mackerel-client-ruby) [![Gem Version](https://badge.fury.io/rb/mackerel-client.png)](http://badge.fury.io/rb/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
@@ -3,6 +3,7 @@ RELEASE
3
3
 
4
4
  1. Create release branch. (`git checkout -b version-<VERSION>`)
5
5
  1. Bump version `VERSION` and `lib/mackerel/version.rb` files.
6
+ 1. Write changes in CHANGELOG.md
6
7
  1. Push release branch to upstream(GitHub). (`git push -u origin version-<VERSION>`)
7
8
  1. Create Pull-Request on Github.
8
9
  1. Merge Pull-Request to master branch on Github.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.11.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
-
@@ -27,38 +27,26 @@ module Mackerel
27
27
 
28
28
  client_method = client.method(@method)
29
29
  response = client_method.call(request_path) do |req|
30
- req.headers = @headers
30
+ req.headers.update @headers
31
31
  req.headers['x-api-key'] = @api_key
32
32
  req.headers['Content-Type'] ||= JSON_CONTENT_TYPE
33
33
  req.params = @params
34
34
  req.body = @body
35
35
  end
36
- check_status(response.status)
37
-
38
36
  JSON.parse(response.body)
37
+ rescue Faraday::ClientError, Faraday::ServerError => e
38
+ begin
39
+ body = JSON.parse(e.response[:body])
40
+ message = body["error"].is_a?(Hash) ? body["error"]["message"] : body["error"]
41
+ raise Mackerel::Error, "#{@method.upcase} #{@path} failed: #{e.response[:status]} #{message}"
42
+ rescue JSON::ParserError
43
+ # raise Mackerel::Error with original response body
44
+ raise Mackerel::Error, "#{@method.upcase} #{@path} failed: #{e.response[:status]} #{e.response[:body]}"
45
+ end
39
46
  end
40
47
 
41
48
  private
42
49
 
43
- def check_status(status)
44
- case status
45
- when 200...300
46
- nil
47
- when 400
48
- message ="Invalid parameter"
49
- raise "#{@method.upcase} #{@path} failed: #{status} #{message}"
50
- when 403
51
- message ="Not authorized"
52
- raise "#{@method.upcase} #{@path} failed: #{status} #{message}"
53
- when 404
54
- message ="Resource not found"
55
- raise "#{@method.upcase} #{@path} failed: #{status} #{message}"
56
- when 409
57
- message ="Already exists"
58
- raise "#{@method.upcase} #{@path} failed: #{status} #{message}"
59
- end
60
- end
61
-
62
50
  def make_escaped_query
63
51
  @query.map{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"}.join("&")
64
52
  end
@@ -4,6 +4,7 @@ require 'uri'
4
4
  require 'json' unless defined? ::JSON
5
5
 
6
6
  require 'mackerel/api_command'
7
+ require 'mackerel/error'
7
8
 
8
9
  require 'mackerel/role'
9
10
  require 'mackerel/host'
@@ -20,6 +21,7 @@ require 'mackerel/metric'
20
21
  require 'mackerel/metadata'
21
22
  require 'mackerel/notification_group'
22
23
  require 'mackerel/channel'
24
+ require 'mackerel/downtime'
23
25
 
24
26
  module Mackerel
25
27
  class Client
@@ -37,6 +39,7 @@ module Mackerel
37
39
  include Mackerel::REST::Metadata
38
40
  include Mackerel::REST::Channel
39
41
  include Mackerel::REST::NotificationGroup
42
+ include Mackerel::REST::Downtime
40
43
 
41
44
  def initialize(args = {})
42
45
  @origin = args[:mackerel_origin] || 'https://api.mackerelio.com'
@@ -54,6 +57,7 @@ module Mackerel
54
57
 
55
58
  def http_client
56
59
  Faraday.new(:url => @origin) do |faraday|
60
+ faraday.response :raise_error
57
61
  faraday.response :logger if ENV['DEBUG']
58
62
  faraday.adapter Faraday.default_adapter
59
63
  faraday.options.params_encoder = Faraday::FlatParamsEncoder
@@ -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
@@ -0,0 +1,4 @@
1
+ module Mackerel
2
+ class Error < StandardError
3
+ end
4
+ 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, :type, :status, :memo, :isRetired, :id, :createdAt, :roles, :interfaces, :customIdentifier
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
- @type = args["type"]
12
+ @size = args["size"]
13
13
  @status = args["status"]
14
14
  @memo = args["memo"]
15
15
  @isRetired = args["isRetired"]
@@ -1,3 +1,3 @@
1
1
  module Mackerel
2
- VERSION = "0.6.0"
2
+ VERSION = "0.11.0"
3
3
  end
@@ -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.9'
19
+ spec.add_dependency 'faraday', '~> 1.0'
20
20
 
21
21
  spec.add_development_dependency "rake"
22
22
  spec.add_development_dependency "bundler"
@@ -13,6 +13,7 @@ RSpec.describe Mackerel::Client do
13
13
 
14
14
  let(:test_client) {
15
15
  Faraday.new do |builder|
16
+ builder.response :raise_error
16
17
  builder.adapter :test do |stubs|
17
18
  stubs.get(api_path) { stubbed_response }
18
19
  end
@@ -62,6 +63,7 @@ RSpec.describe Mackerel::Client do
62
63
 
63
64
  let(:test_client) {
64
65
  Faraday.new do |builder|
66
+ builder.response :raise_error
65
67
  builder.adapter :test do |stubs|
66
68
  stubs.post(api_path) { stubbed_response }
67
69
  end
@@ -13,6 +13,7 @@ RSpec.describe Mackerel::Client do
13
13
 
14
14
  let(:test_client) {
15
15
  Faraday.new do |builder|
16
+ builder.response :raise_error
16
17
  builder.adapter :test do |stubs|
17
18
  stubs.post(api_path) { stubbed_response }
18
19
  end
@@ -58,6 +59,7 @@ RSpec.describe Mackerel::Client do
58
59
 
59
60
  let(:test_client) {
60
61
  Faraday.new do |builder|
62
+ builder.response :raise_error
61
63
  builder.adapter :test do |stubs|
62
64
  stubs.get(api_path) { stubbed_response }
63
65
  end
@@ -118,6 +120,7 @@ RSpec.describe Mackerel::Client do
118
120
 
119
121
  let(:test_client) {
120
122
  Faraday.new do |builder|
123
+ builder.response :raise_error
121
124
  builder.adapter :test do |stubs|
122
125
  stubs.put(api_path) { stubbed_response }
123
126
  end
@@ -165,6 +168,7 @@ RSpec.describe Mackerel::Client do
165
168
 
166
169
  let(:test_client) {
167
170
  Faraday.new do |builder|
171
+ builder.response :raise_error
168
172
  builder.adapter :test do |stubs|
169
173
  stubs.delete(api_path) { stubbed_response }
170
174
  end
@@ -0,0 +1,82 @@
1
+ RSpec.describe Mackerel::ApiCommand do
2
+ let(:api_key) { "xxxxxxxx" }
3
+ let(:command) { Mackerel::ApiCommand.new(:get, "/api/v0/services", api_key) }
4
+
5
+ describe "#execute" do
6
+ let(:api_path) { "/api/v0/services" }
7
+
8
+ let(:test_client) {
9
+ Faraday.new do |builder|
10
+ builder.response :raise_error
11
+ builder.adapter :test do |stubs|
12
+ stubs.get(api_path) { stubbed_response }
13
+ end
14
+ end
15
+ }
16
+
17
+ let(:services) {
18
+ {
19
+ "services" => [
20
+ {
21
+ "name" => "Web",
22
+ "memo" => "store",
23
+ "roles" => [
24
+ "normal role",
25
+ "special role"
26
+ ]
27
+ },
28
+ {
29
+ "name" => "Web",
30
+ "memo" => "store",
31
+ "roles" => [
32
+ "a role",
33
+ "the role"
34
+ ]
35
+ }
36
+ ]
37
+ }
38
+ }
39
+
40
+ context "when success" do
41
+ let(:stubbed_response) {
42
+ [
43
+ 200,
44
+ {},
45
+ JSON.dump(services)
46
+ ]
47
+ }
48
+
49
+ it {
50
+ expect(command.execute(test_client)).to eq(services)
51
+ }
52
+ end
53
+
54
+ context "when 404 Not Found" do
55
+ let(:stubbed_response) {
56
+ [
57
+ 404,
58
+ {},
59
+ JSON.dump({"error" => { "message" => "Host Not Found."} })
60
+ ]
61
+ }
62
+
63
+ it {
64
+ expect { command.execute(test_client) }.to raise_error Mackerel::Error, "GET /api/v0/services failed: 404 Host Not Found."
65
+ }
66
+ end
67
+
68
+ context "when 401 Unauthorized" do
69
+ let(:stubbed_response) {
70
+ [
71
+ 401,
72
+ {},
73
+ JSON.dump({ "error" => "Authentication failed. Please try with valid Api Key." })
74
+ ]
75
+ }
76
+
77
+ it {
78
+ expect { command.execute(test_client) }.to raise_error Mackerel::Error, "GET /api/v0/services failed: 401 Authentication failed. Please try with valid Api Key."
79
+ }
80
+ end
81
+ end
82
+ end
@@ -15,6 +15,7 @@ RSpec.describe Mackerel::Client do
15
15
 
16
16
  let(:test_client) {
17
17
  Faraday.new do |builder|
18
+ builder.response :raise_error
18
19
  builder.adapter :test do |stubs|
19
20
  stubs.get(api_path) { stubbed_response }
20
21
  end
@@ -20,6 +20,7 @@ RSpec.describe Mackerel::Client do
20
20
 
21
21
  let(:test_client) {
22
22
  Faraday.new do |builder|
23
+ builder.response :raise_error
23
24
  builder.adapter :test do |stubs|
24
25
  stubs.post(api_path) { stubbed_response }
25
26
  end
@@ -62,6 +63,7 @@ RSpec.describe Mackerel::Client do
62
63
 
63
64
  let(:test_client) {
64
65
  Faraday.new do |builder|
66
+ builder.response :raise_error
65
67
  builder.adapter :test do |stubs|
66
68
  stubs.put(api_path) { stubbed_response }
67
69
  end
@@ -104,6 +106,7 @@ RSpec.describe Mackerel::Client do
104
106
 
105
107
  let(:test_client) {
106
108
  Faraday.new do |builder|
109
+ builder.response :raise_error
107
110
  builder.adapter :test do |stubs|
108
111
  stubs.get(api_path) { stubbed_response }
109
112
  end
@@ -122,7 +125,7 @@ RSpec.describe Mackerel::Client do
122
125
  'agent-revision' => 'bc2f9f6',
123
126
  'agent-version' => '0.6.1',
124
127
  },
125
- 'type' => 'unknown',
128
+ 'size' => 'standard',
126
129
  'status' => 'working',
127
130
  'memo' => 'test host',
128
131
  'isRetired' => false,
@@ -159,6 +162,7 @@ RSpec.describe Mackerel::Client do
159
162
 
160
163
  let(:test_client) {
161
164
  Faraday.new do |builder|
165
+ builder.response :raise_error
162
166
  builder.adapter :test do |stubs|
163
167
  stubs.post(api_path) { stubbed_response }
164
168
  end
@@ -194,6 +198,7 @@ RSpec.describe Mackerel::Client do
194
198
 
195
199
  let(:test_client) {
196
200
  Faraday.new do |builder|
201
+ builder.response :raise_error
197
202
  builder.adapter :test do |stubs|
198
203
  stubs.put(api_path) { stubbed_response }
199
204
  end
@@ -236,6 +241,7 @@ RSpec.describe Mackerel::Client do
236
241
 
237
242
  let(:test_client) {
238
243
  Faraday.new do |builder|
244
+ builder.response :raise_error
239
245
  builder.adapter :test do |stubs|
240
246
  stubs.post(api_path) { stubbed_response }
241
247
  end
@@ -270,6 +276,7 @@ RSpec.describe Mackerel::Client do
270
276
 
271
277
  let(:test_client) {
272
278
  Faraday.new do |builder|
279
+ builder.response :raise_error
273
280
  builder.adapter :test do |stubs|
274
281
  stubs.post(api_path) { stubbed_response }
275
282
  end
@@ -327,6 +334,7 @@ RSpec.describe Mackerel::Client do
327
334
 
328
335
  let(:test_client) {
329
336
  Faraday.new do |builder|
337
+ builder.response :raise_error
330
338
  builder.adapter :test do |stubs|
331
339
  stubs.get(api_path) { stubbed_response }
332
340
  end
@@ -346,7 +354,7 @@ RSpec.describe Mackerel::Client do
346
354
  'agent-revision' => 'bc2f9f6',
347
355
  'agent-version' => '0.6.1',
348
356
  },
349
- 'type' => 'unknown',
357
+ 'size' => 'standard',
350
358
  'status' => 'working',
351
359
  'memo' => 'test host',
352
360
  'isRetired' => false,
@@ -388,6 +396,7 @@ RSpec.describe Mackerel::Client do
388
396
 
389
397
  let(:test_client) {
390
398
  Faraday.new do |builder|
399
+ builder.response :raise_error
391
400
  builder.adapter :test do |stubs|
392
401
  stubs.post(api_path) { stubbed_response }
393
402
  end
@@ -433,6 +442,7 @@ RSpec.describe Mackerel::Client do
433
442
 
434
443
  let(:test_client) {
435
444
  Faraday.new do |builder|
445
+ builder.response :raise_error
436
446
  builder.adapter :test do |stubs|
437
447
  stubs.get(api_path) { stubbed_response }
438
448
  end
@@ -466,6 +476,7 @@ RSpec.describe Mackerel::Client do
466
476
 
467
477
  let(:test_client) {
468
478
  Faraday.new do |builder|
479
+ builder.response :raise_error
469
480
  builder.adapter :test do |stubs|
470
481
  stubs.get(api_path) { stubbed_response }
471
482
  end
@@ -501,6 +512,7 @@ RSpec.describe Mackerel::Client do
501
512
 
502
513
  let(:test_client) {
503
514
  Faraday.new do |builder|
515
+ builder.response :raise_error
504
516
  builder.adapter :test do |stubs|
505
517
  stubs.put(api_path) { stubbed_response }
506
518
  end
@@ -540,6 +552,7 @@ RSpec.describe Mackerel::Client do
540
552
 
541
553
  let(:test_client) {
542
554
  Faraday.new do |builder|
555
+ builder.response :raise_error
543
556
  builder.adapter :test do |stubs|
544
557
  stubs.delete(api_path) { stubbed_response }
545
558
  end
@@ -13,6 +13,7 @@ RSpec.describe Mackerel::Client do
13
13
 
14
14
  let(:test_client) {
15
15
  Faraday.new do |builder|
16
+ builder.response :raise_error
16
17
  builder.adapter :test do |stubs|
17
18
  stubs.post(api_path) { stubbed_response }
18
19
  end
@@ -61,6 +62,7 @@ RSpec.describe Mackerel::Client do
61
62
 
62
63
  let(:test_client) {
63
64
  Faraday.new do |builder|
65
+ builder.response :raise_error
64
66
  builder.adapter :test do |stubs|
65
67
  stubs.put(api_path) { stubbed_response }
66
68
  end
@@ -110,6 +112,7 @@ RSpec.describe Mackerel::Client do
110
112
 
111
113
  let(:test_client) {
112
114
  Faraday.new do |builder|
115
+ builder.response :raise_error
113
116
  builder.adapter :test do |stubs|
114
117
  stubs.get(api_path) { stubbed_response }
115
118
  end
@@ -160,6 +163,7 @@ RSpec.describe Mackerel::Client do
160
163
 
161
164
  let(:test_client) {
162
165
  Faraday.new do |builder|
166
+ builder.response :raise_error
163
167
  builder.adapter :test do |stubs|
164
168
  stubs.get(api_path) { stubbed_response }
165
169
  end
@@ -208,6 +212,7 @@ RSpec.describe Mackerel::Client do
208
212
 
209
213
  let(:test_client) {
210
214
  Faraday.new do |builder|
215
+ builder.response :raise_error
211
216
  builder.adapter :test do |stubs|
212
217
  stubs.delete(api_path) { stubbed_response }
213
218
  end
@@ -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
@@ -15,6 +15,7 @@ RSpec.describe Mackerel::Client do
15
15
 
16
16
  let(:test_client) {
17
17
  Faraday.new do |builder|
18
+ builder.response :raise_error
18
19
  builder.adapter :test do |stubs|
19
20
  stubs.post(api_path) { stubbed_response }
20
21
  end
@@ -56,6 +57,7 @@ RSpec.describe Mackerel::Client do
56
57
 
57
58
  let(:test_client) {
58
59
  Faraday.new do |builder|
60
+ builder.response :raise_error
59
61
  builder.adapter :test do |stubs|
60
62
  stubs.post(api_path) { stubbed_response }
61
63
  end
@@ -13,6 +13,7 @@ RSpec.describe Mackerel::Client do
13
13
 
14
14
  let(:test_client) {
15
15
  Faraday.new do |builder|
16
+ builder.response :raise_error
16
17
  builder.adapter :test do |stubs|
17
18
  stubs.post(api_path) { stubbed_response }
18
19
  end
@@ -52,6 +53,7 @@ RSpec.describe Mackerel::Client do
52
53
 
53
54
  let(:test_client) {
54
55
  Faraday.new do |builder|
56
+ builder.response :raise_error
55
57
  builder.adapter :test do |stubs|
56
58
  stubs.get(api_path) { stubbed_response }
57
59
  end
@@ -98,6 +100,7 @@ RSpec.describe Mackerel::Client do
98
100
 
99
101
  let(:test_client) {
100
102
  Faraday.new do |builder|
103
+ builder.response :raise_error
101
104
  builder.adapter :test do |stubs|
102
105
  stubs.get(api_path) { stubbed_response }
103
106
  end
@@ -141,6 +144,7 @@ RSpec.describe Mackerel::Client do
141
144
 
142
145
  let(:test_client) {
143
146
  Faraday.new do |builder|
147
+ builder.response :raise_error
144
148
  builder.adapter :test do |stubs|
145
149
  stubs.post(api_path) { stubbed_response }
146
150
  end
@@ -181,6 +185,7 @@ RSpec.describe Mackerel::Client do
181
185
 
182
186
  let(:test_client) {
183
187
  Faraday.new do |builder|
188
+ builder.response :raise_error
184
189
  builder.adapter :test do |stubs|
185
190
  stubs.get(api_path) { stubbed_response }
186
191
  end
@@ -222,6 +227,7 @@ RSpec.describe Mackerel::Client do
222
227
 
223
228
  let(:test_client) {
224
229
  Faraday.new do |builder|
230
+ builder.response :raise_error
225
231
  builder.adapter :test do |stubs|
226
232
  stubs.post(api_path) { stubbed_response }
227
233
  end
@@ -13,6 +13,7 @@ RSpec.describe Mackerel::Client do
13
13
 
14
14
  let(:test_client) {
15
15
  Faraday.new do |builder|
16
+ builder.response :raise_error
16
17
  builder.adapter :test do |stubs|
17
18
  stubs.post(api_path) { stubbed_response }
18
19
  end
@@ -59,6 +60,7 @@ RSpec.describe Mackerel::Client do
59
60
 
60
61
  let(:test_client) {
61
62
  Faraday.new do |builder|
63
+ builder.response :raise_error
62
64
  builder.adapter :test do |stubs|
63
65
  stubs.get(api_path) { stubbed_response }
64
66
  end
@@ -125,6 +127,7 @@ RSpec.describe Mackerel::Client do
125
127
 
126
128
  let(:test_client) {
127
129
  Faraday.new do |builder|
130
+ builder.response :raise_error
128
131
  builder.adapter :test do |stubs|
129
132
  stubs.put(api_path) { stubbed_response }
130
133
  end
@@ -173,6 +176,7 @@ RSpec.describe Mackerel::Client do
173
176
 
174
177
  let(:test_client) {
175
178
  Faraday.new do |builder|
179
+ builder.response :raise_error
176
180
  builder.adapter :test do |stubs|
177
181
  stubs.delete(api_path) { stubbed_response }
178
182
  end
@@ -13,6 +13,7 @@ RSpec.describe Mackerel::Client do
13
13
 
14
14
  let(:test_client) {
15
15
  Faraday.new do |builder|
16
+ builder.response :raise_error
16
17
  builder.adapter :test do |stubs|
17
18
  stubs.post(api_path) { stubbed_response }
18
19
  end
@@ -13,6 +13,7 @@ RSpec.describe Mackerel::Client do
13
13
 
14
14
  let(:test_client) {
15
15
  Faraday.new do |builder|
16
+ builder.response :raise_error
16
17
  builder.adapter :test do |stubs|
17
18
  stubs.post(api_path) { stubbed_response }
18
19
  end
@@ -76,6 +77,7 @@ RSpec.describe Mackerel::Client do
76
77
 
77
78
  let(:test_client) {
78
79
  Faraday.new do |builder|
80
+ builder.response :raise_error
79
81
  builder.adapter :test do |stubs|
80
82
  stubs.get(api_path) { stubbed_response }
81
83
  end
@@ -159,6 +161,7 @@ RSpec.describe Mackerel::Client do
159
161
 
160
162
  let(:test_client) {
161
163
  Faraday.new do |builder|
164
+ builder.response :raise_error
162
165
  builder.adapter :test do |stubs|
163
166
  stubs.put(api_path) { stubbed_response }
164
167
  end
@@ -219,6 +222,7 @@ RSpec.describe Mackerel::Client do
219
222
 
220
223
  let(:test_client) {
221
224
  Faraday.new do |builder|
225
+ builder.response :raise_error
222
226
  builder.adapter :test do |stubs|
223
227
  stubs.delete(api_path) { stubbed_response }
224
228
  end
@@ -15,6 +15,7 @@ RSpec.describe Mackerel::Client do
15
15
 
16
16
  let(:test_client) {
17
17
  Faraday.new do |builder|
18
+ builder.response :raise_error
18
19
  builder.adapter :test do |stubs|
19
20
  stubs.get(api_path) { stubbed_response }
20
21
  end
@@ -15,6 +15,7 @@ RSpec.describe Mackerel::Client do
15
15
 
16
16
  let(:test_client) {
17
17
  Faraday.new do |builder|
18
+ builder.response :raise_error
18
19
  builder.adapter :test do |stubs|
19
20
  stubs.get(api_path) { stubbed_response }
20
21
  end
@@ -71,6 +72,7 @@ RSpec.describe Mackerel::Client do
71
72
 
72
73
  let(:test_client) {
73
74
  Faraday.new do |builder|
75
+ builder.response :raise_error
74
76
  builder.adapter :test do |stubs|
75
77
  stubs.get(api_path) { stubbed_response }
76
78
  end
@@ -120,6 +122,7 @@ RSpec.describe Mackerel::Client do
120
122
 
121
123
  let(:test_client) {
122
124
  Faraday.new do |builder|
125
+ builder.response :raise_error
123
126
  builder.adapter :test do |stubs|
124
127
  stubs.get(api_path) { stubbed_response }
125
128
  end
@@ -15,6 +15,7 @@ RSpec.describe Mackerel::Client do
15
15
 
16
16
  let(:test_client) {
17
17
  Faraday.new do |builder|
18
+ builder.response :raise_error
18
19
  builder.adapter :test do |stubs|
19
20
  stubs.get(api_path) { stubbed_response }
20
21
  end
@@ -64,6 +65,7 @@ RSpec.describe Mackerel::Client do
64
65
 
65
66
  let(:test_client) {
66
67
  Faraday.new do |builder|
68
+ builder.response :raise_error
67
69
  builder.adapter :test do |stubs|
68
70
  stubs.delete(api_path) { stubbed_response }
69
71
  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.6.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mackerel developer team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-07-04 00:00:00.000000000 Z
11
+ date: 2021-03-25 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.9'
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.9'
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -73,9 +73,11 @@ 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"
80
+ - CHANGELOG.md
79
81
  - Gemfile
80
82
  - LICENSE.txt
81
83
  - README.md
@@ -100,6 +102,8 @@ files:
100
102
  - lib/mackerel/client.rb
101
103
  - lib/mackerel/client/helper.rb
102
104
  - lib/mackerel/dashboard.rb
105
+ - lib/mackerel/downtime.rb
106
+ - lib/mackerel/error.rb
103
107
  - lib/mackerel/host.rb
104
108
  - lib/mackerel/invitation.rb
105
109
  - lib/mackerel/metadata.rb
@@ -115,10 +119,12 @@ files:
115
119
  - mackerel-client.gemspec
116
120
  - spec/mackerel/alert_spec.rb
117
121
  - spec/mackerel/annotation_spec.rb
122
+ - spec/mackerel/api_commend_spec.rb
118
123
  - spec/mackerel/channel_spec.rb
119
124
  - spec/mackerel/client/helper_spec.rb
120
125
  - spec/mackerel/client_spec.rb
121
126
  - spec/mackerel/dashboard_spec.rb
127
+ - spec/mackerel/downtime_spec.rb
122
128
  - spec/mackerel/invitation_spec.rb
123
129
  - spec/mackerel/metric_spec.rb
124
130
  - spec/mackerel/monitor_spec.rb
@@ -147,18 +153,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
153
  - !ruby/object:Gem::Version
148
154
  version: '0'
149
155
  requirements: []
150
- rubyforge_project:
151
- rubygems_version: 2.7.6
156
+ rubygems_version: 3.0.3
152
157
  signing_key:
153
158
  specification_version: 4
154
159
  summary: Mackerel client implemented by Ruby.
155
160
  test_files:
156
161
  - spec/mackerel/alert_spec.rb
157
162
  - spec/mackerel/annotation_spec.rb
163
+ - spec/mackerel/api_commend_spec.rb
158
164
  - spec/mackerel/channel_spec.rb
159
165
  - spec/mackerel/client/helper_spec.rb
160
166
  - spec/mackerel/client_spec.rb
161
167
  - spec/mackerel/dashboard_spec.rb
168
+ - spec/mackerel/downtime_spec.rb
162
169
  - spec/mackerel/invitation_spec.rb
163
170
  - spec/mackerel/metric_spec.rb
164
171
  - spec/mackerel/monitor_spec.rb
data/.travis.yml DELETED
@@ -1,9 +0,0 @@
1
- language: ruby
2
- before_install:
3
- # https://github.com/travis-ci/travis-ci/issues/3531
4
- - gem install bundler # -v 1.7.14 if a specific version is needed
5
- rvm:
6
- - "2.2"
7
- - "2.1.1"
8
- - "2.0.0"
9
- - "1.9.3"