Module: HTTP::Chainable
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_callbacks ⇒ Object
- #default_callbacks=(callbacks) ⇒ Object
- #default_headers ⇒ Object
- #default_headers=(headers) ⇒ Object
- #default_options ⇒ Object
- #default_options=(opts) ⇒ 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.
-
#on(event, &block) ⇒ Object
Make a request invoking the given event callbacks.
-
#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.
-
#stream ⇒ Object
Alias for with_response(:object).
-
#trace(uri, options = {}) ⇒ Object
Echo the request back to the client.
-
#via(*proxy) ⇒ Object
(also: #through)
Make a request through an HTTP proxy.
- #with_follow(follow) ⇒ Object
-
#with_headers(headers) ⇒ Object
(also: #with)
Make a request with the given headers.
-
#with_response(response_type) ⇒ Object
Specify the kind of response to return (:auto, :object, :body, :parsed_body).
Instance Method Details
#accept(type) ⇒ Object
Accept the given MIME type(s)
93 94 95 96 97 98 99 100 101 |
# File 'lib/http/chainable.rb', line 93 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_callbacks ⇒ Object
121 122 123 |
# File 'lib/http/chainable.rb', line 121 def default_callbacks .callbacks end |
#default_callbacks=(callbacks) ⇒ Object
125 126 127 128 129 |
# File 'lib/http/chainable.rb', line 125 def default_callbacks=(callbacks) @default_options = .dup do |opts| opts.callbacks = callbacks end end |
#default_headers ⇒ Object
111 112 113 |
# File 'lib/http/chainable.rb', line 111 def default_headers .headers end |
#default_headers=(headers) ⇒ Object
115 116 117 118 119 |
# File 'lib/http/chainable.rb', line 115 def default_headers=(headers) @default_options = .dup do |opts| opts.headers = headers end end |
#default_options ⇒ Object
103 104 105 |
# File 'lib/http/chainable.rb', line 103 def @default_options ||= HTTP::Options.new end |
#default_options=(opts) ⇒ Object
107 108 109 |
# File 'lib/http/chainable.rb', line 107 def (opts) @default_options = HTTP::Options.new(opts) 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, end |
#on(event, &block) ⇒ Object
Make a request invoking the given event callbacks
54 55 56 |
# File 'lib/http/chainable.rb', line 54 def on(event, &block) branch .with_callback(event, block) 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 |
# File 'lib/http/chainable.rb', line 49 def request(verb, uri, = {}) branch().request verb, uri end |
#stream ⇒ Object
Alias for with_response(:object)
80 |
# File 'lib/http/chainable.rb', line 80 def stream; with_response(:object); 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 |
#via(*proxy) ⇒ Object Also known as: through
Make a request through an HTTP proxy
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/http/chainable.rb', line 59 def via(*proxy) proxy_hash = {} proxy_hash[:proxy_address] = proxy[0] if proxy[0].is_a? String proxy_hash[:proxy_port] = proxy[1] if proxy[1].is_a? Integer proxy_hash[:proxy_username]= proxy[2] if proxy[2].is_a? String proxy_hash[:proxy_password]= proxy[3] if proxy[3].is_a? String if proxy_hash.keys.size >=2 branch .with_proxy(proxy_hash) else raise ArgumentError, "invalid HTTP proxy: #{proxy_hash}" end end |
#with_follow(follow) ⇒ Object
82 83 84 |
# File 'lib/http/chainable.rb', line 82 def with_follow(follow) branch .with_follow(follow) end |
#with_headers(headers) ⇒ Object Also known as: with
Make a request with the given headers
87 88 89 |
# File 'lib/http/chainable.rb', line 87 def with_headers(headers) branch .with_headers(headers) end |
#with_response(response_type) ⇒ Object
Specify the kind of response to return (:auto, :object, :body, :parsed_body)
75 76 77 |
# File 'lib/http/chainable.rb', line 75 def with_response(response_type) branch .with_response(response_type) end |