ayadn 1.8.2 → 2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/CHANGELOG.md +73 -52
- data/README.md +17 -3
- data/ayadn.gemspec +3 -4
- data/doc/01-index.md +6 -5
- data/doc/02-install.md +23 -1
- data/doc/03-first-steps.md +22 -28
- data/doc/04-options.md +1 -1
- data/doc/05-streams.md +29 -9
- data/doc/06-post.md +13 -5
- data/doc/07-actions.md +63 -1
- data/doc/08-listings.md +112 -4
- data/doc/09-accounts.md +17 -3
- data/doc/10-nicerank.md +5 -5
- data/doc/11-blacklist.md +8 -14
- data/doc/12-alias.md +1 -13
- data/doc/14-set.md +8 -110
- data/doc/15-nowplaying.md +16 -4
- data/doc/18-contact.md +14 -13
- data/doc/19-examples.md +2 -0
- data/lib/ayadn/action.rb +322 -183
- data/lib/ayadn/alias.rb +17 -45
- data/lib/ayadn/annotations.rb +1 -1
- data/lib/ayadn/api.rb +7 -8
- data/lib/ayadn/app.rb +99 -12
- data/lib/ayadn/authorize.rb +92 -57
- data/lib/ayadn/blacklist.rb +52 -62
- data/lib/ayadn/check.rb +81 -74
- data/lib/ayadn/cnx.rb +77 -26
- data/lib/ayadn/databases.rb +890 -105
- data/lib/ayadn/debug.rb +30 -89
- data/lib/ayadn/descriptions.rb +876 -329
- data/lib/ayadn/endpoints.rb +2 -2
- data/lib/ayadn/errors.rb +9 -9
- data/lib/ayadn/extend.rb +8 -1
- data/lib/ayadn/fileops.rb +10 -8
- data/lib/ayadn/mark.rb +79 -56
- data/lib/ayadn/migration.rb +427 -0
- data/lib/ayadn/nicerank.rb +74 -72
- data/lib/ayadn/nowplaying.rb +123 -60
- data/lib/ayadn/nowwatching.rb +26 -10
- data/lib/ayadn/pinboard.rb +12 -7
- data/lib/ayadn/post.rb +40 -37
- data/lib/ayadn/profile.rb +5 -2
- data/lib/ayadn/scroll.rb +20 -5
- data/lib/ayadn/search.rb +30 -22
- data/lib/ayadn/set.rb +146 -50
- data/lib/ayadn/settings.rb +66 -67
- data/lib/ayadn/status.rb +459 -234
- data/lib/ayadn/stream.rb +80 -46
- data/lib/ayadn/switch.rb +51 -47
- data/lib/ayadn/tvshow.rb +47 -15
- data/lib/ayadn/version.rb +1 -1
- data/lib/ayadn/view.rb +119 -60
- data/lib/ayadn/workers.rb +144 -92
- data/lib/ayadn.rb +7 -8
- data/spec/mock/ayadn/accounts.sqlite +0 -0
- data/spec/mock/ayadn.sqlite +0 -0
- data/spec/unit/annotations_spec.rb +12 -13
- data/spec/unit/api_spec.rb +3 -4
- data/spec/unit/blacklistworkers_spec.rb +18 -23
- data/spec/unit/databases_spec.rb +51 -36
- data/spec/unit/endpoints_spec.rb +5 -2
- data/spec/unit/extend_spec.rb +24 -0
- data/spec/unit/nicerank_spec.rb +13 -13
- data/spec/unit/post_spec.rb +47 -36
- data/spec/unit/set_spec.rb +67 -96
- data/spec/unit/view_spec.rb +12 -6
- data/spec/unit/workers_spec.rb +38 -12
- data/tags +1285 -0
- metadata +29 -39
- data/spec/mock/aliases.db +0 -0
- data/spec/mock/blacklist.db +0 -0
- data/spec/mock/bookmarks.db +0 -0
- data/spec/mock/channels.db +0 -0
- data/spec/mock/index.db +0 -0
- data/spec/mock/nicerank.db +0 -0
- data/spec/mock/pagination.db +0 -0
- data/spec/mock/users.db +0 -0
- data/spec/unit/status_spec.rb +0 -9
data/lib/ayadn/action.rb
CHANGED
@@ -4,27 +4,29 @@ module Ayadn
|
|
4
4
|
|
5
5
|
##
|
6
6
|
# This class is the main initializer + dispatcher
|
7
|
+
# It responds to the CLI commands dispatcher, app.rb
|
7
8
|
|
8
9
|
def initialize
|
9
10
|
@api = API.new
|
10
11
|
@view = View.new
|
11
12
|
@workers = Workers.new
|
12
|
-
@
|
13
|
-
@
|
14
|
-
@
|
13
|
+
@thor = Thor::Shell::Color.new
|
14
|
+
@status = Status.new
|
15
|
+
@check = Check.new
|
15
16
|
Settings.load_config
|
16
17
|
Settings.get_token
|
17
18
|
Settings.init_config
|
18
19
|
Logs.create_logger
|
19
20
|
Databases.open_databases
|
20
|
-
at_exit { Databases.close_all }
|
21
21
|
end
|
22
22
|
|
23
23
|
def method_missing(meth, options)
|
24
24
|
case meth.to_s
|
25
25
|
when 'unified', 'checkins', 'global', 'trending', 'photos', 'conversations', 'interactions'
|
26
26
|
begin
|
27
|
-
|
27
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
28
|
+
stream = Stream.new(@api, @view, @workers)
|
29
|
+
stream.send(meth.to_sym, options)
|
28
30
|
rescue => e
|
29
31
|
Errors.global_error({error: e, caller: caller, data: [meth, options]})
|
30
32
|
end
|
@@ -35,7 +37,9 @@ module Ayadn
|
|
35
37
|
|
36
38
|
def mentions(username, options)
|
37
39
|
begin
|
38
|
-
|
40
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
41
|
+
stream = Stream.new(@api, @view, @workers)
|
42
|
+
stream.mentions(username, options)
|
39
43
|
rescue => e
|
40
44
|
Errors.global_error({error: e, caller: caller, data: [username, options]})
|
41
45
|
end
|
@@ -43,7 +47,9 @@ module Ayadn
|
|
43
47
|
|
44
48
|
def posts(username, options)
|
45
49
|
begin
|
46
|
-
|
50
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
51
|
+
stream = Stream.new(@api, @view, @workers)
|
52
|
+
stream.posts(username, options)
|
47
53
|
rescue => e
|
48
54
|
Errors.global_error({error: e, caller: caller, data: [username, options]})
|
49
55
|
end
|
@@ -51,7 +57,9 @@ module Ayadn
|
|
51
57
|
|
52
58
|
def whatstarred(username, options)
|
53
59
|
begin
|
54
|
-
|
60
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
61
|
+
stream = Stream.new(@api, @view, @workers)
|
62
|
+
stream.whatstarred(username, options)
|
55
63
|
rescue => e
|
56
64
|
Errors.global_error({error: e, caller: caller, data: [username, options]})
|
57
65
|
end
|
@@ -59,7 +67,9 @@ module Ayadn
|
|
59
67
|
|
60
68
|
def whoreposted(post_id, options)
|
61
69
|
begin
|
62
|
-
|
70
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
71
|
+
stream = Stream.new(@api, @view, @workers)
|
72
|
+
stream.whoreposted(post_id, options)
|
63
73
|
rescue => e
|
64
74
|
Errors.global_error({error: e, caller: caller, data: [post_id, options]})
|
65
75
|
end
|
@@ -67,7 +77,9 @@ module Ayadn
|
|
67
77
|
|
68
78
|
def whostarred(post_id, options)
|
69
79
|
begin
|
70
|
-
|
80
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
81
|
+
stream = Stream.new(@api, @view, @workers)
|
82
|
+
stream.whostarred(post_id, options)
|
71
83
|
rescue => e
|
72
84
|
Errors.global_error({error: e, caller: caller, data: [post_id, options]})
|
73
85
|
end
|
@@ -75,52 +87,71 @@ module Ayadn
|
|
75
87
|
|
76
88
|
def convo(post_id, options)
|
77
89
|
begin
|
78
|
-
|
90
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
91
|
+
stream = Stream.new(@api, @view, @workers)
|
92
|
+
stream.convo(post_id, options)
|
79
93
|
rescue => e
|
80
94
|
Errors.global_error({error: e, caller: caller, data: [post_id, options]})
|
81
95
|
end
|
82
96
|
end
|
83
97
|
|
84
|
-
def delete(post_ids)
|
98
|
+
def delete(post_ids, options = {})
|
85
99
|
begin
|
86
100
|
ids = post_ids.select { |post_id| post_id.is_integer? }
|
87
|
-
|
101
|
+
if ids.empty?
|
102
|
+
@status.error_missing_post_id
|
103
|
+
exit
|
104
|
+
end
|
105
|
+
if options[:force]
|
106
|
+
Settings.global[:force] = true
|
107
|
+
else
|
108
|
+
ids.map! { |post_id| @workers.get_real_post_id(post_id) }
|
109
|
+
end
|
110
|
+
puts "\n"
|
88
111
|
ids.each do |post_id|
|
89
|
-
|
112
|
+
@status.deleting_post(post_id)
|
90
113
|
resp = @api.delete_post(post_id)
|
91
|
-
|
114
|
+
@check.has_been_deleted(post_id, resp)
|
92
115
|
end
|
93
116
|
rescue => e
|
94
|
-
Errors.global_error({error: e, caller: caller, data: [
|
117
|
+
Errors.global_error({error: e, caller: caller, data: [post_ids]})
|
95
118
|
end
|
96
119
|
end
|
97
120
|
|
98
121
|
def delete_m(args)
|
99
122
|
begin
|
100
|
-
|
123
|
+
unless args.length >= 2
|
124
|
+
@status.error_missing_message_id
|
125
|
+
exit
|
126
|
+
end
|
101
127
|
channel = args[0]
|
102
128
|
args.shift
|
103
129
|
ids = args.select {|message_id| message_id.is_integer?}
|
104
|
-
|
130
|
+
if ids.empty?
|
131
|
+
@status.error_missing_message_id
|
132
|
+
exit
|
133
|
+
end
|
105
134
|
channel_id = @workers.get_channel_id_from_alias(channel)
|
135
|
+
puts "\n"
|
106
136
|
ids.each do |message_id|
|
107
|
-
|
137
|
+
@status.deleting_message(message_id)
|
108
138
|
resp = @api.delete_message(channel_id, message_id)
|
109
|
-
|
139
|
+
@check.message_has_been_deleted(message_id, resp)
|
110
140
|
end
|
111
141
|
rescue => e
|
112
|
-
Errors.global_error({error: e, caller: caller, data: [
|
142
|
+
Errors.global_error({error: e, caller: caller, data: [args]})
|
113
143
|
end
|
114
144
|
end
|
115
145
|
|
116
146
|
def unfollow(usernames)
|
117
147
|
begin
|
118
|
-
|
148
|
+
@check.no_username(usernames)
|
119
149
|
users = @workers.all_but_me(usernames)
|
120
|
-
puts
|
150
|
+
puts "\n"
|
151
|
+
@status.unfollowing(users.join(','))
|
121
152
|
users.each do |user|
|
122
153
|
resp = @api.unfollow(user)
|
123
|
-
|
154
|
+
@check.has_been_unfollowed(user, resp)
|
124
155
|
end
|
125
156
|
rescue => e
|
126
157
|
Errors.global_error({error: e, caller: caller, data: [usernames]})
|
@@ -129,12 +160,13 @@ module Ayadn
|
|
129
160
|
|
130
161
|
def follow(usernames)
|
131
162
|
begin
|
132
|
-
|
163
|
+
@check.no_username(usernames)
|
133
164
|
users = @workers.all_but_me(usernames)
|
134
|
-
puts
|
165
|
+
puts "\n"
|
166
|
+
@status.following(users.join(','))
|
135
167
|
users.each do |user|
|
136
168
|
resp = @api.follow(user)
|
137
|
-
|
169
|
+
@check.has_been_followed(user, resp)
|
138
170
|
end
|
139
171
|
rescue => e
|
140
172
|
Errors.global_error({error: e, caller: caller, data: [usernames]})
|
@@ -143,12 +175,13 @@ module Ayadn
|
|
143
175
|
|
144
176
|
def unmute(usernames)
|
145
177
|
begin
|
146
|
-
|
178
|
+
@check.no_username(usernames)
|
147
179
|
users = @workers.all_but_me(usernames)
|
148
|
-
puts
|
180
|
+
puts "\n"
|
181
|
+
@status.unmuting(users.join(','))
|
149
182
|
users.each do |user|
|
150
183
|
resp = @api.unmute(user)
|
151
|
-
|
184
|
+
@check.has_been_unmuted(user, resp)
|
152
185
|
end
|
153
186
|
rescue => e
|
154
187
|
Errors.global_error({error: e, caller: caller, data: [usernames]})
|
@@ -157,12 +190,13 @@ module Ayadn
|
|
157
190
|
|
158
191
|
def mute(usernames)
|
159
192
|
begin
|
160
|
-
|
193
|
+
@check.no_username(usernames)
|
161
194
|
users = @workers.all_but_me(usernames)
|
162
|
-
puts
|
195
|
+
puts "\n"
|
196
|
+
@status.muting(users.join(','))
|
163
197
|
users.each do |user|
|
164
198
|
resp = @api.mute(user)
|
165
|
-
|
199
|
+
@check.has_been_muted(user, resp)
|
166
200
|
end
|
167
201
|
rescue => e
|
168
202
|
Errors.global_error({error: e, caller: caller, data: [usernames]})
|
@@ -171,12 +205,13 @@ module Ayadn
|
|
171
205
|
|
172
206
|
def unblock(usernames)
|
173
207
|
begin
|
174
|
-
|
208
|
+
@check.no_username(usernames)
|
175
209
|
users = @workers.all_but_me(usernames)
|
176
|
-
puts
|
210
|
+
puts "\n"
|
211
|
+
@status.unblocking(users.join(','))
|
177
212
|
users.each do |user|
|
178
213
|
resp = @api.unblock(user)
|
179
|
-
|
214
|
+
@check.has_been_unblocked(user, resp)
|
180
215
|
end
|
181
216
|
rescue => e
|
182
217
|
Errors.global_error({error: e, caller: caller, data: [usernames]})
|
@@ -185,78 +220,129 @@ module Ayadn
|
|
185
220
|
|
186
221
|
def block(usernames)
|
187
222
|
begin
|
188
|
-
|
223
|
+
@check.no_username(usernames)
|
189
224
|
users = @workers.all_but_me(usernames)
|
190
|
-
puts
|
225
|
+
puts "\n"
|
226
|
+
@status.blocking(users.join(','))
|
191
227
|
users.each do |user|
|
192
228
|
resp = @api.block(user)
|
193
|
-
|
229
|
+
@check.has_been_blocked(user, resp)
|
194
230
|
end
|
195
231
|
rescue => e
|
196
232
|
Errors.global_error({error: e, caller: caller, data: [usernames]})
|
197
233
|
end
|
198
234
|
end
|
199
235
|
|
200
|
-
def repost(
|
236
|
+
def repost(post_ids, options = {})
|
201
237
|
begin
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
238
|
+
ids = post_ids.select { |post_id| post_id.is_integer? }
|
239
|
+
if ids.empty?
|
240
|
+
@status.error_missing_post_id
|
241
|
+
exit
|
242
|
+
end
|
243
|
+
if options[:force]
|
244
|
+
Settings.global[:force] = true
|
245
|
+
else
|
246
|
+
ids.map! { |post_id| @workers.get_real_post_id(post_id) }
|
247
|
+
end
|
248
|
+
puts "\n"
|
249
|
+
ids.each do |post_id|
|
250
|
+
@status.reposting(post_id)
|
251
|
+
resp = @api.get_details(post_id)
|
252
|
+
@check.already_reposted(resp)
|
253
|
+
id = @workers.get_original_id(post_id, resp)
|
254
|
+
@check.has_been_reposted(id, @api.repost(id))
|
255
|
+
end
|
208
256
|
rescue => e
|
209
|
-
Errors.global_error({error: e, caller: caller, data: [
|
257
|
+
Errors.global_error({error: e, caller: caller, data: [post_ids, id]})
|
210
258
|
end
|
211
259
|
end
|
212
260
|
|
213
|
-
def unrepost(
|
261
|
+
def unrepost(post_ids, options = {})
|
214
262
|
begin
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
263
|
+
ids = post_ids.select { |post_id| post_id.is_integer? }
|
264
|
+
if ids.empty?
|
265
|
+
@status.error_missing_post_id
|
266
|
+
exit
|
267
|
+
end
|
268
|
+
if options[:force]
|
269
|
+
Settings.global[:force] = true
|
219
270
|
else
|
220
|
-
|
271
|
+
ids.map! { |post_id| @workers.get_real_post_id(post_id) }
|
272
|
+
end
|
273
|
+
puts "\n"
|
274
|
+
ids.each do |post_id|
|
275
|
+
@status.unreposting(post_id)
|
276
|
+
if @api.get_details(post_id)['data']['you_reposted']
|
277
|
+
@check.has_been_unreposted(post_id, @api.unrepost(post_id))
|
278
|
+
else
|
279
|
+
@status.not_your_repost
|
280
|
+
end
|
221
281
|
end
|
222
282
|
rescue => e
|
223
|
-
Errors.global_error({error: e, caller: caller, data: [
|
283
|
+
Errors.global_error({error: e, caller: caller, data: [post_ids]})
|
224
284
|
end
|
225
285
|
end
|
226
286
|
|
227
|
-
def unstar(
|
287
|
+
def unstar(post_ids, options = {})
|
228
288
|
begin
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
if
|
235
|
-
|
289
|
+
ids = post_ids.select { |post_id| post_id.is_integer? }
|
290
|
+
if ids.empty?
|
291
|
+
@status.error_missing_post_id
|
292
|
+
exit
|
293
|
+
end
|
294
|
+
if options[:force]
|
295
|
+
Settings.global[:force] = true
|
236
296
|
else
|
237
|
-
|
297
|
+
ids.map! { |post_id| @workers.get_real_post_id(post_id) }
|
298
|
+
end
|
299
|
+
puts "\n"
|
300
|
+
ids.each do |post_id|
|
301
|
+
@status.unstarring(post_id)
|
302
|
+
resp = @api.get_details(post_id)
|
303
|
+
id = @workers.get_original_id(post_id, resp)
|
304
|
+
resp = @api.get_details(id)
|
305
|
+
if resp['data']['you_starred']
|
306
|
+
@check.has_been_unstarred(id, @api.unstar(id))
|
307
|
+
else
|
308
|
+
@status.not_your_starred
|
309
|
+
end
|
238
310
|
end
|
239
311
|
rescue => e
|
240
|
-
Errors.global_error({error: e, caller: caller, data: [
|
312
|
+
Errors.global_error({error: e, caller: caller, data: [post_ids]})
|
241
313
|
end
|
242
314
|
end
|
243
315
|
|
244
|
-
def star(
|
316
|
+
def star(post_ids, options = {})
|
245
317
|
begin
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
318
|
+
ids = post_ids.select { |post_id| post_id.is_integer? }
|
319
|
+
if ids.empty?
|
320
|
+
@status.error_missing_post_id
|
321
|
+
exit
|
322
|
+
end
|
323
|
+
if options[:force]
|
324
|
+
Settings.global[:force] = true
|
325
|
+
else
|
326
|
+
ids.map! { |post_id| @workers.get_real_post_id(post_id) }
|
327
|
+
end
|
328
|
+
puts "\n"
|
329
|
+
ids.each do |post_id|
|
330
|
+
@status.starring(post_id)
|
331
|
+
resp = @api.get_details(post_id)
|
332
|
+
@check.already_starred(resp)
|
333
|
+
id = @workers.get_original_id(post_id, resp)
|
334
|
+
@check.has_been_starred(id, @api.star(id))
|
335
|
+
end
|
252
336
|
rescue => e
|
253
|
-
Errors.global_error({error: e, caller: caller, data: [
|
337
|
+
Errors.global_error({error: e, caller: caller, data: [post_ids]})
|
254
338
|
end
|
255
339
|
end
|
256
340
|
|
257
341
|
def hashtag(hashtag, options)
|
258
342
|
begin
|
259
|
-
|
343
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
344
|
+
search = Search.new(@api, @view, @workers)
|
345
|
+
search.hashtag(hashtag, options)
|
260
346
|
rescue => e
|
261
347
|
Errors.global_error({error: e, caller: caller, data: [hashtag, options]})
|
262
348
|
end
|
@@ -264,7 +350,9 @@ module Ayadn
|
|
264
350
|
|
265
351
|
def search(words, options)
|
266
352
|
begin
|
267
|
-
|
353
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
354
|
+
search = Search.new(@api, @view, @workers)
|
355
|
+
search.find(words, options)
|
268
356
|
rescue => e
|
269
357
|
Errors.global_error({error: e, caller: caller, data: [words, options]})
|
270
358
|
end
|
@@ -272,7 +360,9 @@ module Ayadn
|
|
272
360
|
|
273
361
|
def followings(username, options)
|
274
362
|
begin
|
275
|
-
|
363
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
364
|
+
stream = Stream.new(@api, @view, @workers)
|
365
|
+
stream.followings(username, options)
|
276
366
|
rescue => e
|
277
367
|
Errors.global_error({error: e, caller: caller, data: [username, options]})
|
278
368
|
end
|
@@ -280,7 +370,9 @@ module Ayadn
|
|
280
370
|
|
281
371
|
def followers(username, options)
|
282
372
|
begin
|
283
|
-
|
373
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
374
|
+
stream = Stream.new(@api, @view, @workers)
|
375
|
+
stream.followers(username, options)
|
284
376
|
rescue => e
|
285
377
|
Errors.global_error({error: e, caller: caller, data: [username, options]})
|
286
378
|
end
|
@@ -288,7 +380,9 @@ module Ayadn
|
|
288
380
|
|
289
381
|
def muted(options)
|
290
382
|
begin
|
291
|
-
|
383
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
384
|
+
stream = Stream.new(@api, @view, @workers)
|
385
|
+
stream.muted(options)
|
292
386
|
rescue => e
|
293
387
|
Errors.global_error({error: e, caller: caller, data: [options]})
|
294
388
|
end
|
@@ -296,7 +390,9 @@ module Ayadn
|
|
296
390
|
|
297
391
|
def blocked(options)
|
298
392
|
begin
|
299
|
-
|
393
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
394
|
+
stream = Stream.new(@api, @view, @workers)
|
395
|
+
stream.blocked(options)
|
300
396
|
rescue => e
|
301
397
|
Errors.global_error({error: e, caller: caller, data: [options]})
|
302
398
|
end
|
@@ -308,6 +404,7 @@ module Ayadn
|
|
308
404
|
jj JSON.parse(Settings.config.to_json)
|
309
405
|
jj JSON.parse(Settings.options.to_json)
|
310
406
|
else
|
407
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
311
408
|
@view.show_settings
|
312
409
|
end
|
313
410
|
rescue => e
|
@@ -320,10 +417,10 @@ module Ayadn
|
|
320
417
|
profile = Profile.new(options)
|
321
418
|
profile.get_text_from_user
|
322
419
|
profile.prepare_payload
|
323
|
-
|
420
|
+
@status.updating_profile
|
324
421
|
profile.update
|
325
|
-
|
326
|
-
userinfo('me')
|
422
|
+
@status.done
|
423
|
+
userinfo(['me'], options)
|
327
424
|
rescue => e
|
328
425
|
Errors.global_error({error: e, caller: caller, data: [options]})
|
329
426
|
end
|
@@ -331,18 +428,20 @@ module Ayadn
|
|
331
428
|
|
332
429
|
def userinfo(username, options = {})
|
333
430
|
begin
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
431
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
432
|
+
@check.no_username(username)
|
433
|
+
usernames = @workers.add_arobases_to_usernames(username)
|
434
|
+
usernames.each.with_index do |username, index|
|
435
|
+
if options[:raw]
|
436
|
+
@view.show_raw(@api.get_user(username), options)
|
437
|
+
else
|
438
|
+
@view.downloading if index == 0
|
439
|
+
stream = @api.get_user(username)
|
440
|
+
@check.no_user(stream, username)
|
441
|
+
@check.same_username(stream) ? token = @api.get_token_info['data'] : token = nil
|
442
|
+
@view.clear_screen if index == 0
|
443
|
+
@view.infos(stream['data'], token)
|
444
|
+
end
|
346
445
|
end
|
347
446
|
rescue => e
|
348
447
|
Errors.global_error({error: e, caller: caller, data: [username, options]})
|
@@ -351,8 +450,13 @@ module Ayadn
|
|
351
450
|
|
352
451
|
def postinfo(post_id, options)
|
353
452
|
begin
|
354
|
-
|
355
|
-
|
453
|
+
@check.bad_post_id(post_id)
|
454
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
455
|
+
if options[:force]
|
456
|
+
Settings.global[:force] = true
|
457
|
+
else
|
458
|
+
post_id = @workers.get_real_post_id(post_id)
|
459
|
+
end
|
356
460
|
details = lambda { @api.get_details(post_id, options) }
|
357
461
|
if options[:raw]
|
358
462
|
@view.show_raw(details.call, options)
|
@@ -360,28 +464,27 @@ module Ayadn
|
|
360
464
|
end
|
361
465
|
@view.clear_screen
|
362
466
|
response = details.call
|
363
|
-
|
467
|
+
@check.no_post(response, post_id)
|
364
468
|
resp = response['data']
|
365
469
|
response = @api.get_user("@#{resp['user']['username']}")
|
366
|
-
|
470
|
+
@check.no_user(response, response['data']['username'])
|
367
471
|
stream = response['data']
|
368
|
-
|
472
|
+
@status.post_info
|
369
473
|
@view.show_simple_post([resp], options)
|
370
|
-
if
|
371
|
-
|
372
|
-
|
373
|
-
@view.show_simple_post([resp['repost_of']], options)
|
374
|
-
end
|
375
|
-
if Settings.options[:timeline][:compact] == true
|
376
|
-
puts "\nAUTHOR:\n".inverse
|
377
|
-
else
|
378
|
-
puts "AUTHOR:\n".inverse
|
379
|
-
end
|
474
|
+
puts "\n" if Settings.options[:timeline][:compact] == true
|
475
|
+
@thor.say_status "info", "author", "cyan"
|
476
|
+
puts "\n" unless Settings.options[:timeline][:compact] == true
|
380
477
|
if response['data']['username'] == Settings.config[:identity][:username]
|
381
478
|
@view.show_userinfos(stream, @api.get_token_info['data'], true)
|
382
479
|
else
|
383
480
|
@view.show_userinfos(stream, nil, true)
|
384
481
|
end
|
482
|
+
if resp['repost_of']
|
483
|
+
@status.repost_info
|
484
|
+
Errors.repost(post_id, resp['repost_of']['id'])
|
485
|
+
@view.show_simple_post([resp['repost_of']], options)
|
486
|
+
puts "\n" if Settings.options[:timeline][:compact] == true
|
487
|
+
end
|
385
488
|
rescue => e
|
386
489
|
Errors.global_error({error: e, caller: caller, data: [post_id, options]})
|
387
490
|
end
|
@@ -408,7 +511,7 @@ module Ayadn
|
|
408
511
|
begin
|
409
512
|
file = @api.get_file(file_id)['data']
|
410
513
|
FileOps.download_url(file['name'], file['url'])
|
411
|
-
|
514
|
+
@status.downloaded(file['name'])
|
412
515
|
rescue => e
|
413
516
|
Errors.global_error({error: e, caller: caller, data: [file_id, file['url']]})
|
414
517
|
end
|
@@ -438,7 +541,9 @@ module Ayadn
|
|
438
541
|
|
439
542
|
def messages(channel_id, options)
|
440
543
|
begin
|
441
|
-
|
544
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
545
|
+
stream = Stream.new(@api, @view, @workers)
|
546
|
+
stream.messages(channel_id, options)
|
442
547
|
rescue => e
|
443
548
|
Errors.global_error({error: e, caller: caller, data: [channel_id, options]})
|
444
549
|
end
|
@@ -446,11 +551,12 @@ module Ayadn
|
|
446
551
|
|
447
552
|
def messages_unread(options)
|
448
553
|
begin
|
554
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
449
555
|
if options[:silent]
|
450
|
-
Settings.options[:marker][:
|
556
|
+
Settings.options[:marker][:messages] = false
|
451
557
|
end
|
452
558
|
puts "\n"
|
453
|
-
@
|
559
|
+
@thor.say_status :searching, "channels with unread PMs"
|
454
560
|
response = @api.get_channels
|
455
561
|
unread_channels = []
|
456
562
|
response['data'].map do |ch|
|
@@ -458,11 +564,14 @@ module Ayadn
|
|
458
564
|
unread_channels << ch['id']
|
459
565
|
end
|
460
566
|
end
|
461
|
-
|
567
|
+
if unread_channels.empty?
|
568
|
+
@status.no_new_messages
|
569
|
+
exit
|
570
|
+
end
|
462
571
|
unread_messages = {}
|
463
572
|
unread_channels.each do |id|
|
464
|
-
@
|
465
|
-
since = Databases.
|
573
|
+
@thor.say_status :downloading, "messages from channel #{id}"
|
574
|
+
since = Databases.find_last_id_from("channel:#{id}")
|
466
575
|
unless since.nil?
|
467
576
|
api_options = {count: 20, since_id: since}
|
468
577
|
else
|
@@ -477,26 +586,22 @@ module Ayadn
|
|
477
586
|
end
|
478
587
|
unread_messages[id] = [messages, last_message_id]
|
479
588
|
end
|
480
|
-
if Settings.options[:marker][:
|
589
|
+
if Settings.options[:marker][:messages] == true
|
481
590
|
unread_messages.each do |k,v|
|
482
591
|
name = "channel:#{k}"
|
483
|
-
Databases.
|
592
|
+
Databases.pagination_insert(name, v[1])
|
484
593
|
resp = @api.update_marker(name, v[1])
|
485
594
|
res = JSON.parse(resp)
|
486
595
|
if res['meta']['code'] != 200
|
487
|
-
@
|
596
|
+
@thor.say_status :error, "couldn't update channel #{k} as read", :red
|
488
597
|
else
|
489
|
-
@
|
598
|
+
@thor.say_status :updated, "channel #{k} as read", :green
|
490
599
|
end
|
491
600
|
end
|
492
601
|
end
|
493
602
|
@view.clear_screen
|
494
603
|
unread_messages.each do |k,v|
|
495
|
-
|
496
|
-
puts "\nUnread message from channel #{k}:\n".color(Settings.options[:colors][:unread]).inverse
|
497
|
-
else
|
498
|
-
puts "\nUnread messages from channel #{k}:\n".color(Settings.options[:colors][:unread]).inverse
|
499
|
-
end
|
604
|
+
@status.unread_from_channel(k)
|
500
605
|
@view.show_posts(v[0])
|
501
606
|
end
|
502
607
|
puts "\n" if Settings.options[:timeline][:compact]
|
@@ -505,11 +610,23 @@ module Ayadn
|
|
505
610
|
end
|
506
611
|
end
|
507
612
|
|
508
|
-
def pin(post_id, usertags)
|
509
|
-
|
510
|
-
|
613
|
+
def pin(post_id, usertags, options = {})
|
614
|
+
begin
|
615
|
+
require 'pinboard'
|
616
|
+
require 'base64'
|
617
|
+
rescue LoadError => e
|
618
|
+
puts "\nAYADN: Error while loading Gems\n\n"
|
619
|
+
puts "RUBY: #{e}\n\n"
|
620
|
+
exit
|
621
|
+
end
|
511
622
|
begin
|
512
|
-
|
623
|
+
@check.bad_post_id(post_id)
|
624
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
625
|
+
if options[:force]
|
626
|
+
Settings.global[:force] = true
|
627
|
+
else
|
628
|
+
post_id = @workers.get_real_post_id(post_id)
|
629
|
+
end
|
513
630
|
@view.downloading
|
514
631
|
resp = @api.get_details(post_id)['data']
|
515
632
|
@view.clear_screen
|
@@ -520,16 +637,16 @@ module Ayadn
|
|
520
637
|
post_text = "From: #{handle} -- Text: #{text} -- Links: #{links.join(" ")}"
|
521
638
|
pinner = Ayadn::PinBoard.new
|
522
639
|
unless pinner.has_credentials_file?
|
523
|
-
|
640
|
+
@status.no_pin_creds
|
524
641
|
pinner.ask_credentials
|
525
|
-
|
642
|
+
@status.pin_creds_saved
|
526
643
|
end
|
527
644
|
credentials = pinner.load_credentials
|
528
645
|
maker = Struct.new(:username, :password, :url, :tags, :text, :description)
|
529
646
|
bookmark = maker.new(credentials[0], credentials[1], resp['canonical_url'], usertags.join(","), post_text, links[0])
|
530
|
-
|
647
|
+
@status.saving_pin
|
531
648
|
pinner.pin(bookmark)
|
532
|
-
|
649
|
+
@status.done
|
533
650
|
rescue => e
|
534
651
|
Errors.global_error({error: e, caller: caller, data: [post_id, usertags]})
|
535
652
|
end
|
@@ -538,7 +655,7 @@ module Ayadn
|
|
538
655
|
def auto(options)
|
539
656
|
begin
|
540
657
|
@view.clear_screen
|
541
|
-
|
658
|
+
@status.auto
|
542
659
|
Post.new.auto_readline
|
543
660
|
rescue => e
|
544
661
|
Errors.global_error({error: e, caller: caller, data: [options]})
|
@@ -547,14 +664,17 @@ module Ayadn
|
|
547
664
|
|
548
665
|
def post(args, options)
|
549
666
|
begin
|
667
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
550
668
|
writer = Post.new
|
551
|
-
@view.clear_screen
|
552
|
-
puts Status.posting
|
553
669
|
if options[:poster] # Returns the same options hash + poster embed
|
554
670
|
settings = options.dup
|
555
671
|
options = NowWatching.new.get_poster(settings[:poster], settings)
|
556
672
|
end
|
557
|
-
|
673
|
+
text = args.join(" ")
|
674
|
+
writer.post_size_error(text) if writer.post_size_ok?(text) == false
|
675
|
+
@view.clear_screen
|
676
|
+
@status.posting
|
677
|
+
resp = writer.post({options: options, text: text})
|
558
678
|
save_and_view(resp)
|
559
679
|
rescue => e
|
560
680
|
Errors.global_error({error: e, caller: caller, data: [args, options]})
|
@@ -563,14 +683,15 @@ module Ayadn
|
|
563
683
|
|
564
684
|
def write(options)
|
565
685
|
begin
|
686
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
566
687
|
writer = Post.new
|
567
|
-
|
568
|
-
|
688
|
+
@status.writing
|
689
|
+
@status.post
|
569
690
|
lines_array = writer.compose
|
570
|
-
writer.check_post_length(lines_array)
|
571
691
|
text = lines_array.join("\n")
|
692
|
+
writer.post_size_error(text) if writer.post_size_ok?(text) == false
|
572
693
|
@view.clear_screen
|
573
|
-
|
694
|
+
@status.posting
|
574
695
|
if options[:poster]
|
575
696
|
settings = options.dup
|
576
697
|
options = NowWatching.new.get_poster(settings[:poster], settings)
|
@@ -584,29 +705,30 @@ module Ayadn
|
|
584
705
|
|
585
706
|
def pmess(username, options = {})
|
586
707
|
begin
|
708
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
587
709
|
if options[:silent]
|
588
|
-
Settings.options[:marker][:
|
710
|
+
Settings.options[:marker][:messages] = false
|
589
711
|
end
|
590
|
-
|
712
|
+
@check.no_username(username)
|
591
713
|
username = [@workers.add_arobase(username)]
|
592
714
|
writer = Post.new
|
593
|
-
|
594
|
-
|
715
|
+
@status.message_from(username)
|
716
|
+
@status.message
|
595
717
|
lines_array = writer.compose
|
596
|
-
writer.check_message_length(lines_array)
|
597
718
|
text = lines_array.join("\n")
|
719
|
+
writer.message_size_error(text) if writer.message_size_ok?(text) == false
|
598
720
|
@view.clear_screen
|
599
|
-
|
721
|
+
@status.posting
|
600
722
|
if options[:poster]
|
601
723
|
settings = options.dup
|
602
724
|
options = NowWatching.new.get_poster(settings[:poster], settings)
|
603
725
|
end
|
604
726
|
resp = writer.pm({options: options, text: text, username: username})
|
605
|
-
if Settings.options[:marker][:
|
727
|
+
if Settings.options[:marker][:messages] == true
|
606
728
|
if resp['meta']['code'] == 200
|
607
729
|
data = resp['data']
|
608
730
|
name = "channel:#{data['channel_id']}"
|
609
|
-
Databases.
|
731
|
+
Databases.pagination_insert(name, data['id'])
|
610
732
|
marked = @api.update_marker(name, data['id'])
|
611
733
|
updated = JSON.parse(marked)
|
612
734
|
if updated['meta']['code'] != 200
|
@@ -614,9 +736,9 @@ module Ayadn
|
|
614
736
|
end
|
615
737
|
end
|
616
738
|
end
|
617
|
-
FileOps.save_message(resp) if Settings.options[:backup][:
|
739
|
+
FileOps.save_message(resp) if Settings.options[:backup][:messages]
|
618
740
|
@view.clear_screen
|
619
|
-
|
741
|
+
@status.yourmessage(username[0])
|
620
742
|
@view.show_posted(resp)
|
621
743
|
rescue => e
|
622
744
|
Errors.global_error({error: e, caller: caller, data: [username, options]})
|
@@ -625,34 +747,40 @@ module Ayadn
|
|
625
747
|
|
626
748
|
def reply(post_id, options = {})
|
627
749
|
begin
|
628
|
-
|
629
|
-
|
750
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
751
|
+
@check.bad_post_id(post_id)
|
752
|
+
if options[:force]
|
753
|
+
Settings.global[:force] = true
|
754
|
+
else
|
755
|
+
post_id = @workers.get_real_post_id(post_id)
|
756
|
+
end
|
757
|
+
@status.replying_to(post_id)
|
630
758
|
replied_to = @api.get_details(post_id)
|
631
|
-
|
759
|
+
@check.no_post(replied_to, post_id)
|
632
760
|
unless options[:noredirect]
|
633
761
|
post_id = @workers.get_original_id(post_id, replied_to)
|
634
762
|
end
|
635
763
|
if replied_to['data']['repost_of']
|
636
764
|
if post_id == replied_to['data']['repost_of']['id']
|
637
765
|
replied_to = @api.get_details(post_id)
|
638
|
-
|
766
|
+
@check.no_post(replied_to, post_id)
|
639
767
|
end
|
640
768
|
end
|
641
769
|
# ----
|
642
770
|
writer = Post.new
|
643
|
-
|
644
|
-
|
771
|
+
@status.writing
|
772
|
+
@status.reply
|
645
773
|
lines_array = writer.compose
|
646
|
-
writer.check_post_length(lines_array)
|
647
|
-
@view.clear_screen
|
648
774
|
text = lines_array.join("\n")
|
775
|
+
# text length is tested in Post class for the reply command
|
776
|
+
@view.clear_screen
|
649
777
|
replied_to = @workers.build_posts([replied_to['data']])
|
650
778
|
if options[:poster]
|
651
779
|
settings = options.dup
|
652
780
|
options = NowWatching.new.get_poster(settings[:poster], settings)
|
653
781
|
end
|
654
782
|
resp = writer.reply({options: options, text: text, id: post_id, reply_to: replied_to})
|
655
|
-
FileOps.save_post(resp) if Settings.options[:backup][:
|
783
|
+
FileOps.save_post(resp) if Settings.options[:backup][:posts]
|
656
784
|
# ----
|
657
785
|
options = options.dup
|
658
786
|
unless resp['data']['reply_to'].nil?
|
@@ -660,6 +788,7 @@ module Ayadn
|
|
660
788
|
end
|
661
789
|
options[:post_id] = resp['data']['id'].to_i
|
662
790
|
@view.render(@api.get_convo(post_id), options)
|
791
|
+
puts "\n" if Settings.options[:timeline][:compact] == true && !options[:raw]
|
663
792
|
rescue => e
|
664
793
|
Errors.global_error({error: e, caller: caller, data: [post_id, options]})
|
665
794
|
end
|
@@ -667,27 +796,29 @@ module Ayadn
|
|
667
796
|
|
668
797
|
def send_to_channel(channel_id, options = {})
|
669
798
|
begin
|
799
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
670
800
|
if options[:silent]
|
671
|
-
Settings.options[:marker][:
|
801
|
+
Settings.options[:marker][:messages] = false
|
672
802
|
end
|
673
803
|
channel_id = @workers.get_channel_id_from_alias(channel_id)
|
674
804
|
writer = Post.new
|
675
|
-
|
676
|
-
|
805
|
+
@status.writing
|
806
|
+
@status.message
|
677
807
|
lines_array = writer.compose
|
678
|
-
|
808
|
+
text = lines_array.join("\n")
|
809
|
+
writer.message_size_error(text) if writer.message_size_ok?(text) == false
|
679
810
|
@view.clear_screen
|
680
|
-
|
811
|
+
@status.posting
|
681
812
|
if options[:poster]
|
682
813
|
settings = options.dup
|
683
814
|
options = NowWatching.new.get_poster(settings[:poster], settings)
|
684
815
|
end
|
685
|
-
resp = writer.message({options: options, id: channel_id, text:
|
686
|
-
if Settings.options[:marker][:
|
816
|
+
resp = writer.message({options: options, id: channel_id, text: text})
|
817
|
+
if Settings.options[:marker][:messages] == true
|
687
818
|
if resp['meta']['code'] == 200
|
688
819
|
data = resp['data']
|
689
820
|
name = "channel:#{data['channel_id']}"
|
690
|
-
Databases.
|
821
|
+
Databases.pagination_insert(name, data['id'])
|
691
822
|
marked = @api.update_marker(name, data['id'])
|
692
823
|
updated = JSON.parse(marked)
|
693
824
|
if updated['meta']['code'] != 200
|
@@ -695,9 +826,9 @@ module Ayadn
|
|
695
826
|
end
|
696
827
|
end
|
697
828
|
end
|
698
|
-
FileOps.save_message(resp) if Settings.options[:backup][:
|
829
|
+
FileOps.save_message(resp) if Settings.options[:backup][:messages]
|
699
830
|
@view.clear_screen
|
700
|
-
|
831
|
+
@status.yourpost
|
701
832
|
@view.show_posted(resp)
|
702
833
|
rescue => e
|
703
834
|
Errors.global_error({error: e, caller: caller, data: [channel_id, options]})
|
@@ -705,26 +836,35 @@ module Ayadn
|
|
705
836
|
end
|
706
837
|
|
707
838
|
def nowplaying(options = {})
|
708
|
-
|
839
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
840
|
+
np = NowPlaying.new(@api, @view, @workers, options)
|
709
841
|
options[:lastfm] ? np.lastfm(options) : np.itunes(options)
|
710
842
|
end
|
711
843
|
|
712
844
|
def nowwatching(args, options = {})
|
713
845
|
begin
|
714
|
-
|
846
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
847
|
+
if args.empty?
|
848
|
+
@status.error_missing_title
|
849
|
+
exit
|
850
|
+
end
|
715
851
|
nw = NowWatching.new(@view)
|
716
852
|
nw.post(args, options)
|
717
853
|
rescue ArgumentError => e
|
718
|
-
|
854
|
+
@status.no_movie
|
719
855
|
rescue => e
|
720
|
-
|
856
|
+
@status.wtf
|
721
857
|
Errors.global_error({error: e, caller: caller, data: [args, options]})
|
722
858
|
end
|
723
859
|
end
|
724
860
|
|
725
861
|
def tvshow(args, options = {})
|
726
862
|
begin
|
727
|
-
|
863
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
864
|
+
if args.empty?
|
865
|
+
@status.error_missing_title
|
866
|
+
exit
|
867
|
+
end
|
728
868
|
client = TvShow.new
|
729
869
|
show_obj = if options[:alt]
|
730
870
|
client.find_alt(args.join(' '))
|
@@ -734,14 +874,16 @@ module Ayadn
|
|
734
874
|
candidate = client.create_details(show_obj)
|
735
875
|
candidate.ok ? candidate.post(options) : candidate.cancel
|
736
876
|
rescue => e
|
737
|
-
|
877
|
+
@status.wtf
|
738
878
|
Errors.global_error({error: e, caller: caller, data: [args, options]})
|
739
879
|
end
|
740
880
|
end
|
741
881
|
|
742
882
|
def random_posts(options)
|
743
883
|
begin
|
744
|
-
|
884
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
885
|
+
stream = Stream.new(@api, @view, @workers)
|
886
|
+
stream.random_posts(options)
|
745
887
|
rescue => e
|
746
888
|
Errors.global_error({error: e, caller: caller, data: [@max_id, @random_post_id, @resp, options]})
|
747
889
|
end
|
@@ -749,11 +891,7 @@ module Ayadn
|
|
749
891
|
|
750
892
|
def version
|
751
893
|
begin
|
752
|
-
|
753
|
-
puts "Version:\t".color(:cyan) + "#{VERSION}\n".color(:green)
|
754
|
-
puts "Changelog:\t".color(:cyan) + "https://github.com/ericdke/na/blob/master/CHANGELOG.md\n".color(Settings.options[:colors][:link])
|
755
|
-
puts "Docs:\t\t".color(:cyan) + "https://github.com/ericdke/na/tree/master/doc".color(Settings.options[:colors][:link])
|
756
|
-
puts "\n"
|
894
|
+
@status.version
|
757
895
|
rescue => e
|
758
896
|
Errors.global_error({error: e, caller: caller, data: []})
|
759
897
|
end
|
@@ -762,9 +900,10 @@ module Ayadn
|
|
762
900
|
private
|
763
901
|
|
764
902
|
def save_and_view(resp)
|
765
|
-
FileOps.save_post(resp) if Settings.options[:backup][:
|
903
|
+
FileOps.save_post(resp) if Settings.options[:backup][:posts]
|
766
904
|
@view.clear_screen
|
767
|
-
|
905
|
+
@status.yourpost
|
906
|
+
puts "\n\n"
|
768
907
|
@view.show_posted(resp)
|
769
908
|
end
|
770
909
|
|