lib/t_bird/transmitter.rb in t_bird-0.0.2 vs lib/t_bird/transmitter.rb in t_bird-0.0.3

- old
+ new

@@ -2,40 +2,30 @@ require 'aws/s3' module TBird class Transmitter - include AWS::S3 - attr_reader :name, :file, :metadata - def initialize(name, file, metadata = {}) - @name = name - @file = file - @metadata = default_metadata.merge(metadata) - connect! + def initialize + @s3 = AWS::S3.new(access_key_id: Configuration.aws_key, secret_access_key: Configuration.aws_secret) end - def transmit! - if @transmission.nil? - @transmission = S3Object.store(name, file, Configuration.aws_bucket, metadata) - end - @success ||= Service.response.success? - @success + def transmit!(name, file, options = {}) + s3object = s3bucket.objects[name] + s3object.write(file, default_options.merge(options)) + s3object.public_url(secure: true) end - def url - @url ||= S3Object.url_for(name, Configuration.aws_bucket, authenticated: false, use_ssl: true) - end - private - def connect! - Base.establish_connection!(access_key_id: Configuration.aws_key, secret_access_key: Configuration.aws_secret, use_ssl: true) + def s3bucket + @s3bucket ||= @s3.buckets[Configuration.aws_bucket] end - def default_metadata - { - access: :public_read, - content_type: 'binary/octet-stream' + def default_options + { + acl: :public_read, + content_type: 'binary/octet-stream', + metadata: {} } end end end