Module: Whoosh::HTTP
- Defined in:
- lib/whoosh/http.rb,
lib/whoosh/http/response.rb
Defined Under Namespace
Classes: AsyncClient, ConnectionError, Response, TimeoutError
Class Method Summary
collapse
-
.async ⇒ Object
Returns an async client for non-blocking requests.
-
.concurrent(*requests) ⇒ Object
Run multiple HTTP requests concurrently.
-
.delete(url, headers: {}, timeout: 30) ⇒ Object
-
.get(url, headers: {}, timeout: 30) ⇒ Object
-
.patch(url, json: nil, body: nil, headers: {}, timeout: 30) ⇒ Object
-
.post(url, json: nil, body: nil, headers: {}, timeout: 30) ⇒ Object
-
.put(url, json: nil, body: nil, headers: {}, timeout: 30) ⇒ Object
Class Method Details
.async ⇒ Object
Returns an async client for non-blocking requests
48
49
50
|
# File 'lib/whoosh/http.rb', line 48
def async
AsyncClient.new
end
|
.concurrent(*requests) ⇒ Object
Run multiple HTTP requests concurrently
37
38
39
40
41
42
43
44
45
|
# File 'lib/whoosh/http.rb', line 37
def concurrent(*requests)
threads = requests.map do |req|
method = req[:method] || :get
url = req[:url]
opts = req.except(:method, :url)
Thread.new { send(method, url, **opts) }
end
threads.map(&:value)
end
|
.delete(url, headers: {}, timeout: 30) ⇒ Object
32
33
34
|
# File 'lib/whoosh/http.rb', line 32
def delete(url, headers: {}, timeout: 30)
request(:delete, url, headers: , timeout: timeout)
end
|
.get(url, headers: {}, timeout: 30) ⇒ Object
16
17
18
|
# File 'lib/whoosh/http.rb', line 16
def get(url, headers: {}, timeout: 30)
request(:get, url, headers: , timeout: timeout)
end
|
.patch(url, json: nil, body: nil, headers: {}, timeout: 30) ⇒ Object
28
29
30
|
# File 'lib/whoosh/http.rb', line 28
def patch(url, json: nil, body: nil, headers: {}, timeout: 30)
request(:patch, url, json: json, body: body, headers: , timeout: timeout)
end
|
.post(url, json: nil, body: nil, headers: {}, timeout: 30) ⇒ Object
20
21
22
|
# File 'lib/whoosh/http.rb', line 20
def post(url, json: nil, body: nil, headers: {}, timeout: 30)
request(:post, url, json: json, body: body, headers: , timeout: timeout)
end
|
.put(url, json: nil, body: nil, headers: {}, timeout: 30) ⇒ Object
24
25
26
|
# File 'lib/whoosh/http.rb', line 24
def put(url, json: nil, body: nil, headers: {}, timeout: 30)
request(:put, url, json: json, body: body, headers: , timeout: timeout)
end
|