Class: Leal::Status::Client

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

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



9
10
11
# File 'lib/leal/status/client.rb', line 9

def initialize(client:)
  @client = client
end

Instance Method Details

#check(request_options: {}, **_params) ⇒ Leal::Status::Types::CheckStatusResponse

Returns the status of the API. No authentication required.

Every response from this API, including this one, carries RateLimit-Limit, RateLimit-Remaining, RateLimit-Reset and RateLimit-Policy. Exceeding the limit returns 429 with Retry-After in seconds.

Examples:

client.status.check

Parameters:

  • request_options (Hash) (defaults to: {})
  • _params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/leal/status/client.rb', line 31

def check(request_options: {}, **_params)
  request = Leal::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "GET",
    path: "api/v1/status",
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Leal::Errors::TimeoutError
  end
  code = response.code.to_i
  if code.between?(200, 299)
    Leal::Status::Types::CheckStatusResponse.load(response.body)
  else
    error_class = Leal::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end