11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/fetch_and_process/s3.rb', line 11
def s3_handler
options = {
bucket: uri.host,
key: uri.path[1..],
}
options[:if_modified_since] = File.mtime(cache_location) if File.exist?(cache_location)
s3.get_object(options, target: cache_location)
rescue Aws::S3::Errors::NotModified
options.delete(:if_modified_since)
s3.head_object(options)
rescue Aws::S3::Errors::AccessDenied => e
raise FetchAndProcess::AccessControlError, "Could not fetch file from S3: #{e.message}"
rescue Aws::S3::Errors::NoSuchKey => e
raise FetchAndProcess::FileNotFoundError, "Could not find file on S3: #{e.message}"
end
|