Module: FlickrCli::Menu

Defined in:
lib/menu.rb

Class Method Summary collapse

Class Method Details

.contactsObject



51
52
53
54
55
56
57
58
59
60
# File 'lib/menu.rb', line 51

def self.contacts
  contacts ||= flickr.contacts.getList.map(&:username).sort

  choose do |menu|
    menu.prompt = "Choose a contact"
    contacts.each do |contact|
      menu.choice(contact.to_sym) { FlickrCli::Menu.menu_for(contact) }
    end
  end
end

.download_and_print(picked_photo) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/menu.rb', line 32

def self.download_and_print(picked_photo)

  photos       = flickr.photos.getSizes(:photo_id => picked_photo.id)
  download_url = nil

  ["Medium", "Medium 640", "Small"].each do |style|
    if picture = photos.find{ |photo| photo.label == style }
      download_url  = picture.source
    end
    break if download_url
  end

  my_file = Tempfile.new('tempimage.jpg')
  my_file << Net::HTTP.get_response(URI.parse(download_url)).body
  my_file.close
  puts FlickrCli::ImageCutter.convert_to_ascii(my_file.path)
  my_file.delete
end


4
5
6
7
8
9
10
# File 'lib/menu.rb', line 4

def self.main_menu
  choose do |menu|
    menu.prompt = "What's up?"
    menu.choice(:Contacts)         { contacts }
    # menu.choice(:"Your Sets")      { sets     }
  end
end


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/menu.rb', line 12

def self.menu_for(contact)

  user_id       = flickr.people.findByUsername(:username => contact).id
  photos        = flickr.photos.search(:user_id => user_id)

  choose do |menu|
    menu.prompt = "Pick a file"

    photos.map(&:title).each do |photo|
      menu.choice(photo) do
        # When you choose a photo...
        FlickrCli::Menu.download_and_print(photos.detect{|x| x.title == photo})
        puts "Press any ENTER to continue"
        do_nothing = STDIN.gets
        self.menu_for(FlickrCli::Menu.menu_for(contact))
      end
    end
  end
end