Sha256: 80ef950c031ebbefa1d6767061ddf192f27194577df04c9d60f0f6ea2473c5c5

Contents?: true

Size: 686 Bytes

Versions: 12

Compression:

Stored size: 686 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
          response.read_body
          response.error!
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
blitline-2.2.0 lib/blitline/http_poster.rb
blitline-2.1.0 lib/blitline/http_poster.rb
blitline-2.0.1 lib/blitline/http_poster.rb
blitline-1.4.0 lib/blitline/http_poster.rb
blitline-1.3.0 lib/blitline/http_poster.rb
blitline-1.2.3 lib/blitline/http_poster.rb
blitline-1.2.2 lib/blitline/http_poster.rb
blitline-1.2.0 lib/blitline/http_poster.rb
blitline-1.1.0 lib/blitline/http_poster.rb
blitline-1.0.3 lib/blitline/http_poster.rb
blitline-1.0.2 lib/blitline/http_poster.rb
blitline-1.0.1 lib/blitline/http_poster.rb