Module: Castle::Core::SendRequest

Defined in:
lib/castle/core/send_request.rb

Overview

this class is responsible for making requests to api

Class Method Summary collapse

Class Method Details

.build(command, headers, config) ⇒ Object

Parameters:



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/castle/core/send_request.rb', line 26

def build(command, headers, config)
  url = "#{config.base_url.path}/#{command.path}"
  request_obj = Net::HTTP.const_get(command.method.to_s.capitalize).new(url, headers)

  request_obj.body = ::Castle::Utils::CleanInvalidChars.call(command.data || {}).to_json

  Castle::Logger.call("#{url}:", request_obj.body, config)

  request_obj.basic_auth('', config.api_secret)
  request_obj
end

.call(command, headers, http = nil, config = nil) ⇒ Object

Parameters:



17
18
19
20
21
# File 'lib/castle/core/send_request.rb', line 17

def call(command, headers, http = nil, config = nil)
  (http || Castle::Core::GetConnection.call).request(
    build(command, headers.merge(DEFAULT_HEADERS), config)
  )
end