Class: Ayadn::Stream
- Inherits:
-
Object
- Object
- Ayadn::Stream
- Defined in:
- lib/ayadn/stream.rb
Instance Method Summary collapse
- #blocked(options) ⇒ Object
- #checkins(options) ⇒ Object
- #conversations(options) ⇒ Object
- #convo(post_id, options) ⇒ Object
- #followers(username, options) ⇒ Object
- #followings(username, options) ⇒ Object
- #global(settings) ⇒ Object
-
#initialize(api, view, workers) ⇒ Stream
constructor
A new instance of Stream.
- #interactions(options) ⇒ Object
- #mentions(username, options) ⇒ Object
- #messages(channel_id, options) ⇒ Object
- #muted(options) ⇒ Object
- #photos(options) ⇒ Object
- #posts(username, options) ⇒ Object
- #random_posts(options) ⇒ Object
- #trending(options) ⇒ Object
- #unified(options) ⇒ Object
- #whatstarred(username, options) ⇒ Object
- #whoreposted(post_id, options) ⇒ Object
- #whostarred(post_id, options) ⇒ Object
Constructor Details
#initialize(api, view, workers) ⇒ Stream
Returns a new instance of Stream.
6 7 8 9 10 |
# File 'lib/ayadn/stream.rb', line 6 def initialize api, view, workers @api = api @view = view @workers = workers end |
Instance Method Details
#blocked(options) ⇒ Object
139 140 141 142 143 144 145 146 |
# File 'lib/ayadn/stream.rb', line 139 def blocked() @view.downloading() show_raw_list(nil, :blocked, ) list = @api.get_blocked Errors.no_data('blocked') if list.empty? @view.list(:blocked, list, nil) Databases.add_to_users_db_from_list(list) end |
#checkins(options) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/ayadn/stream.rb', line 21 def checkins @view.downloading() stream = @api.get_checkins() Check.no_new_posts(stream, , 'explore:checkins') Databases.save_max_id(stream) @view.render(stream, ) Scroll.new(@api, @view).checkins() if [:scroll] end |
#conversations(options) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/ayadn/stream.rb', line 60 def conversations @view.downloading() stream = @api.get_conversations() Check.no_new_posts(stream, , 'explore:replies') Databases.save_max_id(stream) @view.render(stream, ) Scroll.new(@api, @view).replies() if [:scroll] end |
#convo(post_id, options) ⇒ Object
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/ayadn/stream.rb', line 180 def convo(post_id, ) Check.bad_post_id(post_id) @view.downloading() details = @api.get_details(post_id, ) Check.no_post(details, post_id) id = @workers.get_original_id(post_id, details) stream = @api.get_convo(id, ) Check.no_post(stream, id) Databases.pagination["replies:#{id}"] = stream['meta']['max_id'] = .dup [:reply_to] = details['data']['reply_to'].to_i unless details['data']['reply_to'].nil? [:post_id] = post_id.to_i @view.render(stream, ) Scroll.new(@api, @view).convo(id, ) if [:scroll] end |
#followers(username, options) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/ayadn/stream.rb', line 117 def followers(username, ) Check.no_username(username) username = @workers.add_arobase(username) @view.downloading() show_raw_list(username, :followers, ) list = @api.get_followers(username) Check.auto_save_followers(list) Errors.no_data('followers') if list.empty? @view.list(:followers, list, username) Databases.add_to_users_db_from_list(list) end |
#followings(username, options) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/ayadn/stream.rb', line 105 def followings(username, ) Check.no_username(username) username = @workers.add_arobase(username) @view.downloading() show_raw_list(username, :followings, ) list = @api.get_followings(username) Check.auto_save_followings(list) Errors.no_data('followings') if list.empty? @view.list(:followings, list, username) Databases.add_to_users_db_from_list(list) end |
#global(settings) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ayadn/stream.rb', line 30 def global settings = settings.dup [:filter] = nicerank_true() @view.downloading() stream = @api.get_global() niceranks = NiceRank.new.get_ranks(stream) Check.no_new_posts(stream, , 'global') Databases.save_max_id(stream) @view.render(stream, , niceranks) Scroll.new(@api, @view).global() if [:scroll] end |
#interactions(options) ⇒ Object
148 149 150 151 152 153 154 |
# File 'lib/ayadn/stream.rb', line 148 def interactions() @view.downloading() stream = @api.get_interactions @view.if_raw(stream, ) @view.clear_screen @view.show_interactions(stream['data']) end |
#mentions(username, options) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ayadn/stream.rb', line 69 def mentions username, Check.no_username(username) username = @workers.add_arobase(username) @view.downloading() stream = @api.get_mentions(username, ) Check.no_user(stream, username) Databases.save_max_id(stream) Check.no_data(stream, 'mentions') = .dup [:in_mentions] = true @view.render(stream, ) Scroll.new(@api, @view).mentions(username, ) if [:scroll] end |
#messages(channel_id, options) ⇒ Object
196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/ayadn/stream.rb', line 196 def (channel_id, ) channel_id = @workers.get_channel_id_from_alias(channel_id) @view.downloading() resp = @api.(channel_id, ) Check.no_new_posts(resp, , "channel:#{channel_id}") Databases.save_max_id(resp) @view.if_raw(resp, ) Check.no_data(resp, 'messages') @view.render(resp, ) Scroll.new(@api, @view).(channel_id, ) if [:scroll] end |
#muted(options) ⇒ Object
129 130 131 132 133 134 135 136 137 |
# File 'lib/ayadn/stream.rb', line 129 def muted() @view.downloading() show_raw_list(nil, :muted, ) list = @api.get_muted Check.auto_save_muted(list) Errors.no_data('muted') if list.empty? @view.list(:muted, list, nil) Databases.add_to_users_db_from_list(list) end |
#photos(options) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/ayadn/stream.rb', line 51 def photos @view.downloading() stream = @api.get_photos() Check.no_new_posts(stream, , 'explore:photos') Databases.save_max_id(stream) @view.render(stream, ) Scroll.new(@api, @view).photos() if [:scroll] end |
#posts(username, options) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ayadn/stream.rb', line 83 def posts username, Check.no_username(username) username = @workers.add_arobase(username) @view.downloading() stream = @api.get_posts(username, ) Check.no_user(stream, username) Databases.save_max_id(stream) Check.no_data(stream, 'mentions') @view.render(stream, ) Scroll.new(@api, @view).posts(username, ) if [:scroll] end |
#random_posts(options) ⇒ Object
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/ayadn/stream.rb', line 208 def random_posts() #_, cols = @view.winsize #max_posts = cols / 16 max_posts = 6 @view.clear_screen puts "Fetching random posts, please wait...".color(:cyan) @max_id = @api.get_global({count: 1})['meta']['max_id'].to_i @view.clear_screen counter = 1 wait = [:wait] || 5 loop do begin @random_post_id = rand(@max_id) @resp = @api.get_details(@random_post_id, {}) next if @resp['data']['is_deleted'] @view.show_simple_post([@resp['data']], {}) counter += 1 if counter == max_posts wait.downto(1) do |i| print "\r#{sprintf("%02d", i)} sec... QUIT WITH [CTRL+C]".color(:cyan) sleep 1 end @view.clear_screen counter = 1 end rescue Interrupt abort(Status.canceled) end end end |
#trending(options) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/ayadn/stream.rb', line 42 def trending @view.downloading() stream = @api.get_trending() Check.no_new_posts(stream, , 'explore:trending') Databases.save_max_id(stream) @view.render(stream, ) Scroll.new(@api, @view).trending() if [:scroll] end |
#unified(options) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/ayadn/stream.rb', line 12 def unified @view.downloading() stream = @api.get_unified() Check.no_new_posts(stream, , 'unified') Databases.save_max_id(stream) @view.render(stream, ) Scroll.new(@api, @view).unified() if [:scroll] end |
#whatstarred(username, options) ⇒ Object
95 96 97 98 99 100 101 102 103 |
# File 'lib/ayadn/stream.rb', line 95 def whatstarred(username, ) Check.no_username(username) username = @workers.add_arobase(username) @view.downloading() stream = @api.get_whatstarred(username, ) Check.no_user(stream, username) Check.no_data(stream, 'whatstarred') [:extract] ? @view.all_stars_links(stream) : @view.render(stream, ) end |
#whoreposted(post_id, options) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/ayadn/stream.rb', line 156 def whoreposted(post_id, ) Check.bad_post_id(post_id) @view.downloading() details = @api.get_details(post_id, ) Check.no_post(details, post_id) id = @workers.get_original_id(post_id, details) list = @api.get_whoreposted(id) @view.if_raw(list, ) abort(Status.nobody_reposted) if list['data'].empty? @view.list(:whoreposted, list['data'], post_id) end |
#whostarred(post_id, options) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/ayadn/stream.rb', line 168 def whostarred(post_id, ) Check.bad_post_id(post_id) @view.downloading() details = @api.get_details(post_id, ) Check.no_post(details, post_id) id = @workers.get_original_id(post_id, details) list = @api.get_whostarred(id) @view.if_raw(list, ) abort(Status.nobody_starred) if list['data'].empty? @view.list(:whostarred, list['data'], id) end |