Sha256: 7aac375135834aae74c45cc1b8f666ac6f1e1e67d836496830d59d1e65705379

Contents?: true

Size: 630 Bytes

Versions: 1

Compression:

Stored size: 630 Bytes

Contents

# frozen_string_literal: true
require 'net/http'
require 'uri'
require 'json'

module Trav3
  module POST
    def self.call(url, headers = {}, fields={})
      uri = URI( url.sub(/\?.*$/, '') )
      req = Net::HTTP::Post.new(uri.request_uri)
      headers.each_pair { |header, value|
        req[header] = value
      }
      req.set_form_data(**fields)
      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)
      else
        RequestError.new(response)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
trav3-0.1.1 lib/trav3/post.rb