Module: Pipe2me::HTTP
Overview
The HTTP module implements a simple wrapper around Net::HTTP, intended to ease the pain of dealing with HTTP requests.
Defined Under Namespace
Classes: Error, RedirectionLimit, ResourceNotFound, Response, ServerError
Constant Summary collapse
- @@config =
– configuration
OpenStruct.new
Class Method Summary collapse
Instance Method Summary collapse
-
#config ⇒ Object
The configuration object.
-
#get(url, headers = {}) ⇒ Object
runs a get request and return a HTTP::Response object.
-
#post(url, body, headers = {}) ⇒ Object
runs a post request and return a HTTP::Response object.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object (private)
153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/pipe2me/ext/http.rb', line 153 def method_missing(sym, *args, &block) case sym.to_s when /^(.*)\!$/ response = send $1, *args, &block response.validate! when /^(.*)\?$/ response = send $1, *args, &block response if response.valid? else super end end |
Class Method Details
.enable_insecure_mode ⇒ Object
11 12 13 14 |
# File 'lib/pipe2me/ext/http.rb', line 11 def self.enable_insecure_mode UI.error "Enabling insecure_mode" @insecure_mode = true end |
.insecure_mode? ⇒ Boolean
16 17 18 |
# File 'lib/pipe2me/ext/http.rb', line 16 def self.insecure_mode? !! @insecure_mode end |
Instance Method Details
#config ⇒ Object
The configuration object. It supports the following entries:
-
config.headers
: default headers to use when doing HTTP requests. Default: “Ruby HTTP client/1.0” -
config.max_redirections
: the number of maximum redirections to follow. Default: 10
To adjust the configuration change these objects, like so:
HTTP.config.headers = { "User-Agent" => "My awesome thingy/1.0" }
58 59 60 |
# File 'lib/pipe2me/ext/http.rb', line 58 def config @@config end |
#get(url, headers = {}) ⇒ Object
runs a get request and return a HTTP::Response object.
142 143 144 |
# File 'lib/pipe2me/ext/http.rb', line 142 def get(url, headers = {}) do_request Net::HTTP::Get, url, headers end |
#post(url, body, headers = {}) ⇒ Object
runs a post request and return a HTTP::Response object.
147 148 149 |
# File 'lib/pipe2me/ext/http.rb', line 147 def post(url, body, headers = {}) do_request Net::HTTP::Post, url, headers, body end |