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 = Castle.config) ⇒ Object

Parameters:



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/castle/core/send_request.rb', line 32

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

  unless command.method == :get
    request_obj.body = ::Castle::Utils::CleanInvalidChars.call(
      command.data
    ).to_json
  end

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

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

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

Parameters:



19
20
21
22
23
24
25
26
27
# File 'lib/castle/core/send_request.rb', line 19

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