Class: Served::Backends::Patron
- Inherits:
-
Base
- Object
- Base
- Served::Backends::Patron
show all
- Defined in:
- lib/served/backends/patron.rb
Overview
Patron Backend uses github.com/toland/patron for its client. This backend does not lock the GIL and is thread safe. Use Patron if you need high concurrency.
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#delete(endpoint, id, params = {}) ⇒ Object
34
35
36
37
38
39
40
41
42
|
# File 'lib/served/backends/patron.rb', line 34
def delete(endpoint, id, params = {})
serialize_response(::Patron::Session.new(headers: ,
timeout: timeout)
.delete(template.expand(id: id,
query: params,
resource: endpoint).to_s))
rescue ::Patron::ConnectionFailed
raise Served::HTTPClient::ConnectionFailed.new(resource)
end
|
#get(endpoint, id, params = {}) ⇒ Object
8
9
10
11
12
13
14
15
|
# File 'lib/served/backends/patron.rb', line 8
def get(endpoint, id, params = {})
serialize_response(::Patron::Session.new(headers: , timeout: timeout)
.get(template.expand(id: id,
query: params,
resource: endpoint).to_s))
rescue ::Patron::ConnectionFailed
raise Served::HTTPClient::ConnectionFailed.new(resource)
end
|
#post(endpoint, body, params = {}) ⇒ Object
26
27
28
29
30
31
32
|
# File 'lib/served/backends/patron.rb', line 26
def post(endpoint, body, params = {})
serialize_response(::Patron::Session.new(headers: , timeout: timeout)
.post(template.expand(query: params,
resource: endpoint).to_s, body))
rescue ::Patron::ConnectionFailed
raise Served::HTTPClient::ConnectionFailed.new(resource)
end
|
#put(endpoint, id, body, params = {}) ⇒ Object
17
18
19
20
21
22
23
24
|
# File 'lib/served/backends/patron.rb', line 17
def put(endpoint, id, body, params = {})
serialize_response(::Patron::Session.new(headers: , timeout: timeout)
.put(template.expand(id: id,
query: params,
resource: endpoint).to_s, body))
rescue ::Patron::ConnectionFailed
raise Served::HTTPClient::ConnectionFailed.new(resource)
end
|
#serialize_response(response) ⇒ Object
44
45
46
47
|
# File 'lib/served/backends/patron.rb', line 44
def serialize_response(response)
OpenStruct.new(body: response.body,
code: response.status)
end
|