Module: Net::HTTPExt
- Defined in:
- lib/vex/base/net/http_ext.rb,
lib/vex/base/net/http_ext.rb
Overview
This adds Net.get, Net.head, Net.post
Defined Under Namespace
Classes: Response
Constant Summary collapse
- REDIRECTION_LIMIT =
10
- DEFAULT_OPTIONS =
{ :redirect => 10 # MAX # of redirection }
- HEADERS_KEY =
:"net:http_ext:preprocessors:headers"
Instance Method Summary collapse
- #exists?(url, opts = {}) ⇒ Boolean (also: #exist?)
-
#get(url, opts = {}) ⇒ Object
GET request.
-
#head(url, opts = {}) ⇒ Object
HEAD request.
- #headers ⇒ Object
- #headers=(h) ⇒ Object
-
#post(url, body, opts = {}) ⇒ Object
POST request.
- #with_headers(scope, &block) ⇒ Object
Instance Method Details
#exists?(url, opts = {}) ⇒ Boolean Also known as: exist?
67 68 69 70 |
# File 'lib/vex/base/net/http_ext.rb', line 67 def exists?(url, opts = {}) r = Net.head(url, opts) r.code >= 200 && r.code < 300 end |
#get(url, opts = {}) ⇒ Object
GET request
63 64 65 |
# File 'lib/vex/base/net/http_ext.rb', line 63 def get(url, opts = {}) http :get, url, nil, opts end |
#head(url, opts = {}) ⇒ Object
HEAD request
58 59 60 |
# File 'lib/vex/base/net/http_ext.rb', line 58 def head(url, opts = {}) http :head, url, nil, opts end |
#headers ⇒ Object
76 77 78 |
# File 'lib/vex/base/net/http_ext.rb', line 76 def headers Thread.current[HEADERS_KEY] ||= {} end |
#headers=(h) ⇒ Object
80 81 82 |
# File 'lib/vex/base/net/http_ext.rb', line 80 def headers=(h) Thread.current[HEADERS_KEY] = h end |
#post(url, body, opts = {}) ⇒ Object
POST request
53 54 55 |
# File 'lib/vex/base/net/http_ext.rb', line 53 def post(url, body, opts = {}) http :post, url, body, opts end |
#with_headers(scope, &block) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/vex/base/net/http_ext.rb', line 84 def with_headers(scope, &block) old = headers self.headers = headers.dup.update scope yield ensure self.headers = old end |