Class: RadarGenerator

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

Constant Summary collapse

IMGUR_API_KEY =
ENV['IMGUR_API_KEY']

Class Method Summary collapse

Class Method Details

.gif(radar_code) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/radar_generator.rb', line 10

def self.gif(radar_code)
  template = TemplateGenerator.template(radar_code)

  temporary_image_files = recent_image_filenames(radar_code).map do |radar_image|
    tempfile = Tempfile.new('composed')

    system "convert -layers flatten #{template} #{raindar_url_for(radar_image)} #{tempfile.path}"
    tempfile
  end
  composed_file_paths = temporary_image_files.map { |tempfile|
    tempfile.path
  }.join(' ')

  temporary_radar_gif = Tempfile.new(['radar', '.gif'])
  system "convert -delay 50 -loop 0 #{composed_file_paths} #{temporary_radar_gif.path}"
  temporary_image_files.each(&:unlink)

  imgur_gateway = ImgurGateway.new(filename: temporary_radar_gif.path)
  if imgur_gateway.upload
    temporary_radar_gif.unlink
    imgur_gateway.url
  else
    'http://bit.ly/1OrtWKX'
  end
end