Module: Motor::ApiConfigs
- Defined in:
- lib/motor/api_configs.rb
Constant Summary collapse
- METHODS =
%w[get post put delete].freeze
- DEFAULT_HEADERS =
{ 'Content-Type' => 'application/json' }.freeze
- InvalidHttpMethod =
Class.new(StandardError)
Class Method Summary collapse
Class Method Details
.run(api_config, method: nil, path: nil, body: nil, params: {}, headers: {}) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/motor/api_configs.rb', line 13 def run(api_config, method: nil, path: nil, body: nil, params: {}, headers: {}) method ||= 'get' raise InvalidHttpMethod unless METHODS.include?(method.downcase) Motor::NetHttpUtils.public_send( method.downcase.to_sym, api_config.url.to_s.sub(%r{/?\z}, '/') + path.delete_prefix('/'), params, DEFAULT_HEADERS.merge(headers).merge(api_config.headers), body&.to_json ) end |