lib/trav3/post.rb in trav3-0.1.1 vs lib/trav3/post.rb in trav3-0.2.0

- old
+ new

@@ -3,24 +3,24 @@ require 'uri' require 'json' module Trav3 module POST - def self.call(url, headers = {}, fields={}) + def self.call(travis, url, fields={}) uri = URI( url.sub(/\?.*$/, '') ) req = Net::HTTP::Post.new(uri.request_uri) - headers.each_pair { |header, value| + travis.headers.each_pair { |header, value| req[header] = value } - req.set_form_data(**fields) + req.set_form_data(**fields) unless fields.empty? http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == "https") response = http.request(req) - - if Net::HTTPOK == response.code_type - Success.new(response) + + if [Net::HTTPAccepted, Net::HTTPOK].include? response.code_type + Success.new(travis, response) else - RequestError.new(response) + RequestError.new(travis, response) end end end end