Module: Castle::API

Defined in:
lib/castle/api.rb,
lib/castle/api/request.rb,
lib/castle/api/session.rb,
lib/castle/api/response.rb

Overview

this class is responsible for making requests to api

Defined Under Namespace

Modules: Request, Response Classes: Session

Class Method Summary collapse

Class Method Details

.call(command, headers = {}) ⇒ Object

Parameters:

  • command (String)
  • headers (Hash) (defaults to: {})


41
42
43
# File 'lib/castle/api.rb', line 41

def call(command, headers = {})
  Castle::API::Response.call(request(command, headers))
end

.request(command, headers = {}) ⇒ Object

Parameters:

  • command (String)
  • headers (Hash) (defaults to: {})

Raises:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/castle/api.rb', line 22

def request(command, headers = {})
  raise Castle::ConfigurationError, 'configuration is not valid' unless Castle.config.valid?

  begin
    Castle::API::Request.call(
      command,
      Castle.config.api_secret,
      headers
    )
  rescue *HANDLED_ERRORS => e
    # @note We need to initialize the error, as the original error is a cause for this
    # custom exception. If we would do it the default Ruby way, the original error
    # would get converted into a string
    raise Castle::RequestError.new(e) # rubocop:disable Style/RaiseArgs
  end
end