Sha256: 4345b6a0e0581eb6a0240f13f24450c6274f9d2be920d16febb7bc496ead5885
Contents?: true
Size: 707 Bytes
Versions: 23
Compression:
Stored size: 707 Bytes
Contents
# frozen_string_literal: true module Motor module ApiConfigs METHODS = %w[get post put delete].freeze DEFAULT_HEADERS = { 'Content-Type' => 'application/json' }.freeze InvalidHttpMethod = Class.new(StandardError) module_function 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 end end
Version data entries
23 entries across 23 versions & 1 rubygems