Class: CoderCompanion::S3Client
- Inherits:
-
Object
- Object
- CoderCompanion::S3Client
- Defined in:
- lib/codercompanion/s3_client.rb
Instance Attribute Summary collapse
- #client ⇒ Aws::S3::Client readonly
- #resource ⇒ Aws::S3::Resource readonly
- #s3_bucket ⇒ String readonly
Instance Method Summary collapse
-
#initialize(params) ⇒ S3Client
constructor
A new instance of S3Client.
- #put_object(local_file_path, key) ⇒ Object
Constructor Details
#initialize(params) ⇒ S3Client
Returns a new instance of S3Client.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/codercompanion/s3_client.rb', line 13 def initialize params @client = Aws::S3::Client.new( :access_key_id => params[:access_key_id], :secret_access_key => params[:secret_access_key], :session_token => params[:session_token], :region => params[:region] ) @resource = Aws::S3::Resource.new(client: @client) @s3_bucket = params[:s3_bucket] end |
Instance Attribute Details
#client ⇒ Aws::S3::Client (readonly)
5 6 7 |
# File 'lib/codercompanion/s3_client.rb', line 5 def client @client end |
#resource ⇒ Aws::S3::Resource (readonly)
8 9 10 |
# File 'lib/codercompanion/s3_client.rb', line 8 def resource @resource end |
#s3_bucket ⇒ String (readonly)
11 12 13 |
# File 'lib/codercompanion/s3_client.rb', line 11 def s3_bucket @s3_bucket end |
Instance Method Details
#put_object(local_file_path, key) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/codercompanion/s3_client.rb', line 25 def put_object local_file_path, key path = File.(local_file_path) obj = resource.bucket(s3_bucket).object(key) response = obj.upload_file(path, { server_side_encryption: "AES256"}) return response end |