Class: FramedUploader::Uploader
- Inherits:
-
Object
- Object
- FramedUploader::Uploader
- Defined in:
- lib/framed_uploader/uploader.rb
Constant Summary collapse
- CREDS_ENDPOINT =
'https://app.framed.io/uploads/1.0/credentials'.freeze
Instance Method Summary collapse
-
#initialize(api_key) ⇒ Uploader
constructor
A new instance of Uploader.
- #upload(*filenames) ⇒ Object
Constructor Details
#initialize(api_key) ⇒ Uploader
Returns a new instance of Uploader.
13 14 15 |
# File 'lib/framed_uploader/uploader.rb', line 13 def initialize(api_key) @api_key = api_key end |
Instance Method Details
#upload(*filenames) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/framed_uploader/uploader.rb', line 17 def upload(*filenames) validate_files!(filenames) creds_response = get_credentials! tmpl = Addressable::Template.new(creds_response.fetch(:template)) bucket = creds_response.fetch(:bucket) company_id = creds_response.fetch(:company_id) = Time.now.to_i s3 = s3_client(creds_response) filenames.each do |filename| s3_key = tmpl.({"company_id" => company_id, "timestamp" => , "filename" => filename}).path File.open(filename, 'rb') do |body| s3.put_object(bucket: bucket, key: s3_key, body: body) end end end |