Class: Ayadn::Scroll
Instance Method Summary collapse
- #convo(post_id, options) ⇒ Object
-
#initialize(api, view) ⇒ Scroll
constructor
A new instance of Scroll.
- #messages(channel_id, options) ⇒ Object
- #method_missing(meth, *args) ⇒ Object
- #scroll_explore_stream(target, options) ⇒ Object
- #scroll_user_stream(username, type, options) ⇒ Object
Constructor Details
#initialize(api, view) ⇒ Scroll
Returns a new instance of Scroll.
5 6 7 8 9 10 11 |
# File 'lib/ayadn/scroll.rb', line 5 def initialize(api, view) @api = api @view = view @view.hide_cursor @chars = %w{ - \\ | / } at_exit { @view.show_cursor } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/ayadn/scroll.rb', line 13 def method_missing(meth, *args) = if args.size > 1 args[1] else args[0] end case meth when :trending, :photos, :checkins, :replies, :global, :unified scroll_explore_stream(meth.to_s, ) when :mentions, :posts scroll_user_stream(args[0], meth.to_s, ) else super end end |
Instance Method Details
#convo(post_id, options) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ayadn/scroll.rb', line 72 def convo(post_id, ) Settings.global.scrolling = true = check_raw() loop do begin stream = @api.get_convo(post_id, ) stream_object = StreamObject.new(stream) Debug.stream stream_object, , post_id clear() if Settings..scroll.spinner show_if_new(stream_object, , "replies:#{post_id}") = save_then_return(stream_object, , "replies:#{post_id}") countdown print "..." if Settings..scroll.spinner rescue Interrupt canceled end end end |
#messages(channel_id, options) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/ayadn/scroll.rb', line 91 def (channel_id, ) Settings.global.scrolling = true = check_raw() loop do begin stream = @api.(channel_id, ) stream_object = StreamObject.new(stream) Debug.stream stream_object, , channel_id clear() if Settings..scroll.spinner show_if_new(stream_object, , "channel:#{channel_id}") if Settings..marker. unless stream_object..max_id.nil? marked = @api.update_marker("channel:#{channel_id}", stream_object..max_id) updated = JSON.parse(marked) if updated['meta']['code'] != 200 Errors.warn "couldn't update channel #{channel_id} as read" end end end = save_then_return(stream_object, , "channel:#{channel_id}") countdown print "..." if Settings..scroll.spinner rescue Interrupt canceled end end end |
#scroll_explore_stream(target, options) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ayadn/scroll.rb', line 29 def scroll_explore_stream target, Settings.global.scrolling = true = check_raw() orig_target = target @nr = NiceRank.new loop do begin stream_object = StreamObject.new(get(target, )) stream_object.posts.empty? ? niceranks = {} : niceranks = @nr.get_ranks(stream_object) Debug.stream stream_object, , target target = "explore:#{target}" if explore?(target) # explore but not global clear() if Settings..scroll.spinner show_if_new(stream_object, , target, niceranks) target = orig_target if target =~ /explore/ = save_then_return(stream_object, , target) countdown print "..." if Settings..scroll.spinner rescue Interrupt canceled end end end |
#scroll_user_stream(username, type, options) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/ayadn/scroll.rb', line 52 def scroll_user_stream username, type, Settings.global.scrolling = true = check_raw() id = @api.get_user(username)['data']['id'] loop do begin stream = @api.send("get_#{type}".to_sym, username, ) stream_object = StreamObject.new(stream) Debug.stream stream_object, , username clear() if Settings..scroll.spinner show_if_new(stream_object, , "#{type}:#{id}") = save_then_return(stream_object, , "#{type}:#{id}") countdown print "..." if Settings..scroll.spinner rescue Interrupt canceled end end end |