Class: BetterStack::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/betterstack/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(configuration = nil) ⇒ Client

Returns a new instance of Client.

Raises:



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

#configurationObject (readonly)

Returns the value of attribute configuration.



3
4
5
# File 'lib/betterstack/client.rb', line 3

def configuration
  @configuration
end

Instance Method Details

#connectionObject



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.options.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

#heartbeatsObject



14
15
16
# File 'lib/betterstack/client.rb', line 14

def heartbeats
  @heartbeats ||= Resources::Heartbeat.new(self)
end

#incidentsObject



22
23
24
# File 'lib/betterstack/client.rb', line 22

def incidents
  @incidents ||= Resources::Incident.new(self)
end

#monitorsObject



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_pagesObject



18
19
20
# File 'lib/betterstack/client.rb', line 18

def status_pages
  @status_pages ||= Resources::StatusPage.new(self)
end