Sha256: b1e97abfd3e0f4fa821cf38edfc47c8f90b2f69af98647b6b0ecb528fd888a4a

Contents?: true

Size: 623 Bytes

Versions: 1

Compression:

Stored size: 623 Bytes

Contents

require 'net/http'
require 'uri'
require 'json'
require 'trav3/result'

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.0 lib/trav3/post.rb