Sha256: e647846f7d28de0417a4edacc71ae42d53d50413d7c8d42b675cc8df485ff76c

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

module Platformx
	module S3Helpers
########################################################
#
# Set Up Connection
#
########################################################
def x_s3_init()

	connection = Fog::Storage.new({
		:provider                 => 'AWS',
		:region 									=> Platformx.configuration.aws_region,
		:aws_access_key_id        => Platformx.configuration.aws_access_key_id,
		:aws_secret_access_key    => Platformx.configuration.aws_secret_access_key
		})
	return connection

end

########################################################
#
# Upload to S3
#
########################################################
def x_s3_upload(new_filename: "", file: "", bucket: "#{Platformx.configuration.aws_bucket}", path: "")


################# Init S3 #################
connection = x_s3_init


################# Set Bucket #################
bucket = connection.directories.create(key: "#{bucket}/#{path}", public: false)

# upload that resume
file = bucket.files.create(
	:key    => "#{new_filename}",
	:body   => open(file),
	:public => false
	)

end


########################################################
#
# Download from S3
#
########################################################
def x_s3_get_link(key: "", bucket:"", bucket_path:"", verbose: false)
	
  connection = x_s3_init
  expiry = Time.now.to_i + 604800
  connection.directories.new(:key => "#{bucket}").files.new(:key => "#{bucket_path}/#{key}").url(expiry)
 
 	if verbose == true
  # returns more information about file from s3
  # directory = connection.directories.get("files.myclocktower.com")
  # file = directory.files.get("support/#{support_id}/#{key}")
  #return file.url(expiry)
	end
 
end

########################################################
#
# End
#
########################################################
	end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
platformx-0.0.7 lib/platformx/aws.rb
platformx-0.0.6 lib/platformx/aws.rb