Class: Ayadn::Mark
Instance Method Summary collapse
Instance Method Details
#add(*args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/ayadn/mark.rb', line 9 def add(*args) begin init status = Status.new unless args.empty? double = args.dup post_id, convo_title = double.shift, double.join(' ') else status.wrong_arguments exit end Check.new.bad_post_id(post_id) if [:force] Settings.global[:force] = true else post_id = Workers.new.get_real_post_id(post_id) end convo_title = post_id if convo_title == '' api, workers, view = API.new, Workers.new, View.new users, bucket = [], [] view.clear_screen status.info(:connected, "analyzing conversation", :yellow) resp = api.get_convo(post_id, ) posts = workers.build_posts(resp['data'].reverse) posts.each do |id, post| users << "#{post[:original_poster]}" post[:mentions].each {|mention| users << "#{mention}"} bucket << post end users.uniq! now = Time.now.to_s bookmark = { 'id' => post_id, 'root_id' => bucket[0][:id], 'last_id' => (bucket.last)[:id], 'title' => convo_title, 'first_date' => bucket[0][:date], 'last_date' => (bucket.last)[:date], 'mark_date' => now[0..18], 'first_poster' => bucket[0][:original_poster], 'last_poster' => (bucket.last)[:username], 'users' => users, 'size' => bucket.length, 'url' => bucket[0][:canonical_url], 'root_text' => bucket[0][:raw_text], 'root_colorized_text' => bucket[0][:text] } view.clear_screen status.info(:done, "bookmarked conversation:", :green) puts make_entry bookmark Databases.add_bookmark bookmark Logs.rec.info "Added conversation bookmark for post #{bookmark['id']}." status.done rescue => e Errors.global_error({error: e, caller: caller, data: [args]}) end end |
#clear ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ayadn/mark.rb', line 90 def clear begin init status = Status.new status.ask_clear_bookmarks input = STDIN.getch if input == 'y' || input == 'Y' Databases.clear_bookmarks Logs.rec.info "Cleared the bookmarks database." status.done else status.canceled exit end rescue => e Errors.global_error({error: e, caller: caller, data: []}) end end |
#delete(*args) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ayadn/mark.rb', line 113 def delete(*args) begin init status = Status.new if args.empty? status.wrong_arguments exit else post_id = args[0] end Check.new.bad_post_id(post_id) if [:force] Settings.global[:force] = true else post_id = Workers.new.get_real_post_id(post_id) end Databases.delete_bookmark post_id status.done rescue => e Errors.global_error({error: e, caller: caller, data: [args]}) end end |
#list ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/ayadn/mark.rb', line 70 def list begin init list = Databases.all_bookmarks if [:raw] jj JSON.parse(list.to_json) exit end if list.empty? Status.new.empty_list exit end puts "\n" list.each {|marked| puts make_entry(JSON.parse(marked[1])); puts "\n"} rescue => e Errors.global_error({error: e, caller: caller, data: [args, ]}) end end |
#rename(*args) ⇒ Object
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/ayadn/mark.rb', line 139 def rename(*args) begin init status = Status.new unless args.empty? || args[1].nil? arguments = args.dup post_id = arguments.shift else abort Status.wrong_arguments end Check.new.bad_post_id(post_id) if [:force] Settings.global[:force] = true else post_id = Workers.new.get_real_post_id(post_id) end Databases.rename_bookmark post_id, arguments.join(" ") status.done rescue => e Errors.global_error({error: e, caller: caller, data: [args]}) end end |