Module: HTTP::Chainable
Instance Method Summary collapse
-
#accept(type) ⇒ Object
Accept the given MIME type(s).
-
#auth(value, opts = nil) ⇒ Object
Make a request with the given Authorization header.
-
#basic_auth(opts) ⇒ Object
Make a request with the given Basic authorization header.
-
#connect(uri, options = {}) ⇒ Object
Convert to a transparent TCP/IP tunnel.
-
#default_headers ⇒ Object
Get headers of HTTP options.
-
#default_headers=(headers) ⇒ Object
Set headers of HTTP options.
-
#default_options ⇒ HTTP::Options
Get options for HTTP.
-
#default_options=(opts) ⇒ HTTP::Options
Set options for HTTP.
-
#delete(uri, options = {}) ⇒ Object
Delete a resource.
-
#follow(opts = true) ⇒ HTTP::Client
(also: #with_follow)
Make client follow redirects.
-
#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.
-
#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_headers(headers) ⇒ Object
(also: #with)
Make a request with the given headers.
Instance Method Details
#accept(type) ⇒ Object
Accept the given MIME type(s)
119 120 121 |
# File 'lib/http/chainable.rb', line 119 def accept(type) with :accept => MimeType.normalize(type) end |
#auth(value, opts = nil) ⇒ Object
Make a request with the given Authorization header
125 126 127 128 129 130 |
# File 'lib/http/chainable.rb', line 125 def auth(value, opts = nil) # shim for deprecated auth(:basic, opts). # will be removed in 0.8.0 return basic_auth(opts) if :basic == value with :authorization => value.to_s end |
#basic_auth(opts) ⇒ Object
Make a request with the given Basic authorization header
137 138 139 140 141 142 |
# File 'lib/http/chainable.rb', line 137 def basic_auth(opts) user = opts.fetch :user pass = opts.fetch :pass auth('Basic ' << Base64.strict_encode64("#{user}:#{pass}")) end |
#connect(uri, options = {}) ⇒ Object
Convert to a transparent TCP/IP tunnel
57 58 59 |
# File 'lib/http/chainable.rb', line 57 def connect(uri, = {}) request :connect, uri, end |
#default_headers ⇒ Object
Get headers of HTTP options
158 159 160 |
# File 'lib/http/chainable.rb', line 158 def default_headers .headers end |
#default_headers=(headers) ⇒ Object
Set headers of HTTP options
164 165 166 167 168 |
# File 'lib/http/chainable.rb', line 164 def default_headers=(headers) @default_options = .dup do |opts| opts.headers = headers end end |
#default_options ⇒ HTTP::Options
Get options for HTTP
146 147 148 |
# File 'lib/http/chainable.rb', line 146 def @default_options ||= HTTP::Options.new end |
#default_options=(opts) ⇒ HTTP::Options
Set options for HTTP
153 154 155 |
# File 'lib/http/chainable.rb', line 153 def (opts) @default_options = HTTP::Options.new(opts) end |
#delete(uri, options = {}) ⇒ Object
Delete a resource
36 37 38 |
# File 'lib/http/chainable.rb', line 36 def delete(uri, = {}) request :delete, uri, end |
#follow(opts = true) ⇒ HTTP::Client Also known as: with_follow
Make client follow redirects.
102 103 104 |
# File 'lib/http/chainable.rb', line 102 def follow(opts = true) branch .with_follow opts end |
#get(uri, options = {}) ⇒ Object
Get a resource
15 16 17 |
# File 'lib/http/chainable.rb', line 15 def get(uri, = {}) request :get, uri, end |
#head(uri, options = {}) ⇒ Object
Request a get sans response body
8 9 10 |
# File 'lib/http/chainable.rb', line 8 def head(uri, = {}) request :head, uri, end |
#options(uri, options = {}) ⇒ Object
Return the methods supported on the given URI
50 51 52 |
# File 'lib/http/chainable.rb', line 50 def (uri, = {}) request :options, uri, end |
#patch(uri, options = {}) ⇒ Object
Apply partial modifications to a resource
64 65 66 |
# File 'lib/http/chainable.rb', line 64 def patch(uri, = {}) request :patch, uri, end |
#post(uri, options = {}) ⇒ Object
Post to a resource
22 23 24 |
# File 'lib/http/chainable.rb', line 22 def post(uri, = {}) request :post, uri, end |
#put(uri, options = {}) ⇒ Object
Put to a resource
29 30 31 |
# File 'lib/http/chainable.rb', line 29 def put(uri, = {}) request :put, uri, end |
#request(verb, uri, options = {}) ⇒ Object
Make an HTTP request with the given verb
71 72 73 |
# File 'lib/http/chainable.rb', line 71 def request(verb, uri, = {}) branch().request verb, uri end |
#stream ⇒ Object
Alias for with_response(:object)
94 95 96 |
# File 'lib/http/chainable.rb', line 94 def stream with_response(:object) end |
#trace(uri, options = {}) ⇒ Object
Echo the request back to the client
43 44 45 |
# File 'lib/http/chainable.rb', line 43 def trace(uri, = {}) request :trace, uri, end |
#via(*proxy) ⇒ Object Also known as: through
Make a request through an HTTP proxy
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/http/chainable.rb', line 78 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 [2, 4].include?(proxy_hash.keys.size) branch .with_proxy(proxy_hash) else fail(RequestError, "invalid HTTP proxy: #{proxy_hash}") end end |
#with_headers(headers) ⇒ Object Also known as: with
Make a request with the given headers
112 113 114 |
# File 'lib/http/chainable.rb', line 112 def with_headers(headers) branch .with_headers(headers) end |