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

- old
+ new

@@ -1,187 +1,194 @@ # encoding: utf-8 module Ayadn class Check - def self.same_username(stream) + def initialize + @status = Status.new + end + + def same_username(stream) stream['data']['username'] == Settings.config[:identity][:username] end - def self.auto_save_muted(list) - FileOps.save_muted_list(list) if Settings.options[:backup][:auto_save_lists] + def auto_save_muted(list) + FileOps.save_muted_list(list) if Settings.options[:backup][:lists] end - def self.auto_save_followers(list) - FileOps.save_followers_list(list) if Settings.options[:backup][:auto_save_lists] + def auto_save_followers(list) + FileOps.save_followers_list(list) if Settings.options[:backup][:lists] end - def self.auto_save_followings(list) - FileOps.save_followings_list(list) if Settings.options[:backup][:auto_save_lists] + def auto_save_followings(list) + FileOps.save_followings_list(list) if Settings.options[:backup][:lists] end - def self.no_username username - abort(Status.error_missing_username) if username.empty? + def no_username username + if username.empty? + @status.error_missing_username + exit + end end - def self.no_data stream, target + def no_data stream, target if stream['data'].empty? Errors.warn "In action/#{target}: no data" - abort(Status.empty_list) + @status.empty_list + exit end end - def self.no_new_posts stream, options, title - if options[:new] + def no_new_posts stream, options, title + if options[:new] == true unless Databases.has_new?(stream, title) - abort(Status.no_new_posts) + @status.no_new_posts + exit end end end - def self.no_post stream, post_id + def no_post stream, post_id if stream['meta']['code'] == 404 - puts Status.post_404(post_id) + @status.post_404(post_id) Errors.info("Impossible to find #{post_id}") exit end end - def self.bad_post_id post_id - abort(Status.error_missing_post_id) unless post_id.is_integer? + def bad_post_id post_id + unless post_id.is_integer? + @status.error_missing_post_id + exit + end end - def self.no_user stream, username + def bad_post_ids(post_ids) + post_ids.each do |id| + unless id.is_integer? + @status.error_missing_post_id + exit + end + end + end + + def no_user stream, username if stream['meta']['code'] == 404 - puts Status.user_404(username) + @status.user_404(username) Errors.info("User #{username} doesn't exist") exit end end - def self.has_been_unfollowed(username, resp) + def has_been_unfollowed(username, resp) if resp['meta']['code'] == 200 - puts Status.unfollowed(username) - Logs.rec.info "Unfollowed #{username}." + @status.unfollowed(username) else - Errors.whine(Status.not_unfollowed(username), resp) + @status.not_unfollowed(username) end end - def self.has_been_unmuted(username, resp) + def has_been_unmuted(username, resp) if resp['meta']['code'] == 200 - puts Status.unmuted(username) - Logs.rec.info "Unmuted #{username}." + @status.unmuted(username) else - Errors.whine(Status.not_unmuted(username), resp) + @status.not_unmuted(username) end end - def self.already_starred(resp) + def already_starred(resp) if resp['data']['you_starred'] - puts "\nYou already starred this post.\n".color(:red) + @status.already_starred exit end end - def self.already_reposted(resp) + def already_reposted(resp) if resp['data']['you_reposted'] - puts "\nYou already reposted this post.\n".color(:red) + @status.already_reposted exit end end - def self.has_been_starred(post_id, resp) + def has_been_starred(post_id, resp) if resp['meta']['code'] == 200 - puts Status.starred(post_id) - Logs.rec.info "Starred #{post_id}." + @status.starred(post_id) else - Errors.whine(Status.not_starred(post_id), resp) + @status.not_starred(post_id) end end - def self.has_been_reposted(post_id, resp) + def has_been_reposted(post_id, resp) if resp['meta']['code'] == 200 - puts Status.reposted(post_id) - Logs.rec.info "Reposted #{post_id}." + @status.reposted(post_id) else - Errors.whine(Status.not_reposted(post_id), resp) + @status.not_reposted(post_id) end end - def self.has_been_blocked(username, resp) + def has_been_blocked(username, resp) if resp['meta']['code'] == 200 - puts Status.blocked(username) - Logs.rec.info "Blocked #{username}." + @status.blocked(username) else - Errors.whine(Status.not_blocked(username), resp) + @status.not_blocked(username) end end - def self.has_been_muted(username, resp) + def has_been_muted(username, resp) if resp['meta']['code'] == 200 - puts Status.muted(username) - Logs.rec.info "Muted #{username}." + @status.muted(username) else - Errors.whine(Status.not_muted(username), resp) + @status.not_muted(username) end end - def self.has_been_followed(username, resp) + def has_been_followed(username, resp) if resp['meta']['code'] == 200 - puts Status.followed(username) - Logs.rec.info "Followed #{username}." + @status.followed(username) else - Errors.whine(Status.not_followed(username), resp) + @status.not_followed(username) end end - def self.has_been_deleted(post_id, resp) + def has_been_deleted(post_id, resp) if resp['meta']['code'] == 200 - puts Status.deleted(post_id) - Logs.rec.info "Deleted post #{post_id}." + @status.deleted(post_id) else - Errors.whine(Status.not_deleted(post_id), resp) + @status.not_deleted(post_id) end end - def self.message_has_been_deleted(message_id, resp) + def message_has_been_deleted(message_id, resp) if resp['meta']['code'] == 200 - puts Status.deleted_m(message_id) - Logs.rec.info "Deleted message #{message_id}." + @status.deleted_m(message_id) else - Errors.whine(Status.not_deleted(message_id), resp) + @status.not_deleted_m(message_id) end end - def self.has_been_unblocked(username, resp) + def has_been_unblocked(username, resp) if resp['meta']['code'] == 200 - puts Status.unblocked(username) - Logs.rec.info "Unblocked #{username}." + @status.unblocked(username) else - Errors.whine(Status.not_unblocked(username), resp) + @status.not_unblocked(username) end end - def self.has_been_unstarred(post_id, resp) + def has_been_unstarred(post_id, resp) if resp['meta']['code'] == 200 - puts Status.unstarred(post_id) - Logs.rec.info "Unstarred #{post_id}." + @status.unstarred(post_id) else - Errors.whine(Status.not_unstarred(post_id), resp) + @status.not_unstarred(post_id) end end - def self.has_been_unreposted(post_id, resp) + def has_been_unreposted(post_id, resp) if resp['meta']['code'] == 200 - puts Status.unreposted(post_id) - Logs.rec.info "Unreposted #{post_id}." + @status.unreposted(post_id) else - Errors.whine(Status.not_unreposted(post_id), resp) + @status.not_unreposted(post_id) end end - - end end