lib/yoti/http/request.rb in yoti-1.5.0 vs lib/yoti/http/request.rb in yoti-1.6.0

- old
+ new

@@ -12,10 +12,19 @@ attr_accessor :endpoint # @return [Hash] the body sent with the request attr_accessor :payload + def initialize + @headers = {} + end + + # Adds a HTTP header to the request + def add_header(header, value) + @headers[header] = value + end + # Makes a HTTP request after signing the headers # @return [Hash] the body from the HTTP request def body raise RequestError, 'The request requires a HTTP method.' unless @http_method raise RequestError, 'The payload needs to be a hash.' unless @payload.to_s.empty? || @payload.is_a?(Hash) @@ -47,9 +56,13 @@ when 'PATCH' http_req = Net::HTTP::Patch.new(uri) http_req.body = @payload.to_json unless @payload.to_s.empty? else raise RequestError, "Request method not allowed: #{@http_method}" + end + + @headers.each do |header, value| + http_req[header] = value end http_req end