class DataMigrater::S3

Public Class Methods

new(bucket, credentials, csv_path) click to toggle source
# File lib/data_migrater/s3.rb, line 7
def initialize(bucket, credentials, csv_path)
  @bucket      = bucket
  @credentials = default_credentials.merge(credentials)
  @csv_path    = csv_path

  ::Aws.config.update @credentials
end

Public Instance Methods

delete() click to toggle source
# File lib/data_migrater/s3.rb, line 15
def delete
  client.delete_object options
end
download() click to toggle source
# File lib/data_migrater/s3.rb, line 19
def download
  client.head_object options

  client.get_object options.merge(response_target: @csv_path)
rescue Aws::S3::Errors::NotFound
  []
end

Private Instance Methods

client() click to toggle source
# File lib/data_migrater/s3.rb, line 29
def client
  @client ||= Aws::S3::Client.new
end
default_credentials() click to toggle source
# File lib/data_migrater/s3.rb, line 33
def default_credentials
  {
    access_key_id: ENV['AWS_ACCESS_KEY_ID'],
    region: ENV.fetch('AWS_REGION', 'us-east-1'),
    secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
  }
end
options() click to toggle source
# File lib/data_migrater/s3.rb, line 41
def options
  { bucket: @bucket, key: @csv_path.split('/').last }
end