Class: Songkick::Transport::Curb
- Inherits:
-
Base
- Object
- Base
- Songkick::Transport::Curb
show all
- Defined in:
- lib/songkick/transport/curb.rb
Constant Summary
collapse
{"Expect" => ""}
Instance Attribute Summary
Attributes inherited from Base
#user_agent
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#with_headers, #with_timeout
Constructor Details
#initialize(host, options = {}) ⇒ Curb
Returns a new instance of Curb.
18
19
20
21
22
23
24
25
|
# File 'lib/songkick/transport/curb.rb', line 18
def initialize(host, options = {})
@host = host
@timeout = options[:timeout] || DEFAULT_TIMEOUT
@user_agent = options[:user_agent]
if c = options[:connection]
Thread.current[:transport_curb_easy] = c
end
end
|
Class Method Details
.clear_thread_connection ⇒ Object
14
15
16
|
# File 'lib/songkick/transport/curb.rb', line 14
def self.clear_thread_connection
Thread.current[:transport_curb_easy] = nil
end
|
Instance Method Details
#connection ⇒ Object
27
28
29
|
# File 'lib/songkick/transport/curb.rb', line 27
def connection
Thread.current[:transport_curb_easy] ||= Curl::Easy.new
end
|
#endpoint ⇒ Object
31
32
33
|
# File 'lib/songkick/transport/curb.rb', line 31
def endpoint
@host
end
|
#execute_request(req) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/songkick/transport/curb.rb', line 35
def execute_request(req)
connection.reset
connection.url = req.url
connection.timeout = req.timeout || @timeout
connection..update(DEFAULT_HEADERS.merge(req.))
= {}
connection. do ||
line = .sub(/\r\n$/, '')
parts = line.split(/:\s*/)
if parts.size >= 2
[parts.shift] = parts * ':'
end
.bytesize
end
if req.use_body?
connection.__send__("http_#{req.verb}", req.body)
else
connection.http(req.verb.upcase)
end
process(req, connection.response_code, , connection.body_str)
rescue Curl::Err::HostResolutionError => error
logger.warn "Could not resolve host: #{@host}"
raise Transport::HostResolutionError, req
rescue Curl::Err::ConnectionFailedError => error
logger.warn "Could not connect to host: #{@host}"
raise Transport::ConnectionFailedError, req
rescue Curl::Err::TimeoutError => error
logger.warn "Request timed out after #{@timeout}s : #{req}"
raise Transport::TimeoutError, req
rescue Curl::Err::GotNothingError => error
logger.warn "Got nothing: #{req}"
raise Transport::UpstreamError, req
end
|