lib/platformx/aws.rb in platformx-0.0.7 vs lib/platformx/aws.rb in platformx-0.0.8
- old
+ new
@@ -1,71 +1,71 @@
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
+ #
+ # Amazon S3 helpers
+ #
+ # @author Tim Mushen
+ #
+ module S3Helpers
+
+ # Set up Amazon S3 connection
+ #
+ # @return [Fog::Storage] S3 storage 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
-end
+ # Upload file to S3 with the given parameters
+ #
+ # @param new_filename [String] new name of the file
+ # @param file [String] file to be uploaded
+ # @param bucket [String] bucket to upload the file to
+ # @param path [String] path of the final file
+ #
+ # @return S3 bucket file
+ def x_s3_upload(new_filename: "", file: "", bucket: "#{Platformx.configuration.aws_bucket}", path: "")
+ # Obtaining an S3 connection
+ connection = x_s3_init
-########################################################
-#
-# Upload to S3
-#
-########################################################
-def x_s3_upload(new_filename: "", file: "", bucket: "#{Platformx.configuration.aws_bucket}", path: "")
+ # Creating the directory to upload the file to
+ 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
-################# Init S3 #################
-connection = x_s3_init
+ # Download link from S3 asset
+ #
+ # @param key [String] key or the file name
+ # @param bucket [String] the bucket name
+ # @param bucket_path [String] the bucket path
+ # @param verbose [Boolean] make operation verborse
+ #
+ # @return [String] a public URL for the file
+ #
+ # @note The returned public URL will expire in 7 days
+ 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
-
-################# 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
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
\ No newline at end of file