Class: GiantClient::PatronAdapter
Instance Method Summary
collapse
#delete, #encode_query, #get, #head, #normalize_header, #normalize_header_hash, #post, #prepend_question_mark, #put, #stringify_query, #url_from_opts
Instance Method Details
#normalize_response(response) ⇒ Object
30
31
32
33
34
35
|
# File 'lib/giant_client/patron_adapter.rb', line 30
def normalize_response(response)
status_code = response.status
= (response.)
body = response.body
Response.new(status_code, , body)
end
|
#request(method, opts) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/giant_client/patron_adapter.rb', line 7
def request(method, opts)
if BODYLESS_METHODS.include?(method)
raise GiantClient::Error::NotImplemented unless opts[:body] == ''
end
url = url_from_opts(opts)
http = Patron::Session.new
http.timeout = opts[:timeout]
http.connect_timeout = opts[:timeout]
= {}
[:data] = opts[:body]
begin
response = http.request(method, url, opts[:headers], )
rescue Patron::TimeoutError
raise GiantClient::Error::Timeout, "the request timed out (timeout: #{opts[:timeout]}"
end
normalize_response(response)
end
|