Class: CoderCompanion::S3Client

Inherits:
Object
  • Object
show all
Defined in:
lib/codercompanion/s3_client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientAws::S3::Client (readonly)

Returns:

  • (Aws::S3::Client)


5
6
7
# File 'lib/codercompanion/s3_client.rb', line 5

def client
  @client
end

#resourceAws::S3::Resource (readonly)

Returns:

  • (Aws::S3::Resource)


8
9
10
# File 'lib/codercompanion/s3_client.rb', line 8

def resource
  @resource
end

#s3_bucketString (readonly)

Returns:

  • (String)


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

Parameters:

  • local_file_path (String)


25
26
27
28
29
30
# File 'lib/codercompanion/s3_client.rb', line 25

def put_object local_file_path, key
    path =  File.expand_path(local_file_path)
    obj = resource.bucket(s3_bucket).object(key)
    response = obj.upload_file(path, { server_side_encryption: "AES256"})
    return response
end