Class: Ayadn::Stream
Instance Method Summary collapse
- #blocked(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
- #method_missing(meth, options) ⇒ Object
- #muted(options) ⇒ Object
- #posts(username, options) ⇒ Object
- #random_posts(options) ⇒ Object
- #stream(meth, options, target) ⇒ Object
- #whatstarred(username, options) ⇒ Object
- #whoreposted(post_id, options) ⇒ Object
- #whostarred(post_id, options) ⇒ Object
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, options) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ayadn/stream.rb', line 36 def method_missing(meth, ) case meth when :checkins, :trending, :photos stream(meth, , "explore:#{meth}") when :conversations stream(meth, , "explore:replies") when :unified stream(meth, , meth.to_s) else super end end |
Instance Method Details
#blocked(options) ⇒ Object
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/ayadn/stream.rb', line 224 def blocked() @view.downloading() unless ["again"] show_raw_list(nil, :blocked, ) if ["again"] list = FileOps.cached_list("blocked") Errors.no_data('cached blocked') if list.nil? else list = @api.get_blocked end if ["cache"] && ["again"].nil? FileOps.cache_list(list, "blocked") end Errors.no_data('blocked') if list.empty? @view.list(:blocked, list, nil, ) Databases.add_to_users_db_from_list(list) end |
#convo(post_id, options) ⇒ Object
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
# File 'lib/ayadn/stream.rb', line 330 def convo(post_id, ) @check.bad_post_id(post_id) if [:force] Settings.global[:force] = true else post_id = @workers.get_real_post_id(post_id) end @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_insert("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] puts "\n" if Settings.[:timeline][:compact] && [:raw].nil? end |
#followers(username, options) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
# File 'lib/ayadn/stream.rb', line 178 def followers(username, ) @check.no_username(username) username = @workers.add_arobase(username) @view.downloading() unless ["again"] show_raw_list(username, :followers, ) if ["again"] list = FileOps.cached_list("followers") Errors.no_data('cached followers') if list.nil? else list = @api.get_followers(username) end @check.auto_save_followers(list) if ["cache"] && ["again"].nil? FileOps.cache_list(list, "followers") end 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
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/ayadn/stream.rb', line 143 def followings(username, ) @check.no_username(username) username = @workers.add_arobase(username) @view.downloading() unless ["again"] show_raw_list(username, :followings, ) if ["again"] list = FileOps.cached_list("followings") Errors.no_data('cached followings') if list.nil? else list = @api.get_followings(username) end @check.auto_save_followings(list) Errors.no_data('followings') if list.empty? if ["lastpost"] && ["again"].nil? count = list.size @workers.thor.say_status :downloading, "please wait, it may take a while...", :red puts "\n" idx = 0 list.each do |str_id,obj| idx += 1 tmp_username = "@#{obj[0]}" colored_username = tmp_username.color(Settings.[:colors][:username]) iter = "#{idx}/#{count}" @workers.thor.say_status iter.to_sym, "last post from #{colored_username}", :cyan resp = @api.get_posts(tmp_username, {count: 1}) obj << resp["data"][0] end end if ["cache"] && ["again"].nil? FileOps.cache_list(list, "followings") end @view.list(:followings, list, username, ) Databases.add_to_users_db_from_list(list) end |
#global(settings) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ayadn/stream.rb', line 16 def global settings Settings.global[:force] = true if settings[:force] = settings.dup [:filter] = nicerank_true() @view.downloading() unless [:scroll] stream = @api.get_global() Settings.global[:force] == true ? niceranks = {} : niceranks = NiceRank.new.get_ranks(stream) @check.no_new_posts(stream, , 'global') Databases.save_max_id(stream, 'global') unless stream['meta']['max_id'].nil? @view.render(stream, , niceranks) end if [:scroll] @view.clear_screen() Scroll.new(@api, @view).global() end puts "\n" if Settings.[:timeline][:compact] && [:raw].nil? end |
#interactions(options) ⇒ Object
241 242 243 244 245 246 247 248 |
# File 'lib/ayadn/stream.rb', line 241 def interactions() @view.downloading() stream = @api.get_interactions @view.if_raw(stream, ) @view.clear_screen @view.show_interactions(stream['data']) puts "\n" if Settings.[:timeline][:compact] == true end |
#mentions(username, options) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/ayadn/stream.rb', line 66 def mentions username, Settings.global[:force] = true if [:force] @check.no_username(username) username = @workers.add_arobase(username) @view.downloading() unless [:scroll] 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, ) end if [:scroll] @view.clear_screen() Scroll.new(@api, @view).mentions(username, ) end puts "\n" if Settings.[:timeline][:compact] && [:raw].nil? end |
#messages(channel_id, options) ⇒ Object
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 |
# File 'lib/ayadn/stream.rb', line 352 def (channel_id, ) if [:silent] Settings.[:marker][:messages] = false end channel_id = @workers.get_channel_id_from_alias(channel_id) @view.downloading() resp = @api.(channel_id, ) name = "channel:#{channel_id}" @check.no_new_posts(resp, , name) if Settings.[:marker][:messages] == true unless resp['meta']['max_id'].nil? marked = @api.update_marker(name, resp['meta']['max_id']) updated = JSON.parse(marked) if updated['meta']['code'] != 200 raise "couldn't update channel #{channel_id} as read" end end end Databases.save_max_id(resp) @view.if_raw(resp, ) @check.no_data(resp, 'messages') unless [:scroll] @view.render(resp, ) Scroll.new(@api, @view).(channel_id, ) if [:scroll] puts "\n" if Settings.[:timeline][:compact] && [:raw].nil? end |
#muted(options) ⇒ Object
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/ayadn/stream.rb', line 202 def muted() @view.downloading() unless ["again"] show_raw_list(nil, :muted, ) if ["again"] list = FileOps.cached_list("muted") Errors.no_data('cached muted') if list.nil? else list = @api.get_muted end @check.auto_save_muted(list) if ["cache"] && ["again"].nil? FileOps.cache_list(list, "muted") end Errors.no_data('muted') if list.empty? @view.list(:muted, list, nil, ) Databases.add_to_users_db_from_list(list) end |
#posts(username, options) ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/ayadn/stream.rb', line 87 def posts username, Settings.global[:force] = true if [:force] @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) unless stream['meta']['marker'].nil? @check.no_data(stream, 'mentions') unless [:raw] || Settings.global[:force] # this is just to show a message rather than an empty screen if Settings.[:blacklist][:active] == true if Databases.is_in_blacklist?('mention', username) @status.no_force("#{username.downcase}") exit end end end if stream['data'][0]['user']['you_muted'] || stream['data'][0]['user']['you_blocked'] unless [:raw] || Settings.global[:force] @status.no_force("#{username.downcase}") exit end end @view.render(stream, ) Scroll.new(@api, @view).posts(username, ) if [:scroll] puts "\n" if Settings.[:timeline][:compact] && [:raw].nil? end |
#random_posts(options) ⇒ Object
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/ayadn/stream.rb', line 378 def random_posts() Settings.global[:force] = true #_, cols = @view.winsize #max_posts = cols / 16 max_posts = 6 @view.clear_screen @status.info("connected", "fetching random posts", "cyan") @max_id = @api.get_global({count: 1})['meta']['max_id'].to_i @view.clear_screen counter = 1 wait = [:wait] || 10 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... ([CTRL+C] to quit)".color(:cyan) sleep 1 end @view.clear_screen counter = 1 end rescue Interrupt @status.canceled exit end end end |
#stream(meth, options, target) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ayadn/stream.rb', line 49 def stream meth, , target Settings.global[:force] = true if [:force] @view.downloading() unless [:scroll] stream = @api.send("get_#{meth}".to_sym, ) @check.no_new_posts(stream, , target) Databases.save_max_id(stream) @view.render(stream, ) end if [:scroll] @view.clear_screen() Scroll.new(@api, @view).send(meth, ) end puts "\n" if Settings.[:timeline][:compact] && [:raw].nil? end |
#whatstarred(username, options) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/ayadn/stream.rb', line 116 def whatstarred(username, ) @check.no_username(username) username = @workers.add_arobase(username) @view.downloading() unless ["again"] if ["again"] stream = FileOps.cached_list("whatstarred") Errors.no_data('cached whatstarred') if stream.nil? else stream = @api.get_whatstarred(username, ) end @check.no_user(stream, username) @check.no_data(stream, 'whatstarred') if ["cache"] && ["again"].nil? FileOps.cache_list(stream, "whatstarred") end if [:extract] @view.all_stars_links(stream) else @view.render(stream, ) end puts "\n" if Settings.[:timeline][:compact] == true end |
#whoreposted(post_id, options) ⇒ Object
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/ayadn/stream.rb', line 250 def whoreposted(post_id, ) @check.bad_post_id(post_id) unless [:force] post_id = @workers.get_real_post_id(post_id) end @view.downloading() unless ["again"] if ["again"] details = FileOps.cached_list("whoreposted_details") Errors.no_data('cached whoreposted details') if details.nil? else details = @api.get_details(post_id, ) end @check.no_post(details, post_id) id = @workers.get_original_id(post_id, details) if ["cache"] && ["again"].nil? FileOps.cache_list(details, "whoreposted_details") end if ["again"] list = FileOps.cached_list("whoreposted") Errors.no_data('cached whoreposted') if list.nil? else list = @api.get_whoreposted(id) end if ["cache"] && ["again"].nil? FileOps.cache_list(list, "whoreposted") end @view.if_raw(list, ) if list['data'].empty? @status.nobody_reposted exit end @view.list(:whoreposted, list['data'], post_id) end |
#whostarred(post_id, options) ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
# File 'lib/ayadn/stream.rb', line 290 def whostarred(post_id, ) @check.bad_post_id(post_id) unless [:force] post_id = @workers.get_real_post_id(post_id) end @view.downloading() unless ["again"] if ["again"] details = FileOps.cached_list("whostarred_details") Errors.no_data('cached whostarred details') if details.nil? else details = @api.get_details(post_id, ) end @check.no_post(details, post_id) id = @workers.get_original_id(post_id, details) if ["cache"] && ["again"].nil? FileOps.cache_list(details, "whostarred_details") end if ["again"] list = FileOps.cached_list("whostarred") Errors.no_data('cached whostarred') if list.nil? else list = @api.get_whostarred(id) end if ["cache"] && ["again"].nil? FileOps.cache_list(list, "whostarred") end @view.if_raw(list, ) if list['data'].empty? @status.nobody_starred exit end @view.list(:whostarred, list['data'], id) end |