Class: Curl::Req
- Inherits:
-
Object
- Object
- Curl::Req
- Defined in:
- lib/curl-multi.rb
Overview
An instance of this class collects the response for each curl easy handle.
Constant Summary collapse
- CURLE_OK =
0
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #add_chunk(chunk) ⇒ Object
- #do_failure ⇒ Object
- #do_success ⇒ Object
- #done(code, status) ⇒ Object
- #done? ⇒ Boolean
- #failed? ⇒ Boolean
-
#initialize(url, success, failure) ⇒ Req
constructor
A new instance of Req.
- #inspect ⇒ Object (also: #to_s)
Constructor Details
#initialize(url, success, failure) ⇒ Req
Returns a new instance of Req.
71 72 73 74 75 76 77 78 |
# File 'lib/curl-multi.rb', line 71 def initialize(url, success, failure) @url = url @success = success @failure = failure @body = '' @done = false @error = nil end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
49 50 51 |
# File 'lib/curl-multi.rb', line 49 def body @body end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
49 50 51 |
# File 'lib/curl-multi.rb', line 49 def url @url end |
Instance Method Details
#add_chunk(chunk) ⇒ Object
80 81 82 |
# File 'lib/curl-multi.rb', line 80 def add_chunk(chunk) @body = body + chunk end |
#do_failure ⇒ Object
66 |
# File 'lib/curl-multi.rb', line 66 def do_failure() @failure.call(@error) end |
#do_success ⇒ Object
64 |
# File 'lib/curl-multi.rb', line 64 def do_success() @success.call(body) end |
#done(code, status) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/curl-multi.rb', line 51 def done(code, status) @done = true if code != CURLE_OK @error = Error.new(code) elsif status != 200 @error = HTTPError.new(status) end end |
#done? ⇒ Boolean
60 |
# File 'lib/curl-multi.rb', line 60 def done?() @done end |
#failed? ⇒ Boolean
62 |
# File 'lib/curl-multi.rb', line 62 def failed?() !!@error end |
#inspect ⇒ Object Also known as: to_s
68 |
# File 'lib/curl-multi.rb', line 68 def inspect() "{Curl::Req #{url}}" end |