Class: Beso::Connection::AWS

Inherits:
Object
  • Object
show all
Defined in:
lib/beso/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ AWS

Returns a new instance of AWS.



7
8
9
10
11
12
# File 'lib/beso/connection.rb', line 7

def initialize( options )
  @access_key  = options.delete( :access_key  ) or raise MissingAccessKeyError
  @secret_key  = options.delete( :secret_key  ) or raise MissingSecretKeyError
  @bucket_name = options.delete( :bucket_name ) or raise MissingBucketNameError
  @aws_region  = options.delete( :aws_region  )
end

Instance Method Details

#get(filename) ⇒ Object



14
15
16
# File 'lib/beso/connection.rb', line 14

def get( filename )
  bucket.files.get filename
end

#read(filename) ⇒ Object



18
19
20
# File 'lib/beso/connection.rb', line 18

def read( filename )
  get( filename ).try( :body ) || ''
end

#write(filename, body) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/beso/connection.rb', line 22

def write( filename, body )
  if file = get( filename )
    file.body = body
    file.save
  else
    storage.put_object @bucket_name, filename, body, headers
  end
end