Sha256: 1a6bfef69c381241b90a08b0f1a514374ed5e3f9138bdeeea58388ec4c392660
Contents?: true
Size: 763 Bytes
Versions: 2
Compression:
Stored size: 763 Bytes
Contents
class Blitline require 'net/http' require 'uri' class HttpPoster # Perform a POST request. # Optionally takes a form_data hash. # Optionally takes a block to receive chunks of the response. def self.post(path, form_data=nil, &block) uri = URI.parse(path) unless path.is_a?(URI) @http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(path) request.set_form_data(form_data) if form_data @http.request(request) do |response| if response.is_a? Net::HTTPSuccess return response.read_body(&block) else result_data = response.read_body(&block) raise "Post to Blitline.com failed. #{response.code}: #{result_data}" end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
blitline-2.6.0 | lib/blitline/http_poster.rb |
blitline-2.5.1 | lib/blitline/http_poster.rb |