Class: BetterStack::Client
- Inherits:
-
Object
- Object
- BetterStack::Client
- Defined in:
- lib/betterstack/client.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #connection ⇒ Object
- #delete(path) ⇒ Object
- #get(path, params = {}) ⇒ Object
- #heartbeats ⇒ Object
- #incidents ⇒ Object
-
#initialize(configuration = nil) ⇒ Client
constructor
A new instance of Client.
- #monitors ⇒ Object
- #patch(path, body = {}) ⇒ Object
- #post(path, body = {}) ⇒ Object
- #put(path, body = {}) ⇒ Object
- #status_pages ⇒ Object
Constructor Details
#initialize(configuration = nil) ⇒ Client
Returns a new instance of Client.
5 6 7 8 |
# File 'lib/betterstack/client.rb', line 5 def initialize(configuration = nil) @configuration = configuration || BetterStack.configuration raise ConfigurationError, "API token is required" unless @configuration&.valid? end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
3 4 5 |
# File 'lib/betterstack/client.rb', line 3 def configuration @configuration end |
Instance Method Details
#connection ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/betterstack/client.rb', line 26 def connection @connection ||= Faraday.new(url: configuration.base_url) do |conn| conn.request :json conn.request :retry, { max: configuration.retries, interval: 0.5, interval_randomness: 0.5, backoff_factor: 2 } conn.response :json conn.headers["Authorization"] = "Bearer #{configuration.api_token}" conn.headers["User-Agent"] = "BetterStack Ruby Gem #{VERSION}" conn..timeout = configuration.timeout end end |
#delete(path) ⇒ Object
62 63 64 65 |
# File 'lib/betterstack/client.rb', line 62 def delete(path) response = connection.delete(path) handle_response(response) end |
#get(path, params = {}) ⇒ Object
42 43 44 45 |
# File 'lib/betterstack/client.rb', line 42 def get(path, params = {}) response = connection.get(path, params) handle_response(response) end |
#heartbeats ⇒ Object
14 15 16 |
# File 'lib/betterstack/client.rb', line 14 def heartbeats @heartbeats ||= Resources::Heartbeat.new(self) end |
#incidents ⇒ Object
22 23 24 |
# File 'lib/betterstack/client.rb', line 22 def incidents @incidents ||= Resources::Incident.new(self) end |
#monitors ⇒ Object
10 11 12 |
# File 'lib/betterstack/client.rb', line 10 def monitors @monitors ||= Resources::Monitor.new(self) end |
#patch(path, body = {}) ⇒ Object
57 58 59 60 |
# File 'lib/betterstack/client.rb', line 57 def patch(path, body = {}) response = connection.patch(path, body) handle_response(response) end |
#post(path, body = {}) ⇒ Object
47 48 49 50 |
# File 'lib/betterstack/client.rb', line 47 def post(path, body = {}) response = connection.post(path, body) handle_response(response) end |
#put(path, body = {}) ⇒ Object
52 53 54 55 |
# File 'lib/betterstack/client.rb', line 52 def put(path, body = {}) response = connection.put(path, body) handle_response(response) end |
#status_pages ⇒ Object
18 19 20 |
# File 'lib/betterstack/client.rb', line 18 def status_pages @status_pages ||= Resources::StatusPage.new(self) end |