Class: Ayadn::Scroll
Instance Method Summary
collapse
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)
options = 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, options)
when :mentions, :posts
scroll_user_stream(args[0], meth.to_s, options)
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, options)
Settings.global.scrolling = true
options = check_raw(options)
loop do
begin
stream = @api.get_convo(post_id, options)
stream_object = StreamObject.new(stream)
Debug.stream stream_object, options, post_id
clear() if Settings.options.scroll.spinner
show_if_new(stream_object, options, "replies:#{post_id}")
options = save_then_return(stream_object, options, "replies:#{post_id}")
countdown
print "..." if Settings.options.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 messages(channel_id, options)
Settings.global.scrolling = true
options = check_raw(options)
loop do
begin
stream = @api.get_messages(channel_id, options)
stream_object = StreamObject.new(stream)
Debug.stream stream_object, options, channel_id
clear() if Settings.options.scroll.spinner
show_if_new(stream_object, options, "channel:#{channel_id}")
if Settings.options.marker.messages
unless stream_object.meta.max_id.nil?
marked = @api.update_marker("channel:#{channel_id}", stream_object.meta.max_id)
updated = JSON.parse(marked)
if updated['meta']['code'] != 200
Errors.warn "couldn't update channel #{channel_id} as read"
end
end
end
options = save_then_return(stream_object, options, "channel:#{channel_id}")
countdown
print "..." if Settings.options.scroll.spinner
rescue Interrupt
canceled
end
end
end
|
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, options
Settings.global.scrolling = true
options = check_raw(options)
orig_target = target
@nr = NiceRank.new
loop do
begin
stream_object = StreamObject.new(get(target, options))
stream_object.posts.empty? ? niceranks = {} : niceranks = @nr.get_ranks(stream_object)
Debug.stream stream_object, options, target
target = "explore:#{target}" if explore?(target)
clear() if Settings.options.scroll.spinner
show_if_new(stream_object, options, target, niceranks)
target = orig_target if target =~ /explore/
options = save_then_return(stream_object, options, target)
countdown
print "..." if Settings.options.scroll.spinner
rescue Interrupt
canceled
end
end
end
|
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, options
Settings.global.scrolling = true
options = check_raw(options)
id = @api.get_user(username)['data']['id']
loop do
begin
stream = @api.send("get_#{type}".to_sym, username, options)
stream_object = StreamObject.new(stream)
Debug.stream stream_object, options, username
clear() if Settings.options.scroll.spinner
show_if_new(stream_object, options, "#{type}:#{id}")
options = save_then_return(stream_object, options, "#{type}:#{id}")
countdown
print "..." if Settings.options.scroll.spinner
rescue Interrupt
canceled
end
end
end
|