mackerel-client 0.5.0 → 0.10.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: 0f043c163694280f7233b26cf625bdba0caa646ba55d3c2cba6002772468c7b9
4
- data.tar.gz: 7b1c11e80e5126cc8312b3d4695e0bc980f8a9c83ce3f629431a5625e89e5624
3
+ metadata.gz: defff3c3d0b9980e41b4fc6d9cc38c89a28f0093617a3f9bc32b5dc02307b7c3
4
+ data.tar.gz: 8d72678528c3f43c2c9772b7583fccc40abbe021afb67a89d14214f895542a40
5
5
  SHA512:
6
- metadata.gz: 18f19702d70fa6718924102398852f947f24d11721aa839af55c141819b0e4cb184b0ccf0ebaca5af3fd75c192fb1e77f2e0e72939aaa396c2a262dd9a207a24
7
- data.tar.gz: a364791a0b00a4695f654f6fae03002a4e11cfa9e2ba5ff55265e0bffd98fa518970315f80672dfbc21108c17997777a2c744c6950b9a8cfa84e0cc91345a56c
6
+ metadata.gz: '08d0ea5a016ae5cdda43fddfbf57fa9868f05fb42b1ab8cd0f3f630fd4b2eb80e94d19856b4746c215b26784e95e90fcca320fcae7a092b625534319c781f8a0'
7
+ data.tar.gz: b2e3ca3de0d0e95dfc302a808d4648ed0ded2ebe2445980b4aa6f20007bcb359e6d8d0fcc372e403471892d9ae9481a2448e9ada6e97c8a2da3a3b600db0cd5d
@@ -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/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format documentation
2
2
  --color
3
+ --require spec_helper
data/CHANGELOG.md ADDED
@@ -0,0 +1,31 @@
1
+ # Changelog
2
+
3
+ ## v0.10.0 (2021-03-15)
4
+
5
+ ## Breaking change
6
+
7
+ Previously `Host` has `type` attribute, but it is removed.
8
+
9
+ * Drop `type` attribute from `Host` and introduce `size` instead #58 (astj)
10
+
11
+ ## v0.9.0 (2020-01-23)
12
+
13
+ * Use Faraday v1.0 #54 (onk)
14
+
15
+ ## v0.8.0 (2019-06-26)
16
+
17
+ ### Breaking change
18
+
19
+ Now mackerel-client raises `Mackerel::Error` when HTTP requests failed.
20
+ Previously various exceptions (mainly `RuntimeError` or `NoMethodError`) happened in such cases.
21
+
22
+ * Use Faraday::Response::RaiseError middleware #49 (onk)
23
+
24
+ ## v0.7.0 (2018-10-22)
25
+
26
+ * fix unintended initializing http headers #47 (y_uuki)
27
+
28
+ ## v0.6.0 (2018-07-04)
29
+
30
+ * Use Rspec v3.x #43 (onk)
31
+
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
@@ -1,7 +1,10 @@
1
1
  RELEASE
2
2
  =======
3
3
 
4
- 1. Update VERSION file.
5
- 1. git push
6
- 1. `gem build mackerel-client.gemspec`
7
- 1. `gem push mackerel-client-$VERSION.gem`
4
+ 1. Create release branch. (`git checkout -b version-<VERSION>`)
5
+ 1. Bump version `VERSION` and `lib/mackerel/version.rb` files.
6
+ 1. Write changes in CHANGELOG.md
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.
10
+ 1. Tagging and Release. (`rake release`)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.5.0
1
+ 0.10.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'
@@ -54,6 +55,7 @@ module Mackerel
54
55
 
55
56
  def http_client
56
57
  Faraday.new(:url => @origin) do |faraday|
58
+ faraday.response :raise_error
57
59
  faraday.response :logger if ENV['DEBUG']
58
60
  faraday.adapter Faraday.default_adapter
59
61
  faraday.options.params_encoder = Faraday::FlatParamsEncoder
@@ -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.5.0"
2
+ VERSION = "0.10.0"
3
3
  end
