lib/ayadn/status.rb in ayadn-1.8.2 vs lib/ayadn/status.rb in ayadn-2.0

- old
+ new

@@ -1,325 +1,550 @@ # encoding: utf-8 module Ayadn class Status - def self.done - "\nDone.\n".color(:green) + + def initialize + @thor = Thor::Shell::Color.new end - def self.downloaded(name) - "\nFile downloaded in #{Settings.config[:paths][:downloads]}/#{name}\n".color(:green) + + def done + info("done", "", "green") end - def self.links_saved(name) - "\nLinks exported to file #{Settings.config[:paths][:lists]}/#{name}\n".color(:green) + + def canceled + say do + puts "\n" + @thor.say_status :canceled, "", :red + end end - def self.downloading - "Downloading from ADN...\n\n".inverse + + def downloaded(name) + info("downloaded", "#{Settings.config[:paths][:downloads]}/#{name}", "green") end - def self.uploading files - files.length > 1 ? pl = "s" : pl = "" - "\nUploading file#{pl} to ADN...".color(:cyan) + + def links_saved(name) + info("done", "links exported to file #{Settings.config[:paths][:lists]}/#{name}", "green") end - def self.posting - "Posting to ADN...\n\n".inverse + + def downloading + info("connected", "downloading from ADN", "yellow") end - def self.deleting_post(post_id) - "\nDeleting post #{post_id}\n".inverse + + def posting + info("connected", "posting to ADN", "yellow") end - def self.deleting_message(message_id) - "\nDeleting message #{message_id}\n".inverse + + def deleting_post(post_id) + @thor.say_status :deleting, "post #{post_id}", :yellow end - def self.unfollowing(username) - "\nUnfollowing #{username}".inverse + + def deleting_message(message_id) + @thor.say_status :deleting, "message #{message_id}", :yellow end - def self.following(username) - "\nFollowing #{username}".inverse + + def unfollowing(username) + @thor.say_status :unfollowing, username, :yellow end - def self.unmuting(username) - "\nUnmuting #{username}".inverse + + def following(username) + @thor.say_status :following, username, :yellow end - def self.muting(username) - "\nMuting #{username}".inverse + + def unmuting(username) + @thor.say_status :unmuting, username, :yellow end - def self.unblocking(username) - "\nUnblocking #{username}".inverse + + def muting(username) + @thor.say_status :muting, username, :yellow end - def self.blocking(username) - "\nBlocking #{username}".inverse + + def unblocking(username) + @thor.say_status :unblocking, username, :yellow end - def self.unreposting(post_id) - "\nUnreposting #{post_id}".inverse + + def blocking(username) + @thor.say_status :blocking, username, :yellow end - def self.reposting(post_id) - "\nReposting #{post_id}".inverse + + def unreposting(post_id) + @thor.say_status :unreposting, "post #{post_id}", :yellow end - def self.unstarring(post_id) - "\nUnstarring #{post_id}".inverse + + def reposting(post_id) + @thor.say_status :reposting, "post #{post_id}", :yellow end - def self.starring(post_id) - "\nStarring #{post_id}".inverse + + def unstarring(post_id) + @thor.say_status :unstarring, "post #{post_id}", :yellow end - def self.not_deleted(post_id) - "\nCould not delete post #{post_id} (post isn't yours, or is already deleted)\n".color(:red) + + def starring(post_id) + @thor.say_status :starring, "post #{post_id}", :yellow end - def self.not_starred(post_id) - "\nCould not star post #{post_id} (post doesn't exist, or is already starred)\n".color(:red) + + def not_deleted(post_id) + info("error", "could not delete post #{post_id} (post isn't yours, or is already deleted)", "red") end - def self.not_unreposted(post_id) - "\nCould not unrepost post #{post_id} (post isn't yours, isn't a repost, or has been deleted)\n".color(:red) + + def not_deleted_m(post_id) + info("error", "could not delete post #{post_id} (post isn't yours, or is already deleted)", "red") end - def self.not_reposted(post_id) - "\nCould not repost post #{post_id} (post has been deleted?)\n".color(:red) + + def not_starred(post_id) + info("error", "could not star post #{post_id} (post doesn't exist, or is already starred)", "red") end - def self.not_unstarred(post_id) - "\nCould not unstar post #{post_id} (post isn't yours, isn't starred, or has been deleted)\n".color(:red) + + def not_unreposted(post_id) + info("error", "could not unrepost post #{post_id} (post isn't yours, isn't a repost, or has been deleted)", "red") end - def self.not_unfollowed(post_id) - "\nCould not unfollow user #{username} (doesn't exist, or wasn't already followed)\n".color(:red) + + def not_reposted(post_id) + info("error", "could not repost post #{post_id} (post has been deleted?)", "red") end - def self.not_followed(post_id) - "\nCould not follow user #{username} (doesn't exist, or you already follow)\n".color(:red) + + def not_unstarred(post_id) + info("error", "could not unstar post #{post_id} (post isn't yours, isn't starred, or has been deleted)", "red") end - def self.not_unmuted(post_id) - "\nCould not unmute user #{username} (doesn't exist, or wasn't already muted)\n".color(:red) + + def not_unfollowed(username) + info("error", "could not unfollow user #{username} (doesn't exist, or wasn't already followed)", "red") end - def self.not_muted(post_id) - "\nCould not mute user #{username} (doesn't exist, or is already muted)\n".color(:red) + + def not_followed(username) + info("error", "could not follow user #{username} (doesn't exist, or you already follow)", "red") end - def self.not_unblocked(post_id) - "\nCould not unblock user #{username} (doesn't exist, or wasn't already blocked)\n".color(:red) + + def not_unmuted(username) + info("error", "could not unmute user #{username} (doesn't exist, or wasn't already muted)", "red") end - def self.not_blocked(post_id) - "\nCould not block user #{username} (doesn't exist, or is already blocked)\n".color(:red) + + def not_muted(username) + info("error", "could not mute user #{username} (doesn't exist, or is already muted)", "red") end - def self.deleted(post_id) - "\nPost #{post_id} has been deleted.\n".color(:green) + + def not_unblocked(username) + info("error", "could not unblock user #{username} (doesn't exist, or wasn't already blocked)", "red") end - def self.deleted_m(message_id) - "\nMessage #{message_id} has been deleted.\n".color(:green) + + def not_blocked(username) + info("error", "could not block user #{username} (doesn't exist, or is already blocked)", "red") end - def self.starred(post_id) - "\nPost #{post_id} has been starred.\n".color(:green) + + def deleted(post_id) + info("deleted", "post #{post_id}", "green") end - def self.unreposted(post_id) - "\nPost #{post_id} has been unreposted.\n".color(:green) + + def deleted_m(message_id) + info("deleted", "message #{message_id}", "green") end - def self.reposted(post_id) - "\nPost #{post_id} has been reposted.\n".color(:green) + + def starred(post_id) + info("starred", "post #{post_id}", "green") end - def self.unstarred(post_id) - "\nPost #{post_id} has been unstarred.\n".color(:green) + + def unreposted(post_id) + info("unreposted", "post #{post_id}", "green") end - def self.unfollowed(username) - "\nUser #{username} has been unfollowed.\n".color(:green) + + def reposted(post_id) + info("reposted", "post #{post_id}", "green") end - def self.followed(username) - "\nUser #{username} has been followed.\n".color(:green) + + def unstarred(post_id) + info("unstarred", "post #{post_id}", "green") end - def self.unmuted(username) - "\nUser #{username} has been unmuted.\n".color(:green) + + def already_starred + info("ok", "already starred", "green") end - def self.muted(username) - "\nUser #{username} has been muted.\n".color(:green) + + def already_reposted + info("ok", "already reposted", "green") end - def self.unblocked(username) - "\nUser #{username} has been unblocked.\n".color(:green) + + def unfollowed(username) + info("unfollowed", username, "green") end - def self.blocked(username) - "\nUser #{username} has been blocked.\n".color(:green) + + def followed(username) + info("followed", username, "green") end - def self.error_missing_title - "\nYou have to specify (part of) a movie title.\n".color(:red) + + def unmuted(username) + info("unmuted", username, "green") end - def self.error_missing_username - "\nYou have to specify a username.\n".color(:red) + + def muted(username) + info("muted", username, "green") end - def self.error_missing_post_id - "\nYou have to specify a post id.\n".color(:red) + + def unblocked(username) + info("unblocked", username, "green") end - def self.error_missing_message_id - "\nYou have to specify a message id.\n".color(:red) + + def blocked(username) + info("blocked", username, "green") end - def self.error_missing_channel_id - "\nYou have to specify a channel id.\n".color(:red) + + def error_missing_title + info("error", "please specify (part of) a movie title", "red") end - def self.error_missing_hashtag - "\nYou have to specify one or more hashtag(s).\n".color(:red) + + def error_missing_username + info("error", "please specify a username", "red") end - def self.error_missing_parameters - "\nYou have to submit valid items. See 'ayadn -sg' for a list of valid parameters and values.\n".color(:red) + + def error_missing_post_id + info("error", "please specify a post id", "red") end - def self.empty_list - "\n\nThe list is empty.\n\n".color(:red) + + def error_missing_message_id + info("error", "please specify a message id", "red") end - def self.not_found - "\n\n404 NOT FOUND - Object does not exist or has been deleted\n\n" + + def error_missing_channel_id + info("error", "please specify a channel id", "red") end - def self.stopped - "\n\nStopped.".color(:red) + + def error_missing_parameters + say do + @thor.say_status :error, "please submit valid items", :red + @thor.say_status :info, "see `ayadn -sg` for a list of valid parameters and values", :cyan + end end - def self.writing - "\nPosting as ".color(:cyan) + "#{Settings.config[:identity][:handle]}".color(:green) + ".".color(:cyan) + + def empty_list + info("info", "the list is empty", "yellow") end - def self.yourpost - "Your post:\n".color(:cyan) + + def writing + puts "\n" + @thor.say_status "author", "#{Settings.config[:identity][:handle]}", "cyan" + puts "\n" end - def self.yourmessage username = nil - if username.nil? - "Your message:\n\n".color(:cyan) - else - "Your message to ".color(:cyan) + username.color(:green) + ":\n\n".color(:cyan) + + def yourmessage username = nil + if username.nil? + @thor.say_status "", "Your message:" + else + @thor.say_status "", "Your message to #{username}:" + end + puts "\n\n" + end + + def message_from(username) + puts "\n" + @thor.say_status "from", "#{Settings.config[:identity][:handle]}", "yellow" + @thor.say_status "to", "#{username[0]}", "yellow" + end + + def replying_to(post_id) + puts "\n" + @thor.say_status "replying", "to post #{post_id}", "yellow" + end + + def readline + say do + @thor.say_status :next, "type your text", :cyan + @thor.say_status :ok, "[CTRL+D] to validate", :cyan + @thor.say_status :cancel, "[CTRL+C] to cancel", :cyan end end - def self.message_from(username) - "\nMessage from ".color(:cyan) + "#{Settings.config[:identity][:handle]} ".color(:green) + "to ".color(:cyan) + "#{username[0]}".color(:yellow) + ".".color(:cyan) + + def reply + @thor.say_status "max", "#{Settings.config[:post_max_length]} characters", "cyan" end - def self.replying_to(post_id) - "\nReplying to post #{post_id}...\n".color(:green) + + def post + @thor.say_status "max", "#{Settings.config[:post_max_length]} characters", "cyan" end - def self.readline - "\nType your text. ".color(:cyan) + "[CTRL+D] ".color(:green) + "to validate, ".color(:cyan) + "[CTRL+C] ".color(:red) + "to cancel.\n".color(:cyan) + + def message + @thor.say_status "max", "#{Settings.config[:message_max_length]} characters", "cyan" end - # def self.classic - # "\nType your text. ".color(:cyan) + "[ENTER] ".color(:green) + "to validate, ".color(:cyan) + "[CTRL+C] ".color(:red) + "to cancel.\n\n".color(:cyan) - # end - def self.reply - "\n#{Settings.config[:post_max_length]} ".color(:yellow) + "characters maximum.\n" + + def valid_colors(colors_list) + @thor.say_status "info", "valid colors:", "cyan" + say { puts colors_list } end - def self.post - "\n#{Settings.config[:post_max_length]} ".color(:yellow) + "characters maximum.\n" + + def must_be_integer + info("error", "this paramater must be an integer between 1 and 200", "red") end - def self.message - "\n#{Settings.config[:message_max_length]} ".color(:yellow) + "characters maximum.\n" + + def no_new_posts + info("info", "no new posts since your last visit with Ayadn", "cyan") end - # def self.method_missing(meth, args) - # "\nThe command '#{meth} #{args}' doesn't exist.\n".color(:red) - # end - def self.valid_colors(colors_list) - "\nThe valid colors are: #{colors_list}\n".color(:cyan) + + def no_new_messages + info("info", "no new messages", "cyan") end - def self.not_mutable - "\nThis parameter is not modifiable for the time being, sorry.\n".color(:red) + + def type_and_target_missing + info("error", "please submit a TYPE ('mention', 'hashtag', 'client') and a TARGET (a @username, a hashtag, a client name)", "red") end - def self.must_be_integer - "\nThis paramater must be an integer between 1 and 200.\n".color(:red) + + def wrong_arguments + info("error", "invalid arguments", "red") end - def self.no_new_posts - "\nNo new posts since your last visit.\n\n".color(:cyan) + + def no_pin_creds + info("error", "Ayadn couldn't find your Pinboard credentials", "red") end - def self.no_new_messages - "\n No new messages since your last visit.\n".color(:cyan) + + def pin_creds_saved + info("done", "credentials successfully encoded and saved", "green") end - def self.type_and_target_missing - "\nYou have to submit a TYPE (mention, hashtag, client name) and a TARGET (a @username, a hashtag, a client name)\n\n".color(:red) + + def saving_pin + info("saving", "post text and links to Pinboard", "yellow") end - def self.wrong_arguments - "\nYou have to submit valid arguments.\n\n".color(:red) + + def error_only_osx + say do + @thor.say_status :error, "this feature only works with iTunes by default", :red + @thor.say_status :info, "if you've got a Last.fm account, use `ayadn -NP --lastfm` (short: `-l`)", :cyan + end end - def self.no_pin_creds - "\nAyadn couldn't find your Pinboard credentials.\n".color(:red) + + def empty_fields + info("canceled", "couldn't get enough information (empty field)", "red") end - def self.pin_creds_saved - "\n\nCredentials successfully encoded and saved in database.\n\n".color(:green) + + def not_authorized + say do + @thor.say_status :error, "no user authorized", :red + @thor.say_status :auth, "please run `ayadn -auth` to authorize an account", :yellow + end end - def self.saving_pin - "\nSaving post text and links to Pinboard...\n\n".color(:yellow) + + def wtf + info("error", "an unkown error happened", "red") end - def self.error_only_osx - "\nThis feature only works with iTunes by default. If you've got a Last.fm account, add the option:\n\n`ayadn -np --lastfm` (short: `-l`).\n\n".color(:red) + + def redirecting + say do + @thor.say_status :info, "post is a repost", :cyan + @thor.say_status :action, "redirecting", :yellow + end end - def self.empty_fields - "\nCanceled: couldn't get enough information (empty field).\n\n".color(:red) + + def nobody_reposted + info("error", "nobody reposted this post", "red") end - def self.canceled - "\n\nCanceled.\n\n".color(:cyan) + + def nobody_starred + info("error", "nobody starred this post", "red") end - def self.not_authorized - "\nYou need to authorize Ayadn before using it.\n\nPlease run 'ayadn -auth' :)\n\n".color(:red) + + def not_your_repost + info("error", "this post isn't one of your reposts", "red") end - def self.wtf - "\nSomething wrong happened. :(\n\n".color(:red) + + def not_your_starred + info("error", "this isn't one of your starred posts", "red") end - def self.redirecting - "\nPost is a repost. Redirecting...\n".color(:cyan) + + def auto + say do + @thor.say_status :info, "entering the auto posting mode", :cyan + @thor.say_status :info, "each line you type (each time you hit ENTER) is automatically posted to ADN", :cyan + @thor.say_status :info, "at any moment, starting now, hit CTRL+C to exit", :cyan + @thor.say_status :info, "AUTO POSTING MODE ACTIVATED", :yellow + end end - def self.nobody_reposted - "\nNobody reposted this post.\n\n".color(:red) + + def threshold + say do + @thor.say_status :error, "please enter a value between 0.1 and 3.5", :red + @thor.say_status :info, "example: 2.1", :green + end end - def self.nobody_starred - "\nNobody starred this post.\n\n".color(:red) + + def must_be_in_index + info("error", "number must be in the range of the indexed posts", "red") end - def self.not_your_repost - "\nThis post isn't one of your reposts.\n\n".color(:red) + + def user_404(username) + info("error", "user #{username} doesn't exist (it could be a deleted account)", "red") end - def self.not_your_starred - "\nThis isn't one of your starred posts.\n\n".color(:red) + + def post_404(post_id) + info("error", "impossible to find #{post_id} (it may have been deleted)", "red") end - def self.auto - view = "\nEntering the auto posting mode.\n\n".color(:cyan) - view << "In this mode, each line you type (each time you hit ENTER!) is automatically posted to ADN.\n\n".color(:cyan) - view << "At any moment, starting now, hit CTRL+C to exit.\n\n".color(:yellow) - view << "\n\t--AUTO POSTING MODE ACTIVATED--\n\n".color(:red) + + def no_alias + info("error", "this alias doesn't exist", "red") end - def self.reducing db - "\nPlease wait while Ayadn is pruning and compacting the #{db} database...\n".color(:cyan) + + def no_itunes + info("canceled", "unable to get info from iTunes", "red") end - def self.cache_range - "\nPlease enter a number of hours between 1 and 168.\n\n".color(:red) + + def pin_username + info("please", "enter your Pinboard username (CTRL+C to cancel)", "green") end - def self.threshold - "\nPlease enter a value between 0.1 and 3.5, example: 2.1\n\n".color(:red) + + def pin_password + info("please", "enter your Pinboard password (invisible, CTRL+C to cancel)", "green") end - def self.must_be_in_index - "\nNumber must be in the range of the indexed posts.\n".color(:red) + + def too_long(size, max_size) + diff = size - max_size + diff > 1 ? pl = "s" : pl = "" + say do + @thor.say_status :error, "text too long", :red + @thor.say_status :info, "#{max_size} max: #{diff} character#{pl} to remove", :green + end end - def self.user_404 username - "\nUser #{username} doesn't exist. It could be a deleted account.\n".color(:red) + + def no_text + info("error", "no text", "red") end - def self.post_404(post_id) - "\nImpossible to find #{post_id}. This post may have been deleted.\n".color(:red) + + def bad_path + info("error", "couldn't upload this file (path seems wrong)", "red") end - def self.no_alias - "\nThis alias doesn't exist.\n\n".color(:red) + + def no_curl + say do + @thor.say_status :error, "Ayadn needs 'curl' to upload files", :red + @thor.say_status :next, "please install 'curl' (or check that it's properly declared in your $PATH)", :yellow + end end - def self.no_itunes - "\nCanceled: unable to get info from iTunes.\n".color(:red) + + def itunes_store + info("connexion", "fetching informations from the iTunes Store", "green") end - def self.pin_username - "Please enter your Pinboard username (CTRL+C to cancel): ".color(:green) + + def fetching_from(source) + info("connexion", "fetching informations from #{source}", "green") end - def self.pin_password - "\nPlease enter your Pinboard password (invisible, CTRL+C to cancel): ".color(:green) + + def no_movie + info("error", "sorry, can't find this movie", "red") end - def self.too_long size, max_size - "\n\nCanceled: too long. #{max_size} max, #{size - max_size} characters to remove.\n\n\n".color(:red) + + def no_show + info("error", "sorry, can't find this show", "red") end - def self.no_text - "\n\nYou should provide some text.\n\n".color(:red) + + def no_show_infos + info("error", "sorry, can't find informations about this show", "red") end - def self.bad_path - "\n\nCouldn't upload this file (path seems wrong).\n\n".color(:red) + + def no_force(target) + say do + @thor.say_status :error, "'#{target}' can't be displayed (could be muted, blocked, in the Blacklist, etc)", :red + @thor.say_status :info, "please use option '--force' ('-f') to try and display this content anyway", :cyan + end end - def self.no_curl - "\n\nAyadn needs 'curl' to upload files. Please install 'curl' (or check that it's properly declared in your $PATH).\n\n".color(:red) + + def profile_options + info("error", "please specify what to update or delete: --bio, --name, --blog, --twitter or --web", "red") end - def self.itunes_store - "Fetching informations from the Itunes Store...\n".color(:green) + + def one_username + info("error", "please specify only one username", "red") end - def self.fetching_from source - "\nFetching informations from #{source}...\n".color(:green) + + def no_username + say do + @thor.say_status :error, "Ayadn couldn't get your username", :red + @thor.say_status :next, "please try again", :yellow + end end - def self.no_movie - "\nSorry, can't find this movie.\n".color(:blue) + + def has_to_migrate + say do + @thor.say_status :upgrade, "Ayadn 1.x user data detected", :red + @thor.say_status :migrate, "please run `ayadn migrate` to upgrade your account", :yellow + end end - def self.no_show - "\nSorry, can't find this show.\n".color(:blue) + + def updating_profile + info("updating", "profile", "yellow") end - def self.no_show_infos - "\nSorry, can't find informations about this show.\n".color(:blue) + + def to_be_posted + info("", "Your post:") end - def self.no_force target - "\n'#{target}' can't be displayed (could be muted, blocked, in the Blacklist, etc). Use option '--force' ('-f') to try and display this content anyway.\n\n".color(:blue) + + def yourpost + # info("", "Your post:") + @thor.say_status nil, "Your post:" end - def self.profile_options - "\n\nYou have to specify what to update or delete: --bio, --name, --blog, --twitter or --web.\n\n".color(:red) + + def post_info + info("info", "post", "cyan") end + + def repost_info + info("info", "repost of", "cyan") + end + + def unread_from_channel(channel_id) + @thor.say_status :info, "unread message(s) from channel #{channel_id}", :cyan + puts "\n\n" + end + + def ayadn + <<-AYADN + +\t\t _____ __ __ _____ ____ _____ +\t\t | _ | | | _ | \\| | | +\t\t | |_ _| | | | | | | +\t\t |__|__| |_| |__|__|____/|_|___| + + + AYADN + end + def version + puts ayadn() + @thor.say_status :version, "#{VERSION}", :green + @thor.say_status :changelog, "https://github.com/ericdke/na/blob/master/CHANGELOG.md", :yellow + @thor.say_status :docs, "https://github.com/ericdke/na/tree/master/doc", :yellow + puts "\n\n" + end + + def ask_clear_databases + info("question", "are you sure you want to erase all the content of your aliases database? [y/N]", "red") + end + + def ask_clear_blacklist + info("question", "are you sure you want to erase all the content of your blacklist database? [y/N]", "red") + end + + def ask_clear_bookmarks + info("question", "are you sure you want to erase all the content of your bookmarks database? [y/N]", "red") + end + + def ok? + info("confirm", "is it ok? [y/N]", "yellow") + end + + def itunes_store_track(store) + puts "\n" + @thor.say_status "next", "Ayadn will use these elements to insert album artwork and a link", :cyan + end + + ##--- + + def info(status, message, color = nil) + if color.nil? + lamb = lambda { @thor.say_status(status.to_sym, message.to_s) } + else + lamb = lambda { @thor.say_status(status.to_sym, message.to_s, color.to_sym) } + end + puts "\n" + lamb.call + puts "\n" + end + + def say() # expects a block + puts "\n" + yield + puts "\n" + end + end end