Sha256: 8e4429d29b4d0d7d634183a860fee6608febd035a6ccfaf38fb5c8ca247699c6
Contents?: true
Size: 824 Bytes
Versions: 2
Compression:
Stored size: 824 Bytes
Contents
# frozen_string_literal: true # rubocop:disable Metrics/MethodLength require 'net/http' require 'uri' module Trav3 module REST def self.post(travis, url, **fields) uri = URI( url.sub(/\?.*$/, '') ) req = Net::HTTP::Post.new(uri.request_uri) travis.headers.each_pair do |header, value| req[header] = value end body = fields.delete(:body) req.body = body if body 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::HTTPAccepted, Net::HTTPOK].include? response.code_type Success.new(travis, response) else RequestError.new(travis, response) end end end end # rubocop:enable Metrics/MethodLength
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
trav3-0.2.5 | lib/trav3/rest/post.rb |
trav3-0.2.4 | lib/trav3/rest/post.rb |