@@ -16,9 +16,9 @@ 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
- spec.add_development_dependency "rake", '~> 0'
22
- spec.add_development_dependency "bundler", "~> 1.5"
23
- spec.add_development_dependency "rspec", '~> 2'
21
+ spec.add_development_dependency "rake"
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rspec"
24
24
  end
@@ -1,8 +1,4 @@
1
- require 'mackerel'
2
- require 'mackerel/host'
3
- require 'json'
4
-
5
- describe Mackerel::Client do
1
+ RSpec.describe Mackerel::Client do
6
2
  let(:api_key) { 'xxxxxxxx' }
7
3
  let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
4
 
@@ -17,6 +13,7 @@ describe Mackerel::Client do
17
13
 
18
14
  let(:test_client) {
19
15
  Faraday.new do |builder|
16
+ builder.response :raise_error
20
17
  builder.adapter :test do |stubs|
21
18
  stubs.get(api_path) { stubbed_response }
22
19
  end
@@ -66,6 +63,7 @@ describe Mackerel::Client do
66
63
 
67
64
  let(:test_client) {
68
65
  Faraday.new do |builder|
66
+ builder.response :raise_error
69
67
  builder.adapter :test do |stubs|
70
68
  stubs.post(api_path) { stubbed_response }
71
69
  end
@@ -1,8 +1,4 @@
1
- require 'mackerel'
2
- require 'mackerel/host'
3
- require 'json'
4
-
5
- describe Mackerel::Client do
1
+ RSpec.describe Mackerel::Client do
6
2
  let(:api_key) { 'xxxxxxxx' }
7
3
  let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
4
 
@@ -17,6 +13,7 @@ describe Mackerel::Client do
17
13
 
18
14
  let(:test_client) {
19
15
  Faraday.new do |builder|
16
+ builder.response :raise_error
20
17
  builder.adapter :test do |stubs|
21
18
  stubs.post(api_path) { stubbed_response }
22
19
  end
@@ -62,6 +59,7 @@ describe Mackerel::Client do
62
59
 
63
60
  let(:test_client) {
64
61
  Faraday.new do |builder|
62
+ builder.response :raise_error
65
63
  builder.adapter :test do |stubs|
66
64
  stubs.get(api_path) { stubbed_response }
67
65
  end
@@ -122,6 +120,7 @@ describe Mackerel::Client do
122
120
 
123
121
  let(:test_client) {
124
122
  Faraday.new do |builder|
123
+ builder.response :raise_error
125
124
  builder.adapter :test do |stubs|
126
125
  stubs.put(api_path) { stubbed_response }
127
126
  end
@@ -169,6 +168,7 @@ describe Mackerel::Client do
169
168
 
170
169
  let(:test_client) {
171
170
  Faraday.new do |builder|
171
+ builder.response :raise_error
172
172
  builder.adapter :test do |stubs|
173
173
  stubs.delete(api_path) { stubbed_response }
174
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
@@ -1,8 +1,4 @@
1
- require 'mackerel'
2
- require 'mackerel/host'
3
- require 'json'
4
-
5
- describe Mackerel::Client do
1
+ RSpec.describe Mackerel::Client do
6
2
  let(:api_key) { 'xxxxxxxx' }
7
3
  let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
4
 
@@ -19,6 +15,7 @@ describe Mackerel::Client do
19
15
 
20
16
  let(:test_client) {
21
17
  Faraday.new do |builder|
18
+ builder.response :raise_error
22
19
  builder.adapter :test do |stubs|
23
20
  stubs.get(api_path) { stubbed_response }
24
21
  end
@@ -1,6 +1,6 @@
1
1
  require 'mackerel/client/helper'
2
2
 
3
- describe Mackerel::Client::Helper do
3
+ RSpec.describe Mackerel::Client::Helper do
4
4
  describe '.as_safe_metric_name' do
5
5
  it 'translates characters that cannot be used as a metric name to safe characters' do
6
6
  name = 'readme.md'
@@ -1,8 +1,4 @@
1
- require 'mackerel'
2
- require 'mackerel/host'
3
- require 'json'
4
-
5
- describe Mackerel::Client do
1
+ RSpec.describe Mackerel::Client do
6
2
  let(:api_key) { 'xxxxxxxx' }
7
3
  let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
4
 
@@ -24,6 +20,7 @@ describe Mackerel::Client do
24
20
 
25
21
  let(:test_client) {
26
22
  Faraday.new do |builder|
23
+ builder.response :raise_error
27
24
  builder.adapter :test do |stubs|
28
25
  stubs.post(api_path) { stubbed_response }
29
26
  end
@@ -66,6 +63,7 @@ describe Mackerel::Client do
66
63
 
67
64
  let(:test_client) {
68
65
  Faraday.new do |builder|
66
+ builder.response :raise_error
69
67
  builder.adapter :test do |stubs|
70
68
  stubs.put(api_path) { stubbed_response }
71
69
  end
@@ -108,6 +106,7 @@ describe Mackerel::Client do
108
106
 
109
107
  let(:test_client) {
110
108
  Faraday.new do |builder|
109
+ builder.response :raise_error
111
110
  builder.adapter :test do |stubs|
112
111
  stubs.get(api_path) { stubbed_response }
113
112
  end
@@ -126,7 +125,7 @@ describe Mackerel::Client do
126
125
  'agent-revision' => 'bc2f9f6',
127
126
  'agent-version' => '0.6.1',
128
127
  },
129
- 'type' => 'unknown',
128
+ 'size' => 'standard',
130
129
  'status' => 'working',
131
130
  'memo' => 'test host',
132
131
  'isRetired' => false,
@@ -163,6 +162,7 @@ describe Mackerel::Client do
163
162
 
164
163
  let(:test_client) {
165
164
  Faraday.new do |builder|
165
+ builder.response :raise_error
166
166
  builder.adapter :test do |stubs|
167
167
  stubs.post(api_path) { stubbed_response }
168
168
  end
@@ -198,6 +198,7 @@ describe Mackerel::Client do
198
198
 
199
199
  let(:test_client) {
200
200
  Faraday.new do |builder|
201
+ builder.response :raise_error
201
202
  builder.adapter :test do |stubs|
202
203
  stubs.put(api_path) { stubbed_response }
203
204
  end
@@ -240,6 +241,7 @@ describe Mackerel::Client do
240
241
 
241
242
  let(:test_client) {
242
243
  Faraday.new do |builder|
244
+ builder.response :raise_error
243
245
  builder.adapter :test do |stubs|
244
246
  stubs.post(api_path) { stubbed_response }
245
247
  end
@@ -274,6 +276,7 @@ describe Mackerel::Client do
274
276
 
275
277
  let(:test_client) {
276
278
  Faraday.new do |builder|
279
+ builder.response :raise_error
277
280
  builder.adapter :test do |stubs|
278
281
  stubs.post(api_path) { stubbed_response }
279
282
  end
@@ -331,6 +334,7 @@ describe Mackerel::Client do
331
334
 
332
335
  let(:test_client) {
333
336
  Faraday.new do |builder|
337
+ builder.response :raise_error
334
338
  builder.adapter :test do |stubs|
335
339
  stubs.get(api_path) { stubbed_response }
336
340
  end
@@ -350,7 +354,7 @@ describe Mackerel::Client do
350
354
  'agent-revision' => 'bc2f9f6',
351
355
  'agent-version' => '0.6.1',
352
356
  },
353
- 'type' => 'unknown',
357
+ 'size' => 'standard',
354
358
  'status' => 'working',
355
359
  'memo' => 'test host',
356
360
  'isRetired' => false,
@@ -392,6 +396,7 @@ describe Mackerel::Client do
392
396
 
393
397
  let(:test_client) {
394
398
  Faraday.new do |builder|
399
+ builder.response :raise_error
395
400
  builder.adapter :test do |stubs|
396
401
  stubs.post(api_path) { stubbed_response }
397
402
  end
@@ -437,6 +442,7 @@ describe Mackerel::Client do
437
442
 
438
443
  let(:test_client) {
439
444
  Faraday.new do |builder|
445
+ builder.response :raise_error
440
446
  builder.adapter :test do |stubs|
441
447
  stubs.get(api_path) { stubbed_response }
442
448
  end
@@ -470,6 +476,7 @@ describe Mackerel::Client do
470
476
 
471
477
  let(:test_client) {
472
478
  Faraday.new do |builder|
479
+ builder.response :raise_error
473
480
  builder.adapter :test do |stubs|
474
481
  stubs.get(api_path) { stubbed_response }
475
482
  end
@@ -505,6 +512,7 @@ describe Mackerel::Client do
505
512
 
506
513
  let(:test_client) {
507
514
  Faraday.new do |builder|
515
+ builder.response :raise_error
508
516
  builder.adapter :test do |stubs|
509
517
  stubs.put(api_path) { stubbed_response }
510
518
  end
@@ -544,6 +552,7 @@ describe Mackerel::Client do
544
552
 
545
553
  let(:test_client) {
546
554
  Faraday.new do |builder|
555
+ builder.response :raise_error
547
556
  builder.adapter :test do |stubs|
548
557
  stubs.delete(api_path) { stubbed_response }
549
558
  end
@@ -1,8 +1,4 @@
1
- require 'mackerel'
2
- require 'mackerel/host'
3
- require 'json'
4
-
5
- describe Mackerel::Client do
1
+ RSpec.describe Mackerel::Client do
6
2
  let(:api_key) { 'xxxxxxxx' }
7
3
  let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
4
 
@@ -17,6 +13,7 @@ describe Mackerel::Client do
17
13
 
18
14
  let(:test_client) {
19
15
  Faraday.new do |builder|
16
+ builder.response :raise_error
20
17
  builder.adapter :test do |stubs|
21
18
  stubs.post(api_path) { stubbed_response }
22
19
  end
@@ -65,6 +62,7 @@ describe Mackerel::Client do
65
62
 
66
63
  let(:test_client) {
67
64
  Faraday.new do |builder|
65
+ builder.response :raise_error
68
66
  builder.adapter :test do |stubs|
69
67
  stubs.put(api_path) { stubbed_response }
70
68
  end
@@ -114,6 +112,7 @@ describe Mackerel::Client do
114
112
 
115
113
  let(:test_client) {
116
114
  Faraday.new do |builder|
115
+ builder.response :raise_error
117
116
  builder.adapter :test do |stubs|
118
117
  stubs.get(api_path) { stubbed_response }
119
118
  end
@@ -164,6 +163,7 @@ describe Mackerel::Client do
164
163
 
165
164
  let(:test_client) {
166
165
  Faraday.new do |builder|
166
+ builder.response :raise_error
167
167
  builder.adapter :test do |stubs|
168
168
  stubs.get(api_path) { stubbed_response }
169
169
  end
@@ -212,6 +212,7 @@ describe Mackerel::Client do
212
212
 
213
213
  let(:test_client) {
214
214
  Faraday.new do |builder|
215
+ builder.response :raise_error
215
216
  builder.adapter :test do |stubs|
216
217
  stubs.delete(api_path) { stubbed_response }
217
218
  end
@@ -1,8 +1,4 @@
1
- require 'mackerel'
2
- require 'mackerel/host'
3
- require 'json'
4
-
5
- describe Mackerel::Client do
1
+ RSpec.describe Mackerel::Client do
6
2
  let(:api_key) { 'xxxxxxxx' }
7
3
  let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
4
 
@@ -19,6 +15,7 @@ describe Mackerel::Client do
19
15
 
20
16
  let(:test_client) {
21
17
  Faraday.new do |builder|
18
+ builder.response :raise_error
22
19
  builder.adapter :test do |stubs|
23
20
  stubs.post(api_path) { stubbed_response }
24
21
  end
@@ -60,6 +57,7 @@ describe Mackerel::Client do
60
57
 
61
58
  let(:test_client) {
62
59
  Faraday.new do |builder|
60
+ builder.response :raise_error
63
61
  builder.adapter :test do |stubs|
64
62
  stubs.post(api_path) { stubbed_response }
65
63
  end
@@ -1,8 +1,4 @@
1
- require 'mackerel'
2
- require 'mackerel/host'
3
- require 'json'
4
-
5
- describe Mackerel::Client do
1
+ RSpec.describe Mackerel::Client do
6
2
  let(:api_key) { 'xxxxxxxx' }
7
3
  let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
4
 
@@ -17,6 +13,7 @@ describe Mackerel::Client do
17
13
 
18
14
  let(:test_client) {
19
15
  Faraday.new do |builder|
16
+ builder.response :raise_error
20
17
  builder.adapter :test do |stubs|
21
18
  stubs.post(api_path) { stubbed_response }
22
19
  end
@@ -56,6 +53,7 @@ describe Mackerel::Client do
56
53
 
57
54
  let(:test_client) {
58
55
  Faraday.new do |builder|
56
+ builder.response :raise_error
59
57
  builder.adapter :test do |stubs|
60
58
  stubs.get(api_path) { stubbed_response }
61
59
  end
@@ -102,6 +100,7 @@ describe Mackerel::Client do
102
100
 
103
101
  let(:test_client) {
104
102
  Faraday.new do |builder|
103
+ builder.response :raise_error
105
104
  builder.adapter :test do |stubs|
106
105
  stubs.get(api_path) { stubbed_response }
107
106
  end
@@ -145,6 +144,7 @@ describe Mackerel::Client do
145
144
 
146
145
  let(:test_client) {
147
146
  Faraday.new do |builder|
147
+ builder.response :raise_error
148
148
  builder.adapter :test do |stubs|
149
149
  stubs.post(api_path) { stubbed_response }
150
150
  end
@@ -185,6 +185,7 @@ describe Mackerel::Client do
185
185
 
186
186
  let(:test_client) {
187
187
  Faraday.new do |builder|
188
+ builder.response :raise_error
188
189
  builder.adapter :test do |stubs|
189
190
  stubs.get(api_path) { stubbed_response }
190
191
  end
@@ -226,6 +227,7 @@ describe Mackerel::Client do
226
227
 
227
228
  let(:test_client) {
228
229
  Faraday.new do |builder|
230
+ builder.response :raise_error
229
231
  builder.adapter :test do |stubs|
230
232
  stubs.post(api_path) { stubbed_response }
231
233
  end
@@ -1,8 +1,4 @@
1
- require 'mackerel'
2
- require 'mackerel/host'
3
- require 'json'
4
-
5
- describe Mackerel::Client do
1
+ RSpec.describe Mackerel::Client do
6
2
  let(:api_key) { 'xxxxxxxx' }
7
3
  let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
4
 
@@ -17,6 +13,7 @@ describe Mackerel::Client do
17
13
 
18
14
  let(:test_client) {
19
15
  Faraday.new do |builder|
16
+ builder.response :raise_error
20
17
  builder.adapter :test do |stubs|
21
18
  stubs.post(api_path) { stubbed_response }
22
19
  end
@@ -63,6 +60,7 @@ describe Mackerel::Client do
63
60
 
64
61
  let(:test_client) {
65
62
  Faraday.new do |builder|
63
+ builder.response :raise_error
66
64
  builder.adapter :test do |stubs|
67
65
  stubs.get(api_path) { stubbed_response }
68
66
  end
@@ -129,6 +127,7 @@ describe Mackerel::Client do
129
127
 
130
128
  let(:test_client) {
131
129
  Faraday.new do |builder|
130
+ builder.response :raise_error
132
131
  builder.adapter :test do |stubs|
133
132
  stubs.put(api_path) { stubbed_response }
134
133
  end
@@ -177,6 +176,7 @@ describe Mackerel::Client do
177
176
 
178
177
  let(:test_client) {
179
178
  Faraday.new do |builder|
179
+ builder.response :raise_error
180
180
  builder.adapter :test do |stubs|
181
181
  stubs.delete(api_path) { stubbed_response }
182
182
  end
@@ -1,8 +1,4 @@
1
- require 'mackerel'
2
- require 'mackerel/host'
3
- require 'json'
4
-
5
- describe Mackerel::Client do
1
+ RSpec.describe Mackerel::Client do
6
2
  let(:api_key) { 'xxxxxxxx' }
7
3
  let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
4
 
@@ -17,6 +13,7 @@ describe Mackerel::Client do
17
13
 
18
14
  let(:test_client) {
19
15
  Faraday.new do |builder|
16
+ builder.response :raise_error
20
17
  builder.adapter :test do |stubs|
21
18
  stubs.post(api_path) { stubbed_response }
22
19
  end
@@ -1,8 +1,4 @@
1
- require 'mackerel'
2
- require 'mackerel/host'
3
- require 'json'
4
-
5
- describe Mackerel::Client do
1
+ RSpec.describe Mackerel::Client do
6
2
  let(:api_key) { 'xxxxxxxx' }
7
3
  let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
4
 
@@ -17,6 +13,7 @@ describe Mackerel::Client do
17
13
 
18
14
  let(:test_client) {
19
15
  Faraday.new do |builder|
16
+ builder.response :raise_error
20
17
  builder.adapter :test do |stubs|
21
18
  stubs.post(api_path) { stubbed_response }
22
19
  end
@@ -80,6 +77,7 @@ describe Mackerel::Client do
80
77
 
81
78
  let(:test_client) {
82
79
  Faraday.new do |builder|
80
+ builder.response :raise_error
83
81
  builder.adapter :test do |stubs|
84
82
  stubs.get(api_path) { stubbed_response }
85
83
  end
@@ -163,6 +161,7 @@ describe Mackerel::Client do
163
161
 
164
162
  let(:test_client) {
165
163
  Faraday.new do |builder|
164
+ builder.response :raise_error
166
165
  builder.adapter :test do |stubs|
167
166
  stubs.put(api_path) { stubbed_response }
168
167
  end
@@ -223,6 +222,7 @@ describe Mackerel::Client do
223
222
 
224
223
  let(:test_client) {
225
224
  Faraday.new do |builder|
225
+ builder.response :raise_error
226
226
  builder.adapter :test do |stubs|
227
227
  stubs.delete(api_path) { stubbed_response }
228
228
  end
@@ -1,8 +1,4 @@
1
- require 'mackerel'
2
- require 'mackerel/host'
3
- require 'json'
4
-
5
- describe Mackerel::Client do
1
+ RSpec.describe Mackerel::Client do
6
2
  let(:api_key) { 'xxxxxxxx' }
7
3
  let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
4
 
@@ -19,6 +15,7 @@ describe Mackerel::Client do
19
15
 
20
16
  let(:test_client) {
21
17
  Faraday.new do |builder|
18
+ builder.response :raise_error
22
19
  builder.adapter :test do |stubs|
23
20
  stubs.get(api_path) { stubbed_response }
24
21
  end
@@ -1,8 +1,4 @@
1
- require 'mackerel'
2
- require 'mackerel/host'
3
- require 'json'
4
-
5
- describe Mackerel::Client do
1
+ RSpec.describe Mackerel::Client do
6
2
  let(:api_key) { 'xxxxxxxx' }
7
3
  let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
4
 
@@ -19,6 +15,7 @@ describe Mackerel::Client do
19
15
 
20
16
  let(:test_client) {
21
17
  Faraday.new do |builder|
18
+ builder.response :raise_error
22
19
  builder.adapter :test do |stubs|
23
20
  stubs.get(api_path) { stubbed_response }
24
21
  end
@@ -75,6 +72,7 @@ describe Mackerel::Client do
75
72
 
76
73
  let(:test_client) {
77
74
  Faraday.new do |builder|
75
+ builder.response :raise_error
78
76
  builder.adapter :test do |stubs|
79
77
  stubs.get(api_path) { stubbed_response }
80
78
  end
@@ -124,6 +122,7 @@ describe Mackerel::Client do
124
122
 
125
123
  let(:test_client) {
126
124
  Faraday.new do |builder|
125
+ builder.response :raise_error
127
126
  builder.adapter :test do |stubs|
128
127
  stubs.get(api_path) { stubbed_response }
129
128
  end
@@ -1,8 +1,4 @@
1
- require 'mackerel'
2
- require 'mackerel/host'
3
- require 'json'
4
-
5
- describe Mackerel::Client do
1
+ RSpec.describe Mackerel::Client do
6
2
  let(:api_key) { 'xxxxxxxx' }
7
3
  let(:client) { Mackerel::Client.new(:mackerel_api_key => api_key) }
8
4
 
@@ -19,6 +15,7 @@ describe Mackerel::Client do
19
15
 
20
16
  let(:test_client) {
21
17
  Faraday.new do |builder|
18
+ builder.response :raise_error
22
19
  builder.adapter :test do |stubs|
23
20
  stubs.get(api_path) { stubbed_response }
24
21
  end
@@ -68,6 +65,7 @@ describe Mackerel::Client do
68
65
 
69
66
  let(:test_client) {
70
67
  Faraday.new do |builder|
68
+ builder.response :raise_error
71
69
  builder.adapter :test do |stubs|
72
70
  stubs.delete(api_path) { stubbed_response }
73
71
  end
data/spec/spec_helper.rb CHANGED
@@ -1,2 +1,10 @@
1
1
  $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'mackerel'
3
+
4
+ RSpec.configure do |config|
5
+ config.disable_monkey_patching!
6
+ config.filter_run_when_matching :focus
7
+
8
+ config.order = :random
9
+ Kernel.srand config.seed
10
+ 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.5.0
4
+ version: 0.10.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: 2018-03-01 00:00:00.000000000 Z
11
+ date: 2021-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -16,56 +16,56 @@ 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
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '1.5'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '1.5'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rspec
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '2'
61
+ version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '2'
68
+ version: '0'
69
69
  description: Mackerel client is a library to access Mackerel (https://mackerel.io/).
70
70
  email:
71
71
  - developers@mackerel.io
@@ -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,7 @@ files:
100
102
  - lib/mackerel/client.rb
101
103
  - lib/mackerel/client/helper.rb
102
104
  - lib/mackerel/dashboard.rb
105
+ - lib/mackerel/error.rb
103
106
  - lib/mackerel/host.rb
104
107
  - lib/mackerel/invitation.rb
105
108
  - lib/mackerel/metadata.rb
@@ -115,6 +118,7 @@ files:
115
118
  - mackerel-client.gemspec
116
119
  - spec/mackerel/alert_spec.rb
117
120
  - spec/mackerel/annotation_spec.rb
121
+ - spec/mackerel/api_commend_spec.rb
118
122
  - spec/mackerel/channel_spec.rb
119
123
  - spec/mackerel/client/helper_spec.rb
120
124
  - spec/mackerel/client_spec.rb
@@ -132,7 +136,7 @@ homepage: https://mackerel.io/
132
136
  licenses:
133
137
  - Apache 2
134
138
  metadata: {}
135
- post_install_message:
139
+ post_install_message:
136
140
  rdoc_options: []
137
141
  require_paths:
138
142
  - lib
@@ -147,14 +151,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
151
  - !ruby/object:Gem::Version
148
152
  version: '0'
149
153
  requirements: []
150
- rubyforge_project:
151
- rubygems_version: 2.7.6
152
- signing_key:
154
+ rubygems_version: 3.2.10
155
+ signing_key:
153
156
  specification_version: 4
154
157
  summary: Mackerel client implemented by Ruby.
155
158
  test_files:
156
159
  - spec/mackerel/alert_spec.rb
157
160
  - spec/mackerel/annotation_spec.rb
161
+ - spec/mackerel/api_commend_spec.rb
158
162
  - spec/mackerel/channel_spec.rb
159
163
  - spec/mackerel/client/helper_spec.rb
160
164
  - spec/mackerel/client_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"