Class: AwsS3Storage

Inherits:
Object
  • Object
show all
Includes:
Storage
Defined in:
lib/autosparkle/storages/aws_s3_storage.rb

Overview

AwsS3Storage class to upload the updated version of the app

Instance Method Summary collapse

Methods included from Storage

#update_file_destination_path

Constructor Details

#initializeAwsS3Storage

Returns a new instance of AwsS3Storage.



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/autosparkle/storages/aws_s3_storage.rb', line 12

def initialize
  @variables = AwsS3EnvironmentVariables.new

  credentials = Aws::Credentials.new(@variables.access_key, @variables.secret_access_key)
  Aws.config.update({
                      region: @variables.region,
                      credentials: credentials
                    })
  s3 = Aws::S3::Resource.new
  @bucket = s3.bucket(@variables.bucket_name)
  super
end

Instance Method Details

#deployed_appcast_xmlObject



39
40
41
42
43
44
# File 'lib/autosparkle/storages/aws_s3_storage.rb', line 39

def deployed_appcast_xml
  appcast_object = @bucket.object('appcast.xml')
  appcast_object.get.body.read
rescue StandardError
  nil
end

#upload(pkg_path, appcast_path) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/autosparkle/storages/aws_s3_storage.rb', line 25

def upload(pkg_path, appcast_path)
  appcast_object = @bucket.object('appcast.xml')
  appcast_object.upload_file(appcast_path)

  puts_if_verbose "Uploaded the appcast file to the bucket #{@variables.bucket_name}"

  version_object = @bucket.object(update_file_destination_path)
  version_object.upload_file(pkg_path)

  puts_if_verbose "Uploaded version #{Env.variables.marketing_version} to the bucket #{@variables.bucket_name}"
rescue StandardError => e
  raise "Failed to upload file: #{e.message}"
end