Module: FlickrCli::Menu

Defined in:
lib/menu.rb

Class Method Summary collapse

Class Method Details

.contactsObject



73
74
75
76
77
78
79
80
81
82
# File 'lib/menu.rb', line 73

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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/menu.rb', line 44

def self.download_and_print(picked_photo)
  if @cached_art["photo_#{picked_photo.id}"]
    puts @cached_art["photo_#{picked_photo.id}"]
  else
    photos       = flickr.photos.getSizes(:photo_id => picked_photo.id)
    download_url = nil

    ["Large", "Medium"].each do |style|
      if picture = photos.find{ |photo| photo.label == style }
        download_url  = picture.source
      end
      break if download_url
  end
    @cached_art["photo_#{picked_photo.id}"] = AsciiArt.new(download_url).to_ascii_art(width: 150, color: true)

    puts @cached_art["photo_#{picked_photo.id}"]
  end
end

.end_programObject



39
40
41
42
# File 'lib/menu.rb', line 39

def self.end_program
  say self.good_by_message
  exit
end

.good_by_messageObject



63
64
65
66
67
68
69
70
71
# File 'lib/menu.rb', line 63

def self.good_by_message
  ['Be that way.',
    "Goodbye - I'll never love again.",
    'I love my kid, is that a crime?',
    'Smell u l8er sk8ter',
    'How could you do this to me? Now?',
    'Listen to Lilys, Swervedriver, and The Swirilies.',
    'Flickr? I hardly know her'].sample
end


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

def self.main_menu
  choose do |menu|
    menu.prompt = "What do you want to explore?"
    menu.choice("Your Photostream")       { menu_for(flickr.test..username) }
    menu.choice("Contacts' Photostream")  { contacts }
    menu.choice("Quit")                   { end_program }
  end
end


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

def self.menu_for(contact, page = 1)

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

  choose do |menu|
    menu.prompt = "Pick a File (page #{the_page})"

    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 ENTER to continue"
        do_nothing = STDIN.gets
        self.menu_for(FlickrCli::Menu.menu_for(contact, the_page))
      end
    end
    menu.choice("More >>")          { self.menu_for(contact, (the_page+1) )}
    menu.choice("Back <<")          { self.menu_for(contact, (the_page-1) )} if the_page > 1
    menu.choice("~(==::Main::==)~") { self.main_menu }
    menu.choice("Quit")             { self.end_program }
  end
end