Module: Http::Chainable
- Included in:
- Http, Parameters
- Defined in:
- lib/http/chainable.rb
Instance Method Summary collapse
-
#accept(type) ⇒ Object
Accept the given MIME type(s).
-
#connect(uri, options = {}) ⇒ Object
Convert to a transparent TCP/IP tunnel.
- #default_headers ⇒ Object
- #default_headers=(headers) ⇒ Object
-
#delete(uri, options = {}) ⇒ Object
Delete a resource.
-
#get(uri, options = {}) ⇒ Object
Get a resource.
-
#head(uri, options = {}) ⇒ Object
Request a get sans response body.
-
#options(uri, options = {}) ⇒ Object
Return the methods supported on the given URI.
-
#patch(uri, options = {}) ⇒ Object
Apply partial modifications to a resource.
-
#post(uri, options = {}) ⇒ Object
Post to a resource.
-
#put(uri, options = {}) ⇒ Object
Put to a resource.
-
#request(verb, uri, options = {}) ⇒ Object
Make an HTTP request with the given verb.
-
#trace(uri, options = {}) ⇒ Object
Echo the request back to the client.
-
#with_headers(headers) ⇒ Object
(also: #with)
Make a request with the given headers.
Instance Method Details
#accept(type) ⇒ Object
Accept the given MIME type(s)
68 69 70 71 72 73 74 75 76 |
# File 'lib/http/chainable.rb', line 68 def accept(type) if type.is_a? String with :accept => type else mime_type = Http::MimeType[type] raise ArgumentError, "unknown MIME type: #{type}" unless mime_type with :accept => mime_type.type end end |
#connect(uri, options = {}) ⇒ Object
Convert to a transparent TCP/IP tunnel
39 40 41 |
# File 'lib/http/chainable.rb', line 39 def connect(uri, = {}) request :connect, uri, end |
#default_headers ⇒ Object
78 79 80 |
# File 'lib/http/chainable.rb', line 78 def default_headers @default_headers ||= {} end |
#default_headers=(headers) ⇒ Object
82 83 84 |
# File 'lib/http/chainable.rb', line 82 def default_headers=(headers) @default_headers = headers end |
#delete(uri, options = {}) ⇒ Object
Delete a resource
24 25 26 |
# File 'lib/http/chainable.rb', line 24 def delete(uri, = {}) request :delete, uri, end |
#get(uri, options = {}) ⇒ Object
Get a resource
9 10 11 |
# File 'lib/http/chainable.rb', line 9 def get(uri, = {}) request :get, uri, end |
#head(uri, options = {}) ⇒ Object
Request a get sans response body
4 5 6 |
# File 'lib/http/chainable.rb', line 4 def head(uri, = {}) request :head, uri, {:response => :object}.merge() end |
#options(uri, options = {}) ⇒ Object
Return the methods supported on the given URI
34 35 36 |
# File 'lib/http/chainable.rb', line 34 def (uri, = {}) request :options, uri, end |
#patch(uri, options = {}) ⇒ Object
Apply partial modifications to a resource
44 45 46 |
# File 'lib/http/chainable.rb', line 44 def patch(uri, = {}) request :patch, uri, end |
#post(uri, options = {}) ⇒ Object
Post to a resource
14 15 16 |
# File 'lib/http/chainable.rb', line 14 def post(uri, = {}) request :post, uri, end |
#put(uri, options = {}) ⇒ Object
Put to a resource
19 20 21 |
# File 'lib/http/chainable.rb', line 19 def put(uri, = {}) request :put, uri, end |
#request(verb, uri, options = {}) ⇒ Object
Make an HTTP request with the given verb
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/http/chainable.rb', line 49 def request(verb, uri, = {}) [:response] ||= :parsed_body if [:headers] headers = default_headers.merge [:headers] else headers = default_headers end Client.new(uri).request verb, .merge(:headers => headers) end |
#trace(uri, options = {}) ⇒ Object
Echo the request back to the client
29 30 31 |
# File 'lib/http/chainable.rb', line 29 def trace(uri, = {}) request :trace, uri, end |
#with_headers(headers) ⇒ Object Also known as: with
Make a request with the given headers
62 63 64 |
# File 'lib/http/chainable.rb', line 62 def with_headers(headers) Parameters.new default_headers.merge(headers) end |