Class: AppFlight::Plugins::S3::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/appflight/plugins/s3.rb

Instance Method Summary collapse

Constructor Details

#initialize(access_key_id, secret_access_key, region) ⇒ Client

Returns a new instance of Client.



10
11
12
13
14
15
# File 'lib/appflight/plugins/s3.rb', line 10

def initialize(access_key_id, secret_access_key, region)
  @s3 = AWS::S3.new(:access_key_id => access_key_id,
                    :secret_access_key => secret_access_key,
                    :region => region)
  @h = HighLine.new
end

Instance Method Details

#prepare_buckets(options) ⇒ Object



17
18
19
20
# File 'lib/appflight/plugins/s3.rb', line 17

def prepare_buckets(options)
  @s3.buckets.create(options[:bucket]) if options[:create]
  @bucket = @s3.buckets[options[:bucket]]
end

#upload(key, fd) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/appflight/plugins/s3.rb', line 46

def upload(key, fd)
  begin
    @bucket.objects.create(key, fd, :acl => 'public_read')
    puts "\t#{@h.color('upload', :green)}\t#{key}"
  rescue => exception
    say_error "Error while uploading to S3: #{exception}"
  end
end

#upload_files(files = [], options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/appflight/plugins/s3.rb', line 22

def upload_files(files = [], options)
  prepare_buckets(options)
  puts "\t#{@h.color('upload', :green)}\tto S3"
  @page = AppFlight::Web::Page.new
  Dir.glob("#{options[:destination]}/*") { |file|
    if file.match('.erb$') then
      upload(File.basename(file).gsub(".erb",""), 
             StringIO.new(@page.render(file)))
    else
      upload(File.basename(file), File.open(file))
    end
  }
end

#upload_ipa(options) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/appflight/plugins/s3.rb', line 36

def upload_ipa(options)
  @s3.buckets.create(options[:bucket]) if options[:create]
  @bucket = @s3.buckets[options[:bucket]]
  @ipa_name = ENV['ipa_name'] 
  @ipa_name ||= ask "IPA File Name:"
  File.open("./#{@ipa_name}") { |fd|
    upload(@ipa_name, fd)
  }
end