module Castle::API
this class is responsible for making requests to api
Constants
- HANDLED_ERRORS
Errors we handle internally
Public Class Methods
call(command, headers = {}, http = nil, config = nil)
click to toggle source
@param command [String] @param headers [Hash] @param http [Net::HTTP] @param config [Castle::Configuration, Castle::SingletonConfiguration
, nil] @return [Hash]
# File lib/castle/api.rb, line 25 def call(command, headers = {}, http = nil, config = nil) Castle::Core::ProcessResponse.call(send_request(command, headers, http, config), config) end
Private Class Methods
send_request(command, headers = {}, http = nil, config = nil)
click to toggle source
@param command [String] @param headers [Hash] @param http [Net::HTTP] @param config [Castle::Configuration, Castle::SingletonConfiguration
]
# File lib/castle/api.rb, line 35 def send_request(command, headers = {}, http = nil, config = nil) config ||= Castle.config raise Castle::ConfigurationError, 'configuration is not valid' unless config.valid? begin Castle::Core::SendRequest.call(command, headers, http, config) 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 # rubocop:disable Style/RaiseArgs raise Castle::RequestError.new(e) # rubocop:enable Style/RaiseArgs end end