betterstack 1.0.0
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.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +17 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +99 -0
- data/README.md +163 -0
- data/Rakefile +8 -0
- data/betterstack.gemspec +32 -0
- data/lib/betterstack/client.rb +94 -0
- data/lib/betterstack/configuration.rb +15 -0
- data/lib/betterstack/error.rb +17 -0
- data/lib/betterstack/resources/base.rb +23 -0
- data/lib/betterstack/resources/heartbeat.rb +47 -0
- data/lib/betterstack/resources/incident.rb +52 -0
- data/lib/betterstack/resources/monitor.rb +51 -0
- data/lib/betterstack/resources/status_page.rb +59 -0
- data/lib/betterstack/version.rb +3 -0
- data/lib/betterstack.rb +31 -0
- metadata +159 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 65d5971eb409798b8a6e441b2fc117d254f0dd234016fe8261e1eebb7f80e709
|
4
|
+
data.tar.gz: 2546bb4b6a26854ac460b255fec9c28227f21f0be3e0a0fd1b18648145fea5a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 19507ec7b6ee9f49592c7e51873a2afca80367f7c20e3d39c0ef9032ec6b8c10fd715a7a88577bcbc5b65842ea05fd9d01862b435edfdbebac49e4fb2cfcea0d
|
7
|
+
data.tar.gz: e6abb2f150469ea4655776ca13f0d45cc1afee4b2c4902a8acc862c069b89c35fe64b9fb1f6c48f64aaed4115f4f4703a847894b5129a8dc435b0147eff97b85
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.7
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Style/Documentation:
|
6
|
+
Enabled: false
|
7
|
+
|
8
|
+
Style/StringLiterals:
|
9
|
+
EnforcedStyle: double_quotes
|
10
|
+
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Exclude:
|
13
|
+
- "spec/**/*"
|
14
|
+
- "*.gemspec"
|
15
|
+
|
16
|
+
Layout/LineLength:
|
17
|
+
Max: 120
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
betterstack (1.0.0)
|
5
|
+
faraday (~> 2.0)
|
6
|
+
faraday-retry (~> 2.0)
|
7
|
+
json (~> 2.0)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.8.7)
|
13
|
+
public_suffix (>= 2.0.2, < 7.0)
|
14
|
+
ast (2.4.3)
|
15
|
+
base64 (0.3.0)
|
16
|
+
bigdecimal (3.2.2)
|
17
|
+
crack (1.0.0)
|
18
|
+
bigdecimal
|
19
|
+
rexml
|
20
|
+
diff-lcs (1.6.2)
|
21
|
+
faraday (2.13.1)
|
22
|
+
faraday-net_http (>= 2.0, < 3.5)
|
23
|
+
json
|
24
|
+
logger
|
25
|
+
faraday-net_http (3.4.0)
|
26
|
+
net-http (>= 0.5.0)
|
27
|
+
faraday-retry (2.3.1)
|
28
|
+
faraday (~> 2.0)
|
29
|
+
hashdiff (1.2.0)
|
30
|
+
json (2.12.2)
|
31
|
+
language_server-protocol (3.17.0.5)
|
32
|
+
lint_roller (1.1.0)
|
33
|
+
logger (1.7.0)
|
34
|
+
net-http (0.6.0)
|
35
|
+
uri
|
36
|
+
parallel (1.27.0)
|
37
|
+
parser (3.3.8.0)
|
38
|
+
ast (~> 2.4.1)
|
39
|
+
racc
|
40
|
+
prism (1.4.0)
|
41
|
+
public_suffix (6.0.2)
|
42
|
+
racc (1.8.1)
|
43
|
+
rainbow (3.1.1)
|
44
|
+
rake (13.3.0)
|
45
|
+
regexp_parser (2.10.0)
|
46
|
+
rexml (3.4.1)
|
47
|
+
rspec (3.13.1)
|
48
|
+
rspec-core (~> 3.13.0)
|
49
|
+
rspec-expectations (~> 3.13.0)
|
50
|
+
rspec-mocks (~> 3.13.0)
|
51
|
+
rspec-core (3.13.4)
|
52
|
+
rspec-support (~> 3.13.0)
|
53
|
+
rspec-expectations (3.13.5)
|
54
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
55
|
+
rspec-support (~> 3.13.0)
|
56
|
+
rspec-mocks (3.13.5)
|
57
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
58
|
+
rspec-support (~> 3.13.0)
|
59
|
+
rspec-support (3.13.4)
|
60
|
+
rubocop (1.76.1)
|
61
|
+
json (~> 2.3)
|
62
|
+
language_server-protocol (~> 3.17.0.2)
|
63
|
+
lint_roller (~> 1.1.0)
|
64
|
+
parallel (~> 1.10)
|
65
|
+
parser (>= 3.3.0.2)
|
66
|
+
rainbow (>= 2.2.2, < 4.0)
|
67
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
68
|
+
rubocop-ast (>= 1.45.0, < 2.0)
|
69
|
+
ruby-progressbar (~> 1.7)
|
70
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
71
|
+
rubocop-ast (1.45.1)
|
72
|
+
parser (>= 3.3.7.2)
|
73
|
+
prism (~> 1.4)
|
74
|
+
ruby-progressbar (1.13.0)
|
75
|
+
unicode-display_width (3.1.4)
|
76
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
77
|
+
unicode-emoji (4.0.4)
|
78
|
+
uri (1.0.3)
|
79
|
+
vcr (6.3.1)
|
80
|
+
base64
|
81
|
+
webmock (3.25.1)
|
82
|
+
addressable (>= 2.8.0)
|
83
|
+
crack (>= 0.3.2)
|
84
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
85
|
+
|
86
|
+
PLATFORMS
|
87
|
+
arm64-darwin-24
|
88
|
+
ruby
|
89
|
+
|
90
|
+
DEPENDENCIES
|
91
|
+
betterstack!
|
92
|
+
rake (~> 13.0)
|
93
|
+
rspec (~> 3.0)
|
94
|
+
rubocop (~> 1.0)
|
95
|
+
vcr (~> 6.0)
|
96
|
+
webmock (~> 3.0)
|
97
|
+
|
98
|
+
BUNDLED WITH
|
99
|
+
2.6.2
|
data/README.md
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
# BetterStack Ruby Gem
|
2
|
+
|
3
|
+
A comprehensive Ruby client for the Better Stack API, providing easy access to monitors, heartbeats, status pages, incidents, and maintenance windows.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'betterstack'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install betterstack
|
20
|
+
|
21
|
+
## Configuration
|
22
|
+
|
23
|
+
Configure the gem with your Better Stack API token:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
BetterStack.configure do |config|
|
27
|
+
config.api_token = "your_api_token_here"
|
28
|
+
config.timeout = 30 # optional, defaults to 30 seconds
|
29
|
+
config.retries = 3 # optional, defaults to 3 retries
|
30
|
+
end
|
31
|
+
```
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
### Monitors
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
client = BetterStack.client
|
39
|
+
|
40
|
+
# List all monitors
|
41
|
+
monitors = client.monitors.list
|
42
|
+
|
43
|
+
# Get a specific monitor
|
44
|
+
monitor = client.monitors.get(monitor_id)
|
45
|
+
|
46
|
+
# Create a new monitor
|
47
|
+
new_monitor = client.monitors.create({
|
48
|
+
monitor_type: "http",
|
49
|
+
url: "https://example.com",
|
50
|
+
name: "My Website",
|
51
|
+
check_frequency: 60
|
52
|
+
})
|
53
|
+
|
54
|
+
# Update a monitor
|
55
|
+
client.monitors.update(monitor_id, { name: "Updated Name" })
|
56
|
+
|
57
|
+
# Pause/Resume monitors
|
58
|
+
client.monitors.pause(monitor_id)
|
59
|
+
client.monitors.resume(monitor_id)
|
60
|
+
|
61
|
+
# Get response times and availability
|
62
|
+
response_times = client.monitors.response_times(monitor_id)
|
63
|
+
availability = client.monitors.availability(monitor_id)
|
64
|
+
|
65
|
+
# Delete a monitor
|
66
|
+
client.monitors.delete(monitor_id)
|
67
|
+
```
|
68
|
+
|
69
|
+
### Heartbeats
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
# List all heartbeats
|
73
|
+
heartbeats = client.heartbeats.list
|
74
|
+
|
75
|
+
# Create a new heartbeat
|
76
|
+
heartbeat = client.heartbeats.create({
|
77
|
+
name: "Daily Backup",
|
78
|
+
period: 86400,
|
79
|
+
grace: 3600
|
80
|
+
})
|
81
|
+
|
82
|
+
# Send a heartbeat ping
|
83
|
+
client.heartbeats.ping(heartbeat_id)
|
84
|
+
|
85
|
+
# Get heartbeat checks
|
86
|
+
checks = client.heartbeats.checks(heartbeat_id)
|
87
|
+
```
|
88
|
+
|
89
|
+
### Status Pages
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
# List status pages
|
93
|
+
status_pages = client.status_pages.list
|
94
|
+
|
95
|
+
# Create a status page
|
96
|
+
status_page = client.status_pages.create({
|
97
|
+
company_name: "My Company",
|
98
|
+
subdomain: "status",
|
99
|
+
timezone: "UTC"
|
100
|
+
})
|
101
|
+
|
102
|
+
# Add resources to status page
|
103
|
+
client.status_pages.add_resource(status_page_id, {
|
104
|
+
resource_id: monitor_id,
|
105
|
+
resource_type: "Monitor"
|
106
|
+
})
|
107
|
+
|
108
|
+
# Manage subscribers
|
109
|
+
client.status_pages.add_subscriber(status_page_id, {
|
110
|
+
email: "user@example.com"
|
111
|
+
})
|
112
|
+
```
|
113
|
+
|
114
|
+
### Incidents
|
115
|
+
|
116
|
+
```ruby
|
117
|
+
# List incidents
|
118
|
+
incidents = client.incidents.list
|
119
|
+
|
120
|
+
# Create an incident
|
121
|
+
incident = client.incidents.create({
|
122
|
+
name: "Database Connection Issues",
|
123
|
+
summary: "Users experiencing slow response times",
|
124
|
+
affected_resources: [monitor_id]
|
125
|
+
})
|
126
|
+
|
127
|
+
# Add incident updates
|
128
|
+
client.incidents.add_update(incident_id, {
|
129
|
+
message: "We are investigating the issue",
|
130
|
+
status: "investigating"
|
131
|
+
})
|
132
|
+
|
133
|
+
# Resolve incident
|
134
|
+
client.incidents.resolve(incident_id, "Issue has been resolved")
|
135
|
+
```
|
136
|
+
|
137
|
+
## Error Handling
|
138
|
+
|
139
|
+
The gem provides specific error classes for different API responses:
|
140
|
+
|
141
|
+
```ruby
|
142
|
+
begin
|
143
|
+
monitor = client.monitors.get(invalid_id)
|
144
|
+
rescue BetterStack::NotFoundError => e
|
145
|
+
puts "Monitor not found: #{e.message}"
|
146
|
+
rescue BetterStack::UnauthorizedError => e
|
147
|
+
puts "Invalid API token: #{e.message}"
|
148
|
+
rescue BetterStack::RateLimitError => e
|
149
|
+
puts "Rate limit exceeded: #{e.message}"
|
150
|
+
rescue BetterStack::ValidationError => e
|
151
|
+
puts "Validation failed: #{e.message}"
|
152
|
+
rescue BetterStack::APIError => e
|
153
|
+
puts "API error: #{e.message} (Status: #{e.status})"
|
154
|
+
end
|
155
|
+
```
|
156
|
+
|
157
|
+
## Contributing
|
158
|
+
|
159
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/sundaycarwash/betterstack-ruby.
|
160
|
+
|
161
|
+
## License
|
162
|
+
|
163
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/betterstack.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
Gem::Specification.new do |spec|
|
2
|
+
spec.name = "betterstack"
|
3
|
+
spec.version = "1.0.0"
|
4
|
+
spec.authors = ["Umang Chouhan"]
|
5
|
+
spec.email = ["umang@sundaycarwash.com"]
|
6
|
+
|
7
|
+
spec.summary = "Ruby client for Better Stack API"
|
8
|
+
spec.description = "A comprehensive Ruby gem for interacting with Better Stack's uptime and telemetry APIs"
|
9
|
+
spec.homepage = "https://github.com/sundaycarwash/betterstack-ruby"
|
10
|
+
spec.license = "MIT"
|
11
|
+
spec.required_ruby_version = ">= 2.7.0"
|
12
|
+
|
13
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
14
|
+
spec.metadata["source_code_uri"] = "https://github.com/sundaycarwash/betterstack-ruby"
|
15
|
+
spec.metadata["changelog_uri"] = "https://github.com/sundaycarwash/betterstack-ruby/blob/main/CHANGELOG.md"
|
16
|
+
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency "faraday", "~> 2.0"
|
25
|
+
spec.add_dependency "faraday-retry", "~> 2.0"
|
26
|
+
spec.add_dependency "json", "~> 2.0"
|
27
|
+
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
spec.add_development_dependency "webmock", "~> 3.0"
|
30
|
+
spec.add_development_dependency "vcr", "~> 6.0"
|
31
|
+
spec.add_development_dependency "rubocop", "~> 1.0"
|
32
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module BetterStack
|
2
|
+
class Client
|
3
|
+
attr_reader :configuration
|
4
|
+
|
5
|
+
def initialize(configuration = nil)
|
6
|
+
@configuration = configuration || BetterStack.configuration
|
7
|
+
raise ConfigurationError, "API token is required" unless @configuration&.valid?
|
8
|
+
end
|
9
|
+
|
10
|
+
def monitors
|
11
|
+
@monitors ||= Resources::Monitor.new(self)
|
12
|
+
end
|
13
|
+
|
14
|
+
def heartbeats
|
15
|
+
@heartbeats ||= Resources::Heartbeat.new(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
def status_pages
|
19
|
+
@status_pages ||= Resources::StatusPage.new(self)
|
20
|
+
end
|
21
|
+
|
22
|
+
def incidents
|
23
|
+
@incidents ||= Resources::Incident.new(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def connection
|
27
|
+
@connection ||= Faraday.new(url: configuration.base_url) do |conn|
|
28
|
+
conn.request :json
|
29
|
+
conn.request :retry, {
|
30
|
+
max: configuration.retries,
|
31
|
+
interval: 0.5,
|
32
|
+
interval_randomness: 0.5,
|
33
|
+
backoff_factor: 2
|
34
|
+
}
|
35
|
+
conn.response :json
|
36
|
+
conn.headers["Authorization"] = "Bearer #{configuration.api_token}"
|
37
|
+
conn.headers["User-Agent"] = "BetterStack Ruby Gem #{VERSION}"
|
38
|
+
conn.options.timeout = configuration.timeout
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def get(path, params = {})
|
43
|
+
response = connection.get(path, params)
|
44
|
+
handle_response(response)
|
45
|
+
end
|
46
|
+
|
47
|
+
def post(path, body = {})
|
48
|
+
response = connection.post(path, body)
|
49
|
+
handle_response(response)
|
50
|
+
end
|
51
|
+
|
52
|
+
def put(path, body = {})
|
53
|
+
response = connection.put(path, body)
|
54
|
+
handle_response(response)
|
55
|
+
end
|
56
|
+
|
57
|
+
def patch(path, body = {})
|
58
|
+
response = connection.patch(path, body)
|
59
|
+
handle_response(response)
|
60
|
+
end
|
61
|
+
|
62
|
+
def delete(path)
|
63
|
+
response = connection.delete(path)
|
64
|
+
handle_response(response)
|
65
|
+
end
|
66
|
+
|
67
|
+
private
|
68
|
+
|
69
|
+
def handle_response(response)
|
70
|
+
case response.status
|
71
|
+
when 200..299
|
72
|
+
response.body
|
73
|
+
when 401
|
74
|
+
raise UnauthorizedError.new("Unauthorized", status: response.status, response_body: response.body)
|
75
|
+
when 404
|
76
|
+
raise NotFoundError.new("Resource not found", status: response.status, response_body: response.body)
|
77
|
+
when 422
|
78
|
+
raise ValidationError.new(extract_error_message(response), status: response.status, response_body: response.body)
|
79
|
+
when 429
|
80
|
+
raise RateLimitError.new("Rate limit exceeded", status: response.status, response_body: response.body)
|
81
|
+
else
|
82
|
+
raise APIError.new("API Error: #{response.status}", status: response.status, response_body: response.body)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def extract_error_message(response)
|
87
|
+
if response.body.is_a?(Hash) && response.body["errors"]
|
88
|
+
response.body["errors"].join(", ")
|
89
|
+
else
|
90
|
+
"Validation failed"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module BetterStack
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :api_token, :base_url, :timeout, :retries
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@base_url = "https://uptime.betterstack.com/api/v2"
|
7
|
+
@timeout = 30
|
8
|
+
@retries = 3
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
!api_token.nil? && !api_token.empty?
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module BetterStack
|
2
|
+
class Error < StandardError; end
|
3
|
+
class ConfigurationError < Error; end
|
4
|
+
class APIError < Error
|
5
|
+
attr_reader :status, :response_body
|
6
|
+
|
7
|
+
def initialize(message, status: nil, response_body: nil)
|
8
|
+
super(message)
|
9
|
+
@status = status
|
10
|
+
@response_body = response_body
|
11
|
+
end
|
12
|
+
end
|
13
|
+
class NotFoundError < APIError; end
|
14
|
+
class UnauthorizedError < APIError; end
|
15
|
+
class RateLimitError < APIError; end
|
16
|
+
class ValidationError < APIError; end
|
17
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module BetterStack
|
2
|
+
module Resources
|
3
|
+
class Base
|
4
|
+
attr_reader :client
|
5
|
+
|
6
|
+
def initialize(client)
|
7
|
+
@client = client
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def resource_path(id = nil)
|
13
|
+
path = "#{resource_name}"
|
14
|
+
path += "/#{id}" if id
|
15
|
+
path
|
16
|
+
end
|
17
|
+
|
18
|
+
def resource_name
|
19
|
+
self.class.name.split("::").last.downcase + "s"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module BetterStack
|
2
|
+
module Resources
|
3
|
+
class Heartbeat < Base
|
4
|
+
def list(params = {})
|
5
|
+
client.get(resource_path, params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(id)
|
9
|
+
client.get(resource_path(id))
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(attributes)
|
13
|
+
client.post(resource_path, attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(id, attributes)
|
17
|
+
client.patch(resource_path(id), attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(id)
|
21
|
+
client.delete(resource_path(id))
|
22
|
+
end
|
23
|
+
|
24
|
+
def pause(id)
|
25
|
+
client.post("#{resource_path(id)}/pause")
|
26
|
+
end
|
27
|
+
|
28
|
+
def resume(id)
|
29
|
+
client.post("#{resource_path(id)}/resume")
|
30
|
+
end
|
31
|
+
|
32
|
+
def ping(id, params = {})
|
33
|
+
client.post("#{resource_path(id)}/ping", params)
|
34
|
+
end
|
35
|
+
|
36
|
+
def checks(id, params = {})
|
37
|
+
client.get("#{resource_path(id)}/checks", params)
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def resource_name
|
43
|
+
"heartbeats"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module BetterStack
|
2
|
+
module Resources
|
3
|
+
class Incident < Base
|
4
|
+
def list(params = {})
|
5
|
+
client.get(resource_path, params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(id)
|
9
|
+
client.get(resource_path(id))
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(attributes)
|
13
|
+
client.post(resource_path, attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(id, attributes)
|
17
|
+
client.patch(resource_path(id), attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(id)
|
21
|
+
client.delete(resource_path(id))
|
22
|
+
end
|
23
|
+
|
24
|
+
def resolve(id, message = nil)
|
25
|
+
body = message ? { message: message } : {}
|
26
|
+
client.post("#{resource_path(id)}/resolve", body)
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_update(id, update_attributes)
|
30
|
+
client.post("#{resource_path(id)}/incident_updates", update_attributes)
|
31
|
+
end
|
32
|
+
|
33
|
+
def updates(id, params = {})
|
34
|
+
client.get("#{resource_path(id)}/incident_updates", params)
|
35
|
+
end
|
36
|
+
|
37
|
+
def update_incident_update(id, update_id, attributes)
|
38
|
+
client.patch("#{resource_path(id)}/incident_updates/#{update_id}", attributes)
|
39
|
+
end
|
40
|
+
|
41
|
+
def delete_incident_update(id, update_id)
|
42
|
+
client.delete("#{resource_path(id)}/incident_updates/#{update_id}")
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def resource_name
|
48
|
+
"incidents"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module BetterStack
|
2
|
+
module Resources
|
3
|
+
class Monitor < Base
|
4
|
+
def list(params = {})
|
5
|
+
client.get(resource_path, params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(id)
|
9
|
+
client.get(resource_path(id))
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(attributes)
|
13
|
+
client.post(resource_path, attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(id, attributes)
|
17
|
+
client.patch(resource_path(id), attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(id)
|
21
|
+
client.delete(resource_path(id))
|
22
|
+
end
|
23
|
+
|
24
|
+
def pause(id)
|
25
|
+
client.post("#{resource_path(id)}/pause")
|
26
|
+
end
|
27
|
+
|
28
|
+
def resume(id)
|
29
|
+
client.post("#{resource_path(id)}/resume")
|
30
|
+
end
|
31
|
+
|
32
|
+
def response_times(id, params = {})
|
33
|
+
client.get("#{resource_path(id)}/response-times", params)
|
34
|
+
end
|
35
|
+
|
36
|
+
def availability(id, params = {})
|
37
|
+
client.get("#{resource_path(id)}/availability", params)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test(attributes)
|
41
|
+
client.post("/monitors/test", attributes)
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def resource_name
|
47
|
+
"monitors"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module BetterStack
|
2
|
+
module Resources
|
3
|
+
class StatusPage < Base
|
4
|
+
def list(params = {})
|
5
|
+
client.get(resource_path, params)
|
6
|
+
end
|
7
|
+
|
8
|
+
def get(id)
|
9
|
+
client.get(resource_path(id))
|
10
|
+
end
|
11
|
+
|
12
|
+
def create(attributes)
|
13
|
+
client.post(resource_path, attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(id, attributes)
|
17
|
+
client.patch(resource_path(id), attributes)
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(id)
|
21
|
+
client.delete(resource_path(id))
|
22
|
+
end
|
23
|
+
|
24
|
+
def resources(id, params = {})
|
25
|
+
client.get("#{resource_path(id)}/resources", params)
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_resource(id, resource_attributes)
|
29
|
+
client.post("#{resource_path(id)}/resources", resource_attributes)
|
30
|
+
end
|
31
|
+
|
32
|
+
def update_resource(id, resource_id, attributes)
|
33
|
+
client.patch("#{resource_path(id)}/resources/#{resource_id}", attributes)
|
34
|
+
end
|
35
|
+
|
36
|
+
def remove_resource(id, resource_id)
|
37
|
+
client.delete("#{resource_path(id)}/resources/#{resource_id}")
|
38
|
+
end
|
39
|
+
|
40
|
+
def subscribers(id, params = {})
|
41
|
+
client.get("#{resource_path(id)}/subscribers", params)
|
42
|
+
end
|
43
|
+
|
44
|
+
def add_subscriber(id, subscriber_attributes)
|
45
|
+
client.post("#{resource_path(id)}/subscribers", subscriber_attributes)
|
46
|
+
end
|
47
|
+
|
48
|
+
def remove_subscriber(id, subscriber_id)
|
49
|
+
client.delete("#{resource_path(id)}/subscribers/#{subscriber_id}")
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def resource_name
|
55
|
+
"status-pages"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/betterstack.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require "faraday"
|
2
|
+
require "faraday/retry"
|
3
|
+
require "json"
|
4
|
+
require_relative "betterstack/version"
|
5
|
+
require_relative "betterstack/configuration"
|
6
|
+
require_relative "betterstack/client"
|
7
|
+
require_relative "betterstack/error"
|
8
|
+
require_relative "betterstack/resources/base"
|
9
|
+
require_relative "betterstack/resources/monitor"
|
10
|
+
require_relative "betterstack/resources/heartbeat"
|
11
|
+
require_relative "betterstack/resources/status_page"
|
12
|
+
require_relative "betterstack/resources/incident"
|
13
|
+
|
14
|
+
module BetterStack
|
15
|
+
class << self
|
16
|
+
attr_accessor :configuration
|
17
|
+
|
18
|
+
def configure
|
19
|
+
self.configuration ||= Configuration.new
|
20
|
+
yield(configuration)
|
21
|
+
end
|
22
|
+
|
23
|
+
def client
|
24
|
+
@client ||= Client.new(configuration)
|
25
|
+
end
|
26
|
+
|
27
|
+
def reset_client!
|
28
|
+
@client = nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,159 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: betterstack
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Umang Chouhan
|
8
|
+
bindir: exe
|
9
|
+
cert_chain: []
|
10
|
+
date: 2025-06-12 00:00:00.000000000 Z
|
11
|
+
dependencies:
|
12
|
+
- !ruby/object:Gem::Dependency
|
13
|
+
name: faraday
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
15
|
+
requirements:
|
16
|
+
- - "~>"
|
17
|
+
- !ruby/object:Gem::Version
|
18
|
+
version: '2.0'
|
19
|
+
type: :runtime
|
20
|
+
prerelease: false
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
requirements:
|
23
|
+
- - "~>"
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '2.0'
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: faraday-retry
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '2.0'
|
40
|
+
- !ruby/object:Gem::Dependency
|
41
|
+
name: json
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '2.0'
|
47
|
+
type: :runtime
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.0'
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
name: rspec
|
56
|
+
requirement: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.0'
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '3.0'
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
name: webmock
|
70
|
+
requirement: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '3.0'
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.0'
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: vcr
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '6.0'
|
89
|
+
type: :development
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '6.0'
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: rubocop
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '1.0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '1.0'
|
110
|
+
description: A comprehensive Ruby gem for interacting with Better Stack's uptime and
|
111
|
+
telemetry APIs
|
112
|
+
email:
|
113
|
+
- umang@sundaycarwash.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".rspec"
|
119
|
+
- ".rubocop.yml"
|
120
|
+
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- betterstack.gemspec
|
125
|
+
- lib/betterstack.rb
|
126
|
+
- lib/betterstack/client.rb
|
127
|
+
- lib/betterstack/configuration.rb
|
128
|
+
- lib/betterstack/error.rb
|
129
|
+
- lib/betterstack/resources/base.rb
|
130
|
+
- lib/betterstack/resources/heartbeat.rb
|
131
|
+
- lib/betterstack/resources/incident.rb
|
132
|
+
- lib/betterstack/resources/monitor.rb
|
133
|
+
- lib/betterstack/resources/status_page.rb
|
134
|
+
- lib/betterstack/version.rb
|
135
|
+
homepage: https://github.com/sundaycarwash/betterstack-ruby
|
136
|
+
licenses:
|
137
|
+
- MIT
|
138
|
+
metadata:
|
139
|
+
homepage_uri: https://github.com/sundaycarwash/betterstack-ruby
|
140
|
+
source_code_uri: https://github.com/sundaycarwash/betterstack-ruby
|
141
|
+
changelog_uri: https://github.com/sundaycarwash/betterstack-ruby/blob/main/CHANGELOG.md
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 2.7.0
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubygems_version: 3.6.2
|
157
|
+
specification_version: 4
|
158
|
+
summary: Ruby client for Better Stack API
|
159
|
+
test_files: []
|