class S3Repo::Client

AWS API client

Public Class Methods

new(params = {}) click to toggle source
# File lib/s3repo/client.rb, line 7
def initialize(params = {})
  @options = params
  @api = Aws::S3::Client.new(region: region)
end

Public Instance Methods

respond_to_missing?(method, include_all = false) click to toggle source
Calls superclass method
# File lib/s3repo/client.rb, line 12
def respond_to_missing?(method, include_all = false)
  @api.respond_to?(method, include_all) || super
end
upload(key, body) click to toggle source
# File lib/s3repo/client.rb, line 16
def upload(key, body)
  puts "Uploading #{key}"
  put_object key: key, body: body
end
upload_file(key, path) click to toggle source
# File lib/s3repo/client.rb, line 21
def upload_file(key, path)
  upload(key, File.open(path).read)
end

Private Instance Methods

bucket() click to toggle source
# File lib/s3repo/client.rb, line 31
def bucket
  @options[:bucket] || raise('Bucket not set')
end
build_params(args) click to toggle source
# File lib/s3repo/client.rb, line 44
def build_params(args)
  raise 'Too many arguments given' if args.size > 1
  params = args.first || {}
  raise 'Argument must be a hash' unless params.is_a? Hash
  params[:bucket] ||= bucket
  params
end
method_missing(method, *args, &block) click to toggle source
Calls superclass method
# File lib/s3repo/client.rb, line 35
def method_missing(method, *args, &block)
  return super unless @api.respond_to?(method)
  define_singleton_method(method) do |*singleton_args|
    params = build_params(singleton_args)
    @api.send(method, params)
  end
  send(method, args.first)
end
region() click to toggle source
# File lib/s3repo/client.rb, line 27
def region
  @options[:region] || raise('AWS region not set')
end