Class: MetallumCli::App
- Inherits:
-
Thor
- Object
- Thor
- MetallumCli::App
- Defined in:
- lib/metallum-cli/app.rb
Instance Method Summary collapse
- #album(*album) ⇒ Object
- #artist(*artist) ⇒ Object
- #band(*band) ⇒ Object
- #config ⇒ Object
- #created ⇒ Object
Instance Method Details
#album(*album) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/metallum-cli/app.rb', line 28 def album(*album) result = Client.get_json Url.ALBUM album.join "_" if result["aaData"].length > 1 puts "Your search returned the following albums:\n" result["aaData"].each_with_index do |r, i| album = Nokogiri::HTML(r[0]).css('a').inner_html puts "#{i+1} -> #{album} | #{r[2]}\n" end puts "Select a album number:" choice = STDIN.gets.chomp album = Nokogiri::HTML(result["aaData"][choice.to_i - 1][1]).css('a') album.map{ |link| Album.show_album_page(Client.get_url(link['href']), [:reviews]) } # Client.get_url album elsif result["aaData"].length == 1 album = Nokogiri::HTML(result["aaData"][0][1]).css('a') album.map{ |link| Album.show_album_page(Client.get_url(link['href']), [:reviews]) } else puts "No reults found" end end |
#artist(*artist) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/metallum-cli/app.rb', line 55 def artist(*artist) result = Client.get_json Url.ARTIST artist.join "_" if result["aaData"].length > 1 puts "Your search returned the following artists:\n" result["aaData"].each_with_index do |r, i| artist = Nokogiri::HTML(r[0]).css('a').inner_html puts "#{i+1} -> #{artist} | #{r[2]} | #{r[1]}\n" end puts "Select a artist number:" choice = STDIN.gets.chomp artist = Nokogiri::HTML(result["aaData"][choice.to_i - 1][0]).css('a') artist.map{ |link| Artist.show_artist_page(Client.get_url(link['href']), [:band]) } # Client.get_url artist elsif result["aaData"].length == 1 artist = Nokogiri::HTML(result["aaData"][0][0]).css('a') artist.map{ |link| Artist.show_artist_page(Client.get_url(link['href']), [:band]) } else puts "No reults found" end end |
#band(*band) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/metallum-cli/app.rb', line 85 def band(*band) result = Client.get_json Url.BAND band.join "_" if result["aaData"].length > 1 puts "Your search returned the following bands:\n" result["aaData"].each_with_index do |r, i| band = Nokogiri::HTML(r[0]).css('a').inner_html puts "#{i+1} -> #{band} | #{r[2]} | #{r[1]}\n" end puts "Select a band number:" choice = STDIN.gets.chomp band = Nokogiri::HTML(result["aaData"][choice.to_i - 1][0]).css('a') band.map{ |link| Band.show_band_page(Client.get_url(link['href']), [:discography], [:members], [:similar], [:links]) } # Client.get_url band elsif result["aaData"].length == 1 band = Nokogiri::HTML(result["aaData"][0][0]).css('a') band.map{ |link| Band.show_band_page(Client.get_url(link['href']), [:discography], [:members], [:similar], [:links]) } else puts "No reults found" end end |
#config ⇒ Object
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/metallum-cli/app.rb', line 15 def config Configuration.save if !ENV['EDITOR'].to_s.empty? && !ENV['EDITOR'].nil? exec "$EDITOR #{ENV['HOME']}/.metallumcli" else puts "$EDITOR is not set. Please type your editor:" editor = STDIN.gets.chomp exec "#{editor} #{ENV['HOME']}/.metallumcli" end end |
#created ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/metallum-cli/app.rb', line 111 def created result = Client.get_json Url.CREATED # File.write "out.json", result result["aaData"].each do |r| band = Nokogiri::HTML(r[1]).css('a').inner_html country = Nokogiri::HTML(r[2]).css('a').inner_html user = Nokogiri::HTML(r[5]).css('a').inner_html puts "Band: #{band}" puts "Country: #{country}" puts "Genre: #{r[3]}" puts "Added by user #{user} at #{r[4]}" puts "\n" end puts "Total results: #{result["iTotalDisplayRecords"]}" end |