Sha256: 33c9ec078bc530d7b00bf1b10bcbd79dae70d7b66ba3a93af20d7c11adea4867

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module BubbleWrap

  # The HTTP module provides a simple interface to make HTTP requests.
  #
  # TODO: preflight support, easier/better cookie support, better error handling
  module HTTP

    # Make a GET request and process the response asynchronously via a block.
    #
    # @examples
    #  # Simple GET request printing the body
    #   BubbleWrap::HTTP.get("https://api.github.com/users/mattetti") do |response|
    #     p response.body.to_str
    #   end
    #
    #  # GET request with basic auth credentials
    #   BubbleWrap::HTTP.get("https://api.github.com/users/mattetti", {credentials: {username: 'matt', password: 'aimonetti'}}) do |response|
    #     p response.body.to_str # prints the response's body
    #   end
    #

    [:get, :post, :put, :delete, :head, :patch].each do |http_verb|

      define_singleton_method(http_verb) do |url, options = {}, &block|
        options[:action] = block if block
        HTTP::Query.new(url, http_verb, options)
      end

    end
  end
end

class InvalidURLError < StandardError; end
class InvalidFileError < StandardError; end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bubble-wrap-1.3.0 motion/http.rb
bubble-wrap-1.3.0.osx motion/http.rb