Class: RemoteImageFetch::CurlWrap

Inherits:
Curl::Easy
  • Object
show all
Defined in:
lib/remote_image_fetch/curl_wrap.rb

Overview

Wrap Curl::Easy with additional helper methods Can’t override initialize() as curb doesn’t call it properly.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argsObject

Returns the value of attribute args.



6
7
8
# File 'lib/remote_image_fetch/curl_wrap.rb', line 6

def args
  @args
end

#callbackObject

Returns the value of attribute callback.



6
7
8
# File 'lib/remote_image_fetch/curl_wrap.rb', line 6

def callback
  @callback
end

#fetcherObject

Returns the value of attribute fetcher.



6
7
8
# File 'lib/remote_image_fetch/curl_wrap.rb', line 6

def fetcher
  @fetcher
end

#redirectObject

Returns the value of attribute redirect.



6
7
8
# File 'lib/remote_image_fetch/curl_wrap.rb', line 6

def redirect
  @redirect
end

#redirectsObject (readonly)

Returns the value of attribute redirects.



5
6
7
# File 'lib/remote_image_fetch/curl_wrap.rb', line 5

def redirects
  @redirects
end

#resultObject (readonly)

Returns the value of attribute result.



5
6
7
# File 'lib/remote_image_fetch/curl_wrap.rb', line 5

def result
  @result
end

Instance Method Details

#body_ioObject



17
18
19
# File 'lib/remote_image_fetch/curl_wrap.rb', line 17

def body_io
  @body_io ||= StringIO.new(body_str)
end

#report(result) ⇒ Object



21
22
23
24
# File 'lib/remote_image_fetch/curl_wrap.rb', line 21

def report(result)
  @result = result
  callback.call(result, *args) if callback
end

#setup(fetcher) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/remote_image_fetch/curl_wrap.rb', line 8

def setup(fetcher)
  self.follow_location = false
  @fetcher = fetcher
  @redirects = 0

  on_complete(&method(:handle_complete))
  on_redirect(&method(:handle_redirect))
end