Class: Shipt
- Inherits:
-
Object
- Object
- Shipt
- Defined in:
- lib/shipt.rb
Instance Method Summary collapse
-
#initialize(bucket_key, options = {}) ⇒ Shipt
constructor
A new instance of Shipt.
- #upload_file(path) ⇒ Object
Constructor Details
#initialize(bucket_key, options = {}) ⇒ Shipt
Returns a new instance of Shipt.
7 8 9 10 11 12 13 14 15 |
# File 'lib/shipt.rb', line 7 def initialize(bucket_key, ={}) raise RuntimeError unless [:access_key] && [:secret_key] @name = [bucket_key, [:descriptor]].join('-') @bucket_key = [[:namespace], bucket_key].join('-') @access_key = [:access_key] @secret_key = [:secret_key] @logger = Logger.new([:logger] || STDOUT) end |
Instance Method Details
#upload_file(path) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/shipt.rb', line 17 def upload_file(path) ext = File.extname(path) = File.basename(path) =~ /\.log\.([\d-]*T[\d-]+)\./ ? $1 : Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S%Z") key_name = if ext == '.log' "#{@name}-#{}#{ext}" else "#{@name}-#{}.log#{ext}" end @logger.info "Uploading \"#{path}\" => \"#{key_name}\"" @logger.info "Creating and Moving to directory #{@bucket_key}" @directory = connection.directories.create(:key => "#{@bucket_key}") r = connection.put_object(@bucket_key, key_name, File.read(path)) @logger.info "Uploaded: #{r.inspect}" return r end |