class Brutalismbot::S3::Client

Attributes

client[R]
prefix[R]

Public Class Methods

new(bucket:nil, prefix:nil, client:nil) click to toggle source
# File lib/brutalismbot/s3/client.rb, line 8
def initialize(bucket:nil, prefix:nil, client:nil)
  @client = client || Aws::S3::Client.new
  @bucket = bucket || ENV["S3_BUCKET"] || "brutalismbot"
  @prefix = prefix || ENV["S3_PREFIX"] || "data/v1/"
end

Public Instance Methods

bucket(**options) click to toggle source
# File lib/brutalismbot/s3/client.rb, line 14
def bucket(**options)
  options[:name] ||= @bucket
  options[:client] ||= @client
  Aws::S3::Bucket.new(**options)
end
get(key:, bucket:nil, **options) { |object| ... } click to toggle source
# File lib/brutalismbot/s3/client.rb, line 20
def get(key:, bucket:nil, **options, &block)
  bucket ||= @bucket
  Brutalismbot.logger.info("GET s3://#{@bucket}/#{key}")
  object = @client.get_object(bucket: bucket, key: key, **options)
  block_given? ? yield(object) : object
end
keys(bucket:nil, prefix:nil, **options) click to toggle source
# File lib/brutalismbot/s3/client.rb, line 27
def keys(bucket:nil, prefix:nil, **options)
  bucket ||= @bucket
  prefix ||= @prefix
  Brutalismbot.logger.info("LIST s3://#{@bucket}/#{prefix}*")
  result = self.bucket(name: bucket).objects(prefix: prefix, **options)
  Prefix.new(result)
end
list(bucket:nil, prefix:nil, **options, &block) click to toggle source
# File lib/brutalismbot/s3/client.rb, line 35
def list(bucket:nil, prefix:nil, **options, &block)
  result = keys(bucket: bucket, prefix: prefix, **options)
  Prefix.new(result, &block)
end