19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/tootsie/input.rb', line 19
def get!
@logger.info("Fetching #{@url} as #{@temp_file.path}")
case @url
when /^file:(.*)/
@file_name = $1
raise InputNotFound, @url unless File.exist?(@file_name)
when /^s3:.*$/
s3_options = S3Utilities.parse_uri(@url)
bucket_name, path = s3_options[:bucket], s3_options[:key]
s3_service = Tootsie::Application.get.s3_service
begin
File.open(@temp_file.path, 'wb') do |f|
object = s3_service.buckets.find(bucket_name).objects.find(path)
object.send(:get_object) unless object.content f << object.content
end
rescue ::S3::Error::NoSuchBucket, ::S3::Error::NoSuchKey
raise InputNotFound, @url
end
when /http(s?):\/\//
response = HTTPClient.new.get(@url)
File.open(@temp_file.path, 'wb') do |f|
f << response.body
end
else
raise ArgumentError, "Don't know to handle URL: #{@url}"
end
end
|