Class: LikadanUploader

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

Constant Summary collapse

BUCKET_NAME =
'likadan-diffs'

Instance Method Summary collapse

Constructor Details

#initializeLikadanUploader

Returns a new instance of LikadanUploader.



8
9
10
11
# File 'lib/likadan_uploader.rb', line 8

def initialize
  @s3_access_key_id = LikadanUtils.config['s3_access_key_id']
  @s3_secret_access_key = LikadanUtils.config['s3_secret_access_key']
end

Instance Method Details

#upload_diffsObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/likadan_uploader.rb', line 13

def upload_diffs
  current_snapshots = LikadanUtils.current_snapshots
  return [] if current_snapshots[:diffs].empty?

  bucket = find_or_build_bucket

  dir = SecureRandom.uuid

  diff_images = current_snapshots[:diffs].map do |diff|
    image = bucket.objects.build("#{dir}/#{diff[:name]}_#{diff[:viewport]}.png")
    image.content = open(diff[:file])
    image.content_type = 'image/png'
    image.save
    diff[:url] = image.url
    diff
  end

  html = bucket.objects.build("#{dir}/index.html")
  html.content =
    ERB.new(
      File.read(File.expand_path(
        File.join(File.dirname(__FILE__), 'likadan-diffs.html.erb')))
    ).result(binding)
  html.content_type = 'text/html'
  html.save
  html.url
end