lib/ayadn/nowwatching.rb in ayadn-1.8.2 vs lib/ayadn/nowwatching.rb in ayadn-2.0
- old
+ new
@@ -1,15 +1,22 @@
# encoding: utf-8
module Ayadn
class NowWatching
- require 'spotlite'
+ begin
+ require 'spotlite'
+ rescue LoadError => e
+ puts "\nAYADN: Error while loading Gems\n\n"
+ puts "RUBY: #{e}\n\n"
+ exit
+ end
def initialize view = nil
@view = view
@spotlite = Spotlite::Movie
+ @status = Status.new
end
# -----
def get_response args, options
@@ -34,30 +41,31 @@
# -----
def post args, options
options = options.dup
- puts "\nContacting IMDb.com...".color(:cyan)
+ @status.info("connected", "IMDb", "yellow")
response = find_by_title(args, options)
text = format_post(response)
show_post(text)
filename = create_filename(response)
FileOps.download_url(filename, response.poster_url)
@view.clear_screen
- puts "\nPosting and uploading the movie poster...\n".color(:green)
+ @status.info("uploading", "movie poster", "yellow")
options[:embed] = ["#{Settings.config[:paths][:downloads]}/#{filename}"]
options[:movie] = true
dic = {
options: options,
text: text,
title: response.title,
source: 'IMDb'
}
resp = Post.new.post(dic)
- FileOps.save_post(resp) if Settings.options[:backup][:auto_save_sent_posts]
+ FileOps.save_post(resp) if Settings.options[:backup][:posts]
@view.clear_screen
- puts Status.yourpost
+ @status.yourpost
+ puts "\n\n"
@view.show_posted(resp)
end
def find_by_title args, options = {}
resp = @spotlite.find(args.join(' '))
@@ -89,14 +97,22 @@
private
def show_post text
@view.clear_screen
- puts Status.writing
- puts "\nYour post:\n\n".color(:cyan)
- puts text
- puts "\nIs it ok? (y/N)".color(:yellow)
- abort(Status.canceled) unless STDIN.getch == ("y" || "Y")
+ @status.writing
+ @status.to_be_posted
+ thor = Thor::Shell::Basic.new
+ puts "\n"
+ text.split("\n").each do |line|
+ thor.say_status(nil, line.color(Settings.options[:colors][:excerpt]))
+ end
+ puts "\n"
+ @status.ok?
+ unless STDIN.getch == ("y" || "Y")
+ @status.canceled
+ exit
+ end
end
end
end