Sha256: e463fb435a3f17b877ae6b66f1e1767f1093df8a3f04c5a76f1f16583ed666dc
Contents?: true
Size: 942 Bytes
Versions: 13
Compression:
Stored size: 942 Bytes
Contents
require 'aws-sdk' module S3Repo ## # AWS API client class Client def initialize(params = {}) @api = Aws::S3::Client.new @defaults = params end def respond_to?(method, include_all = false) @api.respond_to?(method, include_all) || super end def upload!(key, path) puts "Uploading #{key}" put_object key: key, body: File.open(path) { |fh| fh.read } end private 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 def build_params(args) fail 'Too many arguments given' if args.size > 1 params = args.first || {} fail 'Argument must be a hash' unless params.is_a? Hash @defaults.dup.merge!(params) end end end
Version data entries
13 entries across 13 versions & 1 rubygems