pingdom_client_v3 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,125 @@
1
+ require_relative '../../spec_helper'
2
+
3
+ module PingdomClientV3
4
+ RSpec.describe Resources::Check do
5
+ include_context :pingdom_client
6
+
7
+ subject { described_class.new(pingdom_client) }
8
+
9
+ describe '#index', vcr: { cassette_name: 'resources/check/index' } do
10
+ let(:response) { subject.index }
11
+
12
+ it 'returns a PingdomClientV3::Response' do
13
+ expect(response).to be_a PingdomClientV3::Response
14
+ end
15
+
16
+ it 'is successful' do
17
+ expect(response.success?).to be_truthy
18
+ end
19
+
20
+ it 'returns a hash' do
21
+ expect(response.body).to be_a Hash
22
+ end
23
+
24
+ context 'sanity check' do
25
+ let(:check) { response.response_object['checks'].first }
26
+
27
+ it 'is a check' do
28
+ expect(check['id']).to eq 13904858
29
+ expect(check['name']).to eq 'google'
30
+ expect(check['hostname']).to eq 'google.com'
31
+ end
32
+ end
33
+ end
34
+
35
+ describe '#show', vcr: { cassette_name: 'resources/check/show' } do
36
+ let(:response) { subject.show(13904898) }
37
+
38
+ it 'returns a PingdomClientV3::Response' do
39
+ expect(response).to be_a PingdomClientV3::Response
40
+ end
41
+
42
+ it 'is successful' do
43
+ expect(response.success?).to be_truthy
44
+ end
45
+
46
+ it 'returns a hash' do
47
+ expect(response.body).to be_a Hash
48
+ end
49
+
50
+ context 'sanity check' do
51
+ let(:check) { response.response_object['check'] }
52
+
53
+ it 'is a check' do
54
+ expect(check['id']).to eq 13904898
55
+ expect(check['name']).to eq 'a test check'
56
+ expect(check['hostname']).to eq 'google.com'
57
+ end
58
+ end
59
+ end
60
+
61
+ describe '#create', vcr: { cassette_name: 'resources/check/create' } do
62
+ let(:payload) do
63
+ {
64
+ host: 'google.com',
65
+ name: 'a test check',
66
+ type: 'http'
67
+ }
68
+ end
69
+ let(:response) { subject.create(payload) }
70
+
71
+ it 'returns a PingdomClientV3::Response' do
72
+ expect(response).to be_a PingdomClientV3::Response
73
+ end
74
+
75
+ it 'is successful' do
76
+ expect(response.success?).to be_truthy
77
+ end
78
+
79
+ it 'returns a hash' do
80
+ expect(response.body).to be_a Hash
81
+ end
82
+
83
+ context 'sanity check' do
84
+ let(:check) { response.response_object['check'] }
85
+
86
+ it 'is a check' do
87
+ expect(check['id']).to eq 13904898
88
+ expect(check['name']).to eq 'a test check'
89
+ end
90
+ end
91
+ end
92
+
93
+ describe '#destroy', vcr: { cassette_name: 'resources/check/destroy' } do
94
+ let(:payload) do
95
+ {
96
+ host: 'google.com',
97
+ name: 'a test check to destroy',
98
+ type: 'http'
99
+ }
100
+ end
101
+ let(:create_response) { subject.create(payload) }
102
+ let(:response) { subject.destroy(create_response.response_object['check']['id']) }
103
+
104
+ it 'returns a PingdomClientV3::Response' do
105
+ expect(response).to be_a PingdomClientV3::Response
106
+ end
107
+
108
+ it 'is successful' do
109
+ expect(response.success?).to be_truthy
110
+ end
111
+
112
+ it 'returns a hash' do
113
+ expect(response.body).to be_a Hash
114
+ end
115
+
116
+ context 'sanity check' do
117
+ let(:message) { response.response_object['message'] }
118
+
119
+ it 'deletes the check' do
120
+ expect(message).to eq 'Deletion of check was successful!'
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,18 @@
1
+ require_relative '../spec_helper'
2
+
3
+ module PingdomClientV3
4
+ RSpec.describe ResponseObject do
5
+ let(:original_response) { double }
6
+
7
+ subject { described_class.new(attrs) }
8
+
9
+ describe '#initialize' do
10
+ let(:attrs) { { :method_1 => 'value', :method_2 => 'value 2', :PascalCase => 1 } }
11
+
12
+ it 'transform hash keys into methods' do
13
+ expect(subject[:method_1]).to eq 'value'
14
+ expect(subject[:method_2]).to eq 'value 2'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,86 @@
1
+ require_relative '../spec_helper'
2
+ require 'json'
3
+
4
+ module PingdomClientV3
5
+ RSpec.describe Response do
6
+ let(:original_response) { double }
7
+
8
+ subject { described_class.new(original_response) }
9
+
10
+ describe '#success?' do
11
+ let(:original_response) { double(:code => code) }
12
+
13
+ context 'when code between 200..226' do
14
+ let(:code) { 200 }
15
+
16
+ it 'returns true' do
17
+ expect(subject.success?).to be_truthy
18
+ end
19
+ end
20
+
21
+ context 'when code is not between 200..226' do
22
+ let(:code) { 500 }
23
+
24
+ it 'returns true' do
25
+ expect(subject.success?).to be_falsey
26
+ end
27
+ end
28
+ end
29
+
30
+ describe '#failure?' do
31
+ let(:original_response) { double(:code => code) }
32
+
33
+ context 'when code is not between 200..226' do
34
+ let(:code) { 500 }
35
+
36
+ it 'returns true' do
37
+ expect(subject.failure?).to be_truthy
38
+ end
39
+ end
40
+
41
+ context 'when code between 200..226' do
42
+ let(:code) { 200 }
43
+
44
+ it 'returns true' do
45
+ expect(subject.failure?).to be_falsey
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#body' do
51
+ let(:hash) { { 'some' => 'response' } }
52
+ let(:original_response) { double(body: JSON.dump(hash)) }
53
+
54
+ it 'parses json into a hash' do
55
+ expect(subject.body).to eq hash
56
+ end
57
+ end
58
+
59
+ describe '#original_body' do
60
+ let(:hash) { { :some => 'response' } }
61
+ let(:original_response) { double(body: JSON.dump(hash)) }
62
+
63
+ it 'returns the raw json' do
64
+ expect(subject.original_body).to eq JSON.dump(hash)
65
+ end
66
+ end
67
+
68
+ describe '#response_object' do
69
+ let(:original_response) {double(body: JSON.dump(:code => '1234')) }
70
+
71
+ it 'returns a ResponseObject' do
72
+ expect(subject.response_object).to be_a PingdomClientV3::ResponseObject
73
+ end
74
+
75
+ context 'when it is an array' do
76
+ let(:original_response) { double(body: JSON.dump([{:code => '1234'}, {:code => '12345'}])) }
77
+
78
+ it 'returns an array of ResponseObject' do
79
+ expect(subject.response_object).to be_an Array
80
+ expect(subject.response_object.size).to eq 2
81
+ expect(subject.response_object.first).to be_a PingdomClientV3::ResponseObject
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,14 @@
1
+ require "bundler/setup"
2
+ require "pingdom_client_v3"
3
+ require "byebug"
4
+
5
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
6
+
7
+ RSpec.configure do |config|
8
+ # Disable RSpec exposing methods globally on `Module` and `main`
9
+ config.disable_monkey_patching!
10
+
11
+ config.expect_with :rspec do |c|
12
+ c.syntax = :expect
13
+ end
14
+ end
@@ -0,0 +1,5 @@
1
+ shared_context :pingdom_client do
2
+ let(:pingdom_api_key) { ENV['PINGDOM_API_KEY'] }
3
+ let(:pingdom_api_url) { 'https://api.pingdom.com/api/3.1' }
4
+ let(:pingdom_client) { PingdomClientV3::Client.new(pingdom_api_key, pingdom_api_url) }
5
+ end
@@ -0,0 +1,19 @@
1
+ require 'vcr'
2
+
3
+ VCR.configure do |c|
4
+ c.cassette_library_dir = 'spec/vcr_cassettes'
5
+ c.hook_into :webmock
6
+ c.configure_rspec_metadata!
7
+ c.before_record do |i|
8
+ i.response.body.force_encoding('UTF-8')
9
+ end
10
+
11
+ c.preserve_exact_body_bytes do |http_message|
12
+ http_message.body.encoding.name == 'ASCII-8BIT' ||
13
+ !http_message.body.valid_encoding?
14
+ end
15
+
16
+ c.filter_sensitive_data('<AUTHORIZATION_TOKEN>') do |interaction|
17
+ interaction.request.headers['Authorization']&.first
18
+ end
19
+ end
@@ -0,0 +1,58 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.pingdom.com/api/3.1/checks
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"host":"google.com","name":"a test check","type":"http"}'
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ User-Agent:
13
+ - rest-client/2.1.0 (darwin22 arm64) ruby/3.2.2p53
14
+ Authorization:
15
+ - "<AUTHORIZATION_TOKEN>"
16
+ Content-Type:
17
+ - application/json
18
+ Content-Length:
19
+ - '57'
20
+ Accept-Encoding:
21
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
22
+ Host:
23
+ - api.pingdom.com
24
+ response:
25
+ status:
26
+ code: 200
27
+ message: OK
28
+ headers:
29
+ Date:
30
+ - Thu, 15 May 2025 03:54:34 GMT
31
+ Content-Type:
32
+ - application/json
33
+ Content-Length:
34
+ - '47'
35
+ Connection:
36
+ - keep-alive
37
+ Cache-Control:
38
+ - no-cache
39
+ Req-Limit-Long:
40
+ - 'Remaining: 2087982 Time until reset: 2576731'
41
+ Req-Limit-Short:
42
+ - 'Remaining: 11593 Time until reset: 1322'
43
+ Server-Time:
44
+ - '1747281274'
45
+ X-Trace:
46
+ - 2B77AF6DF5C01D8D77CA59038991E6CF8F245E0D01803B70B491B4379E00
47
+ Cf-Cache-Status:
48
+ - DYNAMIC
49
+ Server:
50
+ - cloudflare
51
+ Cf-Ray:
52
+ - 93ffb1d45912d723-BNE
53
+ body:
54
+ encoding: UTF-8
55
+ string: '{"check":{"id":13904898,"name":"a test check"}}'
56
+ http_version:
57
+ recorded_at: Thu, 15 May 2025 03:54:34 GMT
58
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,109 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://api.pingdom.com/api/3.1/checks
6
+ body:
7
+ encoding: UTF-8
8
+ string: '{"host":"google.com","name":"a test check to destroy","type":"http"}'
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ User-Agent:
13
+ - rest-client/2.1.0 (darwin22 arm64) ruby/3.2.2p53
14
+ Authorization:
15
+ - "<AUTHORIZATION_TOKEN>"
16
+ Content-Type:
17
+ - application/json
18
+ Content-Length:
19
+ - '68'
20
+ Accept-Encoding:
21
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
22
+ Host:
23
+ - api.pingdom.com
24
+ response:
25
+ status:
26
+ code: 200
27
+ message: OK
28
+ headers:
29
+ Date:
30
+ - Thu, 15 May 2025 03:57:52 GMT
31
+ Content-Type:
32
+ - application/json
33
+ Transfer-Encoding:
34
+ - chunked
35
+ Connection:
36
+ - keep-alive
37
+ Cache-Control:
38
+ - no-cache
39
+ Req-Limit-Long:
40
+ - 'Remaining: 2087979 Time until reset: 2576533'
41
+ Req-Limit-Short:
42
+ - 'Remaining: 11590 Time until reset: 1124'
43
+ Server-Time:
44
+ - '1747281472'
45
+ X-Trace:
46
+ - 2BFD9E9330B4C76F32A5D93B1E44688C48F2FFEAB28AAA23714EF1823A00
47
+ Cf-Cache-Status:
48
+ - DYNAMIC
49
+ Server:
50
+ - cloudflare
51
+ Cf-Ray:
52
+ - 93ffb6ad98874875-BNE
53
+ body:
54
+ encoding: UTF-8
55
+ string: '{"check":{"id":13904902,"name":"a test check to destroy"}}'
56
+ http_version:
57
+ recorded_at: Thu, 15 May 2025 03:57:52 GMT
58
+ - request:
59
+ method: delete
60
+ uri: https://api.pingdom.com/api/3.1/checks/13904902
61
+ body:
62
+ encoding: US-ASCII
63
+ string: ''
64
+ headers:
65
+ Accept:
66
+ - "*/*"
67
+ User-Agent:
68
+ - rest-client/2.1.0 (darwin22 arm64) ruby/3.2.2p53
69
+ Authorization:
70
+ - "<AUTHORIZATION_TOKEN>"
71
+ Accept-Encoding:
72
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
73
+ Host:
74
+ - api.pingdom.com
75
+ response:
76
+ status:
77
+ code: 200
78
+ message: OK
79
+ headers:
80
+ Date:
81
+ - Thu, 15 May 2025 03:57:53 GMT
82
+ Content-Type:
83
+ - application/json
84
+ Content-Length:
85
+ - '47'
86
+ Connection:
87
+ - keep-alive
88
+ Cache-Control:
89
+ - no-cache
90
+ Req-Limit-Long:
91
+ - 'Remaining: 2087978 Time until reset: 2576532'
92
+ Req-Limit-Short:
93
+ - 'Remaining: 11589 Time until reset: 1123'
94
+ Server-Time:
95
+ - '1747281473'
96
+ X-Trace:
97
+ - 2B0CA449C5B4F5EE1C9684CF9DABE8D1874480D17E33D722E5A4C2E01F00
98
+ Cf-Cache-Status:
99
+ - DYNAMIC
100
+ Server:
101
+ - cloudflare
102
+ Cf-Ray:
103
+ - 93ffb6b4d920d70c-BNE
104
+ body:
105
+ encoding: UTF-8
106
+ string: '{"message":"Deletion of check was successful!"}'
107
+ http_version:
108
+ recorded_at: Thu, 15 May 2025 03:57:53 GMT
109
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.pingdom.com/api/3.1/checks
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ User-Agent:
13
+ - rest-client/2.1.0 (darwin22 arm64) ruby/3.2.2p53
14
+ Authorization:
15
+ - "<AUTHORIZATION_TOKEN>"
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Host:
19
+ - api.pingdom.com
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Thu, 15 May 2025 02:51:43 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Cache-Control:
34
+ - no-cache
35
+ Req-Limit-Long:
36
+ - 'Remaining: 2087990 Time until reset: 2580502'
37
+ Req-Limit-Short:
38
+ - 'Remaining: 11591 Time until reset: 1476'
39
+ Server-Time:
40
+ - '1747277503'
41
+ X-Trace:
42
+ - 2B39541495636BC807675A88F08918C8D51DA7B4A5968589B22897308400
43
+ Cf-Cache-Status:
44
+ - DYNAMIC
45
+ Server:
46
+ - cloudflare
47
+ Cf-Ray:
48
+ - 93ff55c6ef4dd70f-BNE
49
+ body:
50
+ encoding: UTF-8
51
+ string: '{"checks":[{"id":13904858,"created":1747277371,"name":"google","hostname":"google.com","resolution":1,"type":"http","ipv6":false,"verify_certificate":true,"status":"unknown"}],"counts":{"total":1,"limited":1,"filtered":1}}'
52
+ http_version:
53
+ recorded_at: Thu, 15 May 2025 02:51:43 GMT
54
+ recorded_with: VCR 3.0.3
@@ -0,0 +1,54 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.pingdom.com/api/3.1/checks/13904898
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - "*/*"
12
+ User-Agent:
13
+ - rest-client/2.1.0 (darwin22 arm64) ruby/3.2.2p53
14
+ Authorization:
15
+ - "<AUTHORIZATION_TOKEN>"
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ Host:
19
+ - api.pingdom.com
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Thu, 15 May 2025 03:55:36 GMT
27
+ Content-Type:
28
+ - application/json
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ Cache-Control:
34
+ - no-cache
35
+ Req-Limit-Long:
36
+ - 'Remaining: 2087981 Time until reset: 2576670'
37
+ Req-Limit-Short:
38
+ - 'Remaining: 11592 Time until reset: 1261'
39
+ Server-Time:
40
+ - '1747281336'
41
+ X-Trace:
42
+ - 2BDC8EA31018D89D20BE7E0DBD0363EF660EF38F60EE720D933CE6045100
43
+ Cf-Cache-Status:
44
+ - DYNAMIC
45
+ Server:
46
+ - cloudflare
47
+ Cf-Ray:
48
+ - 93ffb355ab76d734-BNE
49
+ body:
50
+ encoding: UTF-8
51
+ string: '{"check":{"id":13904898,"name":"a test check","resolution":5,"sendnotificationwhendown":2,"notifyagainevery":0,"notifywhenbackup":true,"created":1747281274,"type":{"http":{"verify_certificate":true,"url":"\/","encryption":false,"port":80,"requestheaders":{"User-Agent":"Pingdom.com_bot_version_1.4_(http:\/\/www.pingdom.com\/)"}}},"hostname":"google.com","ipv6":false,"responsetime_threshold":30000,"custom_message":"","integrationids":[],"status":"unknown","tags":[],"probe_filters":[]}}'
52
+ http_version:
53
+ recorded_at: Thu, 15 May 2025 03:55:36 GMT
54
+ recorded_with: VCR 3.0.3