Module: IMW::Schemes::HTTP
- Defined in:
- lib/imw/schemes/http.rb
Overview
Defines methods for accessing a resource over HTTP. Uses RestClient to implement the basic HTTP verbs (GET, POST, PUT, DELETE, HEAD).
Class Method Summary collapse
-
.extended(obj) ⇒ Object
Many websites have HTML content without an
.html
extension so automatically extendobj
with IMW::Resources::Formats::HTML in this case.
Instance Method Summary collapse
-
#cp(new_uri) ⇒ IMW::Resource
Copy this resource to the
new_uri
. -
#delete(headers = {}) {|RestClient::Response| ... } ⇒ RestClient::Response
Send a DELETE request to this resource’s URI.
-
#effective_basename ⇒ String
Return the basename of the URI or
_index
if it’s blank, as in the case ofhttp://www.google.com
. -
#get(headers = {}) {|RestClient::Response| ... } ⇒ RestClient::Response
Send a GET request to this resource’s URI.
-
#head(headers = {}) {|RestClient::Response| ... } ⇒ RestClient::Response
Send a HEAD request to this resource’s URI.
-
#post(payload, headers = {}) {|RestClient::Response| ... } ⇒ RestClient::Response
Send a POST request to this resource’s URI with data
payload
. -
#put(payload, headers = {}) {|RestClient::Response| ... } ⇒ RestClient::Response
Send a PUT request to this resource’s URI with data
payload
. -
#via_http? ⇒ true, false
Is this resource being accessed via HTTP?.
Class Method Details
Instance Method Details
#cp(new_uri) ⇒ IMW::Resource
Copy this resource to the new_uri
.
27 28 29 |
# File 'lib/imw/schemes/http.rb', line 27 def cp new_uri IMW::Tools::Transferer.new(:cp, self, new_uri).transfer! end |
#delete(headers = {}) {|RestClient::Response| ... } ⇒ RestClient::Response
Send a DELETE request to this resource’s URI.
If the response doesn’t have HTTP code 2xx, a RestClient error will be raised.
If a block is given then the response will be passed to the block, even in case of a non-2xx code.
See the documentation for RestClient for more information.
125 126 127 128 129 |
# File 'lib/imw/schemes/http.rb', line 125 def delete headers={}, &block make_restclient_request do RestClient.delete(uri.to_s, headers, &block) end end |
#effective_basename ⇒ String
Return the basename of the URI or _index
if it’s blank, as in the case of http://www.google.com
.
35 36 37 |
# File 'lib/imw/schemes/http.rb', line 35 def effective_basename (basename.blank? || basename =~ %r{^/*$}) ? "_index" : basename end |
#get(headers = {}) {|RestClient::Response| ... } ⇒ RestClient::Response
Send a GET request to this resource’s URI.
If the response doesn’t have HTTP code 2xx, a RestClient error will be raised.
If a block is given then the response will be passed to the block, even in case of a non-2xx code.
See the documentation for RestClient for more information.
55 56 57 58 59 |
# File 'lib/imw/schemes/http.rb', line 55 def get headers={}, &block make_restclient_request do RestClient.get(uri.to_s, headers, &block) end end |
#head(headers = {}) {|RestClient::Response| ... } ⇒ RestClient::Response
Send a HEAD request to this resource’s URI.
If the response doesn’t have HTTP code 2xx, a RestClient error will be raised.
If a block is given then the response will be passed to the block, even in case of a non-2xx code.
See the documentation for RestClient for more information.
147 148 149 150 151 |
# File 'lib/imw/schemes/http.rb', line 147 def head headers={}, &block make_restclient_request do RestClient.head(uri.to_s, headers, &block) end end |
#post(payload, headers = {}) {|RestClient::Response| ... } ⇒ RestClient::Response
Send a POST request to this resource’s URI with data payload
.
If the response doesn’t have HTTP code 2xx, a RestClient error will be raised.
If a block is given then the response will be passed to the block, even in case of a non-2xx code.
See the documentation for RestClient for more information.
79 80 81 82 83 |
# File 'lib/imw/schemes/http.rb', line 79 def post payload, headers={}, &block make_restclient_request do RestClient.post(uri.to_s, payload, headers, &block) end end |
#put(payload, headers = {}) {|RestClient::Response| ... } ⇒ RestClient::Response
Send a PUT request to this resource’s URI with data payload
.
If the response doesn’t have HTTP code 2xx, a RestClient error will be raised.
If a block is given then the response will be passed to the block, even in case of a non-2xx code.
See the documentation for RestClient for more information.
103 104 105 106 107 |
# File 'lib/imw/schemes/http.rb', line 103 def put payload, headers={}, &block make_restclient_request do RestClient.put(uri.to_s, payload, headers, &block) end end |
#via_http? ⇒ true, false
Is this resource being accessed via HTTP?
19 20 21 |
# File 'lib/imw/schemes/http.rb', line 19 def via_http? true end |