Class: Curl::Req

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#bodyObject (readonly)

Returns the value of attribute body.



49
50
51
# File 'lib/curl-multi.rb', line 49

def body
  @body
end

#urlObject (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_failureObject



66
# File 'lib/curl-multi.rb', line 66

def do_failure() @failure.call(@error) end

#do_successObject



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

Returns:

  • (Boolean)


60
# File 'lib/curl-multi.rb', line 60

def done?() @done end

#failed?Boolean

Returns:

  • (Boolean)


62
# File 'lib/curl-multi.rb', line 62

def failed?() !!@error end

#inspectObject Also known as: to_s



68
# File 'lib/curl-multi.rb', line 68

def inspect() "{Curl::Req #{url}}" end