Class: Brutalismbot::S3::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/brutalismbot/s3/client.rb

Direct Known Subclasses

Posts::Client, Brutalismbot::Slack::Client

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bucket: nil, prefix: nil, client: nil) ⇒ Client

Returns a new instance of Client.



8
9
10
11
12
13
14
15
# File 'lib/brutalismbot/s3/client.rb', line 8

def initialize(bucket:nil, prefix:nil, client:nil)
  bucket ||= ENV["S3_BUCKET"] || "brutalismbot"
  prefix ||= ENV["S3_PREFIX"] || "data/v1/"
  client ||= Aws::S3::Client.new
  @bucket = Aws::S3::Bucket.new(name: bucket, client: client)
  @client = client
  @prefix = prefix
end

Instance Attribute Details

#bucketObject (readonly)

Returns the value of attribute bucket.



6
7
8
# File 'lib/brutalismbot/s3/client.rb', line 6

def bucket
  @bucket
end

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/brutalismbot/s3/client.rb', line 6

def client
  @client
end

#prefixObject (readonly)

Returns the value of attribute prefix.



6
7
8
# File 'lib/brutalismbot/s3/client.rb', line 6

def prefix
  @prefix
end

Instance Method Details

#get(key, &block) ⇒ Object



17
18
19
20
21
# File 'lib/brutalismbot/s3/client.rb', line 17

def get(key, &block)
  Brutalismbot.logger.info("GET s3://#{@bucket.name}/#{key}")
  object = @bucket.object(key)
  block_given? ? yield(object) : object
end

#list(**options, &block) ⇒ Object



23
24
25
26
27
# File 'lib/brutalismbot/s3/client.rb', line 23

def list(**options, &block)
  options[:prefix] ||= @prefix
  Brutalismbot.logger.info("LIST s3://#{@bucket.name}/#{options[:prefix]}*")
  Prefix.new(@bucket.objects(options), &block)
end