Class: Ayadn::Stream
- Inherits:
-
Object
show all
- Defined in:
- lib/ayadn/stream.rb
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
#initialize(api, view, workers) ⇒ Stream
Returns a new instance of Stream.
6
7
8
9
10
11
12
|
# File 'lib/ayadn/stream.rb', line 6
def initialize api, view, workers
@api = api
@view = view
@workers = workers
@check = Check.new
@status = Status.new
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, options) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/ayadn/stream.rb', line 34
def method_missing(meth, options)
case meth
when :checkins, :trending, :photos
stream(meth, options, "explore:#{meth}")
when :conversations
stream(meth, options, "explore:replies")
when :unified
stream(meth, options, meth.to_s)
else
super
end
end
|
Instance Method Details
#blocked(options) ⇒ Object
159
160
161
162
163
164
165
166
|
# File 'lib/ayadn/stream.rb', line 159
def blocked(options)
@view.downloading(options)
show_raw_list(nil, :blocked, options)
list = @api.get_blocked
Errors.no_data('blocked') if list.empty?
@view.list(:blocked, list, nil, options)
Databases.add_to_users_db_from_list(list)
end
|
#convo(post_id, options) ⇒ Object
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
# File 'lib/ayadn/stream.rb', line 213
def convo(post_id, options)
@check.bad_post_id(post_id)
if options[:force]
Settings.global[:force] = true
else
post_id = @workers.get_real_post_id(post_id)
end
@view.downloading(options)
details = @api.get_details(post_id, options)
@check.no_post(details, post_id)
id = @workers.get_original_id(post_id, details)
stream = @api.get_convo(id, options)
@check.no_post(stream, id)
Databases.("replies:#{id}", stream['meta']['max_id'])
options = options.dup
options[:reply_to] = details['data']['reply_to'].to_i unless details['data']['reply_to'].nil?
options[:post_id] = post_id.to_i
@view.render(stream, options)
Scroll.new(@api, @view).convo(id, options) if options[:scroll]
puts "\n" if Settings.options[:timeline][:compact] && options[:raw].nil?
end
|
#followers(username, options) ⇒ Object
137
138
139
140
141
142
143
144
145
146
147
|
# File 'lib/ayadn/stream.rb', line 137
def followers(username, options)
@check.no_username(username)
username = @workers.add_arobase(username)
@view.downloading(options)
show_raw_list(username, :followers, options)
list = @api.get_followers(username)
@check.auto_save_followers(list)
Errors.no_data('followers') if list.empty?
@view.list(:followers, list, username, options)
Databases.add_to_users_db_from_list(list)
end
|
#followings(username, options) ⇒ Object
125
126
127
128
129
130
131
132
133
134
135
|
# File 'lib/ayadn/stream.rb', line 125
def followings(username, options)
@check.no_username(username)
username = @workers.add_arobase(username)
@view.downloading(options)
show_raw_list(username, :followings, options)
list = @api.get_followings(username)
@check.auto_save_followings(list)
Errors.no_data('followings') if list.empty?
@view.list(:followings, list, username, options)
Databases.add_to_users_db_from_list(list)
end
|
#global(settings) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/ayadn/stream.rb', line 14
def global settings
Settings.global[:force] = true if settings[:force]
options = settings.dup
options[:filter] = nicerank_true()
@view.downloading(options)
unless options[:scroll]
stream = @api.get_global(options)
Settings.global[:force] == true ? niceranks = {} : niceranks = NiceRank.new.get_ranks(stream)
@check.no_new_posts(stream, options, 'global')
Databases.save_max_id(stream, 'global') unless stream['meta']['max_id'].nil?
@view.render(stream, options, niceranks)
end
if options[:scroll]
@view.clear_screen()
Scroll.new(@api, @view).global(options)
end
puts "\n" if Settings.options[:timeline][:compact] && options[:raw].nil?
end
|
#interactions(options) ⇒ Object
168
169
170
171
172
173
174
175
|
# File 'lib/ayadn/stream.rb', line 168
def interactions(options)
@view.downloading(options)
stream = @api.get_interactions
@view.if_raw(stream, options)
@view.clear_screen
@view.show_interactions(stream['data'])
puts "\n" if Settings.options[:timeline][:compact] == true
end
|
#mentions(username, options) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
# File 'lib/ayadn/stream.rb', line 64
def mentions username, options
Settings.global[:force] = true if options[:force]
@check.no_username(username)
username = @workers.add_arobase(username)
@view.downloading(options)
unless options[:scroll]
stream = @api.get_mentions(username, options)
@check.no_user(stream, username)
Databases.save_max_id(stream)
@check.no_data(stream, 'mentions')
options = options.dup
options[:in_mentions] = true
@view.render(stream, options)
end
if options[:scroll]
@view.clear_screen()
Scroll.new(@api, @view).mentions(username, options)
end
puts "\n" if Settings.options[:timeline][:compact] && options[:raw].nil?
end
|
#messages(channel_id, options) ⇒ Object
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
|
# File 'lib/ayadn/stream.rb', line 235
def messages(channel_id, options)
if options[:silent]
Settings.options[:marker][:messages] = false
end
channel_id = @workers.get_channel_id_from_alias(channel_id)
@view.downloading(options)
resp = @api.get_messages(channel_id, options)
name = "channel:#{channel_id}"
@check.no_new_posts(resp, options, name)
if Settings.options[: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, options)
@check.no_data(resp, 'messages') unless options[:scroll]
@view.render(resp, options)
Scroll.new(@api, @view).messages(channel_id, options) if options[:scroll]
puts "\n" if Settings.options[:timeline][:compact] && options[:raw].nil?
end
|
#muted(options) ⇒ Object
149
150
151
152
153
154
155
156
157
|
# File 'lib/ayadn/stream.rb', line 149
def muted(options)
@view.downloading(options)
show_raw_list(nil, :muted, options)
list = @api.get_muted
@check.auto_save_muted(list)
Errors.no_data('muted') if list.empty?
@view.list(:muted, list, nil, options)
Databases.add_to_users_db_from_list(list)
end
|
#posts(username, options) ⇒ Object
85
86
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
|
# File 'lib/ayadn/stream.rb', line 85
def posts username, options
Settings.global[:force] = true if options[:force]
@check.no_username(username)
username = @workers.add_arobase(username)
@view.downloading(options)
stream = @api.get_posts(username, options)
@check.no_user(stream, username)
Databases.save_max_id(stream) unless stream['meta']['marker'].nil?
@check.no_data(stream, 'mentions')
unless options[:raw] || Settings.global[:force]
if Settings.options[: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 options[:raw] || Settings.global[:force]
@status.no_force("#{username.downcase}")
exit
end
end
@view.render(stream, options)
Scroll.new(@api, @view).posts(username, options) if options[:scroll]
puts "\n" if Settings.options[:timeline][:compact] && options[:raw].nil?
end
|
#random_posts(options) ⇒ Object
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
289
290
291
292
|
# File 'lib/ayadn/stream.rb', line 261
def random_posts(options)
Settings.global[:force] = true
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 = options[: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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/ayadn/stream.rb', line 47
def stream meth, options, target
Settings.global[:force] = true if options[:force]
@view.downloading(options)
unless options[:scroll]
stream = @api.send("get_#{meth}".to_sym, options)
@check.no_new_posts(stream, options, target)
Databases.save_max_id(stream)
@view.render(stream, options)
end
if options[:scroll]
@view.clear_screen()
Scroll.new(@api, @view).send(meth, options)
end
puts "\n" if Settings.options[:timeline][:compact] && options[:raw].nil?
end
|
#whatstarred(username, options) ⇒ Object
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/ayadn/stream.rb', line 114
def whatstarred(username, options)
@check.no_username(username)
username = @workers.add_arobase(username)
@view.downloading(options)
stream = @api.get_whatstarred(username, options)
@check.no_user(stream, username)
@check.no_data(stream, 'whatstarred')
options[:extract] ? @view.all_stars_links(stream) : @view.render(stream, options)
puts "\n" if Settings.options[:timeline][:compact] == true
end
|
#whoreposted(post_id, options) ⇒ Object
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
|
# File 'lib/ayadn/stream.rb', line 177
def whoreposted(post_id, options)
@check.bad_post_id(post_id)
unless options[:force]
post_id = @workers.get_real_post_id(post_id)
end
@view.downloading(options)
details = @api.get_details(post_id, options)
@check.no_post(details, post_id)
id = @workers.get_original_id(post_id, details)
list = @api.get_whoreposted(id)
@view.if_raw(list, options)
if list['data'].empty?
@status.nobody_reposted
exit
end
@view.list(:whoreposted, list['data'], post_id)
end
|
#whostarred(post_id, options) ⇒ Object
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
|
# File 'lib/ayadn/stream.rb', line 195
def whostarred(post_id, options)
@check.bad_post_id(post_id)
unless options[:force]
post_id = @workers.get_real_post_id(post_id)
end
@view.downloading(options)
details = @api.get_details(post_id, options)
@check.no_post(details, post_id)
id = @workers.get_original_id(post_id, details)
list = @api.get_whostarred(id)
@view.if_raw(list, options)
if list['data'].empty?
@status.nobody_starred
exit
end
@view.list(:whostarred, list['data'], id)
end
|