Module: AerialRubyClient

Defined in:
lib/aerial_ruby_client.rb,
lib/aerial_ruby_client/version.rb

Constant Summary collapse

VERSION =
"1.1.1"

Instance Method Summary collapse

Instance Method Details

#download_aerials(foldername) ⇒ Object



11
12
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
40
41
# File 'lib/aerial_ruby_client.rb', line 11

def download_aerials(foldername)
  aerialdir = File.join(Dir.home, foldername)
  #=> /home/username/foldername

  Dir.mkdir(aerialdir) unless Dir.exists?(aerialdir)

  url = 'http://a1.phobos.apple.com/us/r1000/000/Features/atv/' +
        'AutumnResources/videos/entries.json'

  response = HTTParty.get(url).to_s
  parsed = JSON.parse(response)
  parsed.each do |item|
    item['assets'].each do |asset|
      filename = asset['timeOfDay'] + '-' + asset['id'] + '.mov'
      filepath = File.join(aerialdir, filename)
      if File.exists?(filepath)
        puts "File #{filename} already exists, skipping..."
      else
        puts "Downloading #{filename} to #{aerialdir}"
        open(asset['url']) do |u|
          File.open(filepath, 'wb') { |f| f.write(u.read) }
        end
      end
    end
  end
  
  puts 'Finished processing all URLs!'

  # Copies the xscreensaver script to the target folder.
  FileUtils.cp("#{__dir__}/aerial_ruby_client/xscreensaver_script.rb", aerialdir)
end