Module: Castle::API

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

Overview

this class is responsible for making requests to api

Defined Under Namespace

Modules: Request, Response

Class Method Summary collapse

Class Method Details

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



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

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

  begin
    Castle::API::Response.call(
      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