Class: DearS3::Cli::ClientHelper

Inherits:
Object
  • Object
show all
Includes:
Thor::Shell
Defined in:
lib/dears3/cli/client_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(s3_client) ⇒ ClientHelper

Returns a new instance of ClientHelper.



6
7
8
9
10
11
12
# File 'lib/dears3/cli/client_helper.rb', line 6

def initialize s3_client
  @s3_client = s3_client

  name = get_bucket_name

  s3_client.set_bucket name
end

Instance Method Details

#current_dir_to_bucket_nameObject



28
29
30
# File 'lib/dears3/cli/client_helper.rb', line 28

def current_dir_to_bucket_name
  File.basename(Dir.getwd).gsub('_', '-')
end

#publishObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/dears3/cli/client_helper.rb', line 32

def publish
  bucket_files = s3_client.files_in_bucket

  if bucket_files.empty?
    abort "Bucket is empty. Please upload at least one file before publishing"
  end

  say "Files currently in your bucket:"
  say bucket_files.join(" | "), :green
  index_doc = request_doc "Pick your bucket's index document:"
  error_doc = request_doc "Pick your bucket's error document:"

  say "Publishing your bucket. This may take a while..."
  bucket_url = s3_client.configure_website index_doc, error_doc
  say "Bucket published at #{ bucket_url }."
end

#unpublishObject



49
50
51
52
# File 'lib/dears3/cli/client_helper.rb', line 49

def unpublish
  bucket_url = s3_client.remove_website
  say "Removed #{ bucket_url } from the web."
end

#uploadObject



14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dears3/cli/client_helper.rb', line 14

def upload
  bucket_name = s3_client.bucket_name

  say "Uploading files to bucket '#{ bucket_name }'."

  begin
    s3_client.walk_and_upload ".", status_proc
  rescue ::AWS::S3::Errors::Forbidden
    alert_access_denied
    exit
  end
  say "Done syncing bucket."
end