Class: GiantClient::CurbAdapter
Constant Summary
collapse
- CRLF =
/\r\n/
/:\s*/
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
36
37
38
39
40
41
|
# File 'lib/giant_client/curb_adapter.rb', line 36
def normalize_response(response)
status_code = response.response_code
= (response.)
body = response.body_str
Response.new(status_code, , body)
end
|
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/giant_client/curb_adapter.rb', line 43
def ()
= {}
pairs = .split(CRLF)
pairs.shift
pairs.each do |pair|
, value = *pair.split(HEADER_SPLIT, 2)
= ()
[] = value
end
end
|
#request(method, opts) ⇒ Object
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/giant_client/curb_adapter.rb', line 9
def request(method, opts)
if BODYLESS_METHODS.include?(method)
raise GiantClient::Error::NotImplemented unless opts[:body] == ''
end
url = url_from_opts(opts)
if method == :post
post_body = opts[:body]
elsif method == :put
put_data = opts[:body]
end
begin
response = Curl.http( method.upcase, url, post_body, put_data ) do |curl|
curl. = opts[:headers]
curl.timeout = opts[:timeout]
curl.connect_timeout = opts[:timeout]
end
rescue Curl::Err::TimeoutError
raise GiantClient::Error::Timeout, "the request timed out (timeout: #{opts[:timeout]}"
end
normalize_response(response)
end
|