Class: DiffuxCIUploader

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

Constant Summary collapse

BUCKET_NAME =
'diffux_ci-diffs'

Instance Method Summary collapse

Constructor Details

#initializeDiffuxCIUploader

Returns a new instance of DiffuxCIUploader.



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

def initialize
  @s3_access_key_id = DiffuxCIUtils.config['s3_access_key_id']
  @s3_secret_access_key = DiffuxCIUtils.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
# File 'lib/diffux_ci_uploader.rb', line 13

def upload_diffs
  current_snapshots = DiffuxCIUtils.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[:description]}_#{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")
  path = File.expand_path(
    File.join(File.dirname(__FILE__), 'diffux_ci-diffs.html.erb'))
  html.content = ERB.new(File.read(path)).result(binding)
  html.content_type = 'text/html'
  html.save
  html.url
end