Class: Dragonfly::Job::FetchUrl
- Inherits:
-
Step
show all
- Defined in:
- lib/dragonfly/job/fetch_url.rb
Defined Under Namespace
Classes: BadURI, CannotHandle, ErrorResponse, TooManyRedirects
Instance Attribute Summary
Attributes inherited from Step
#args, #job
Instance Method Summary
collapse
Methods inherited from Step
abbreviation, #app, basename, #initialize, #inspect, step_name, #to_a
Instance Method Details
42
43
44
45
46
47
48
49
|
# File 'lib/dragonfly/job/fetch_url.rb', line 42
def apply
if data_uri?
update_from_data_uri
else
response = get_following_redirects(url)
job.content.update(response.body || "", 'name' => filename, 'mime_type' => response.content_type)
end
end
|
#data_uri? ⇒ Boolean
38
39
40
|
# File 'lib/dragonfly/job/fetch_url.rb', line 38
def data_uri?
uri =~ /\Adata:/
end
|
33
34
35
36
|
# File 'lib/dragonfly/job/fetch_url.rb', line 33
def filename
return if data_uri?
@filename ||= parse_url(url).path[/[^\/]+\z/]
end
|
21
22
23
|
# File 'lib/dragonfly/job/fetch_url.rb', line 21
def init
job.url_attributes.name = filename
end
|
25
26
27
|
# File 'lib/dragonfly/job/fetch_url.rb', line 25
def uri
args.first
end
|
29
30
31
|
# File 'lib/dragonfly/job/fetch_url.rb', line 29
def url
@url ||= uri =~ /\A\w+:[^\d]/ ? uri : "http://#{uri}"
end
|