Sha256: 989f3efeacbfba4fbc0776adcaf0bb5225bdf085f03f4bf86e6156c9997b9fed
Contents?: true
Size: 1.25 KB
Versions: 21
Compression:
Stored size: 1.25 KB
Contents
# frozen_string_literal: true module Multiwoven module Integrations::Core class HttpClient class << self def request(url, method, payload: nil, headers: {}) uri = URI(url) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == "https") request = build_request(method, uri, payload, headers) http.request(request) end private def build_request(method, uri, payload, headers) request_class = case method.upcase when Constants::HTTP_GET then Net::HTTP::Get when Constants::HTTP_POST then Net::HTTP::Post when Constants::HTTP_PUT then Net::HTTP::Put when Constants::HTTP_PATCH then Net::HTTP::Patch when Constants::HTTP_DELETE then Net::HTTP::Delete else raise ArgumentError, "Unsupported HTTP method: #{method}" end request = request_class.new(uri) headers.each { |key, value| request[key] = value } request.body = payload.to_json if payload && %w[POST PUT PATCH].include?(method.upcase) request end end end end end
Version data entries
21 entries across 21 versions & 1 rubygems