ayadn 3.0 → 4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -4
- data/CHANGELOG.md +12 -4
- data/README.md +2 -5
- data/ayadn.gemspec +0 -2
- data/doc/01-index.md +0 -3
- data/doc/02-install.md +0 -4
- data/doc/06-post.md +0 -16
- data/doc/{18-contact.md → 16-contact.md} +0 -0
- data/doc/{19-examples.md → 17-examples.md} +0 -0
- data/doc/18-develop.md +165 -0
- data/lib/ayadn/action.rb +206 -396
- data/lib/ayadn/alias.rb +1 -1
- data/lib/ayadn/annotations.rb +15 -27
- data/lib/ayadn/api.rb +39 -28
- data/lib/ayadn/app.rb +19 -29
- data/lib/ayadn/authorize.rb +22 -13
- data/lib/ayadn/blacklist.rb +6 -19
- data/lib/ayadn/channel_object.rb +75 -0
- data/lib/ayadn/check.rb +19 -11
- data/lib/ayadn/cnx.rb +9 -15
- data/lib/ayadn/databases.rb +15 -27
- data/lib/ayadn/debug.rb +9 -9
- data/lib/ayadn/descriptions.rb +1 -99
- data/lib/ayadn/diagnostics.rb +16 -15
- data/lib/ayadn/endpoints.rb +18 -22
- data/lib/ayadn/errors.rb +1 -1
- data/lib/ayadn/fileops.rb +12 -12
- data/lib/ayadn/filtered_post_object.rb +11 -0
- data/lib/ayadn/ids.rb +0 -3
- data/lib/ayadn/logs.rb +4 -4
- data/lib/ayadn/mark.rb +34 -30
- data/lib/ayadn/nicerank.rb +7 -7
- data/lib/ayadn/nowplaying.rb +8 -22
- data/lib/ayadn/pinboard.rb +8 -12
- data/lib/ayadn/post.rb +18 -18
- data/lib/ayadn/post_object.rb +118 -0
- data/lib/ayadn/preferences_object.rb +290 -0
- data/lib/ayadn/profile.rb +2 -2
- data/lib/ayadn/scroll.rb +58 -67
- data/lib/ayadn/search.rb +22 -15
- data/lib/ayadn/set.rb +93 -83
- data/lib/ayadn/settings.rb +25 -33
- data/lib/ayadn/status.rb +24 -26
- data/lib/ayadn/stream.rb +68 -66
- data/lib/ayadn/stream_object.rb +56 -0
- data/lib/ayadn/switch.rb +2 -2
- data/lib/ayadn/user_object.rb +116 -0
- data/lib/ayadn/version.rb +1 -1
- data/lib/ayadn/view.rb +255 -278
- data/lib/ayadn/workers.rb +172 -174
- data/spec/integration/action_spec.rb +55 -34
- data/spec/mock/ayadn.sqlite +0 -0
- data/spec/unit/annotations_spec.rb +54 -41
- data/spec/unit/api_spec.rb +78 -7
- data/spec/unit/blacklistworkers_spec.rb +92 -20
- data/spec/unit/databases_spec.rb +117 -36
- data/spec/unit/endpoints_spec.rb +82 -10
- data/spec/unit/nicerank_spec.rb +56 -27
- data/spec/unit/post_spec.rb +94 -21
- data/spec/unit/set_spec.rb +141 -210
- data/spec/unit/view_spec.rb +105 -32
- data/spec/unit/workers_spec.rb +143 -52
- metadata +12 -37
- data/doc/16-movie.md +0 -39
- data/doc/17-tvshow.md +0 -46
- data/lib/ayadn/nowwatching.rb +0 -118
- data/lib/ayadn/tvshow.rb +0 -162
data/lib/ayadn/alias.rb
CHANGED
@@ -53,7 +53,7 @@ module Ayadn
|
|
53
53
|
def list
|
54
54
|
begin
|
55
55
|
init
|
56
|
-
Settings.options
|
56
|
+
Settings.options.timeline.compact = true if options[:compact]
|
57
57
|
list = Databases.all_aliases
|
58
58
|
unless list.empty? || list.nil?
|
59
59
|
if options[:raw]
|
data/lib/ayadn/annotations.rb
CHANGED
@@ -4,8 +4,12 @@ module Ayadn
|
|
4
4
|
|
5
5
|
class Annotations
|
6
6
|
|
7
|
+
###
|
8
|
+
# This class contains the "annotations" (metadata) templates for posting to ADN
|
9
|
+
|
7
10
|
attr_accessor :content
|
8
11
|
|
12
|
+
# Creates basic annotations and optionally adds necessary ones
|
9
13
|
def initialize(dic)
|
10
14
|
dic[:options] = {} if dic[:options].nil?
|
11
15
|
@content = base()
|
@@ -13,23 +17,23 @@ module Ayadn
|
|
13
17
|
@content += youtube(dic) if dic[:options][:youtube]
|
14
18
|
@content += vimeo(dic) if dic[:options][:vimeo]
|
15
19
|
@content += nowplaying(dic) if dic[:options][:nowplaying]
|
16
|
-
@content += movie(dic) if dic[:options][:movie]
|
17
|
-
@content += tvshow(dic) if dic[:options][:tvshow]
|
18
20
|
end
|
19
21
|
|
20
22
|
def base
|
23
|
+
# Creates basic post metadata
|
24
|
+
# Both types are custom types for Ayadn (all types beginning with "com.ayadn" are custom types)
|
21
25
|
[
|
22
26
|
{
|
23
27
|
"type" => "com.ayadn.user",
|
24
28
|
"value" => {
|
25
29
|
"+net.app.core.user" => {
|
26
|
-
"user_id" => Settings.config
|
30
|
+
"user_id" => Settings.config.identity.handle,
|
27
31
|
"format" => "basic"
|
28
32
|
},
|
29
33
|
"env" => {
|
30
|
-
"platform" => Settings.config
|
31
|
-
"ruby" => Settings.config
|
32
|
-
"locale" => Settings.config
|
34
|
+
"platform" => Settings.config.platform,
|
35
|
+
"ruby" => Settings.config.ruby,
|
36
|
+
"locale" => Settings.config.locale
|
33
37
|
}
|
34
38
|
}
|
35
39
|
},
|
@@ -43,13 +47,14 @@ module Ayadn
|
|
43
47
|
"id" => "69904",
|
44
48
|
"email" => "eric@aya.io"
|
45
49
|
},
|
46
|
-
"version" => Settings.config
|
50
|
+
"version" => Settings.config.version
|
47
51
|
}
|
48
52
|
}
|
49
53
|
]
|
50
54
|
end
|
51
55
|
|
52
56
|
def files(dic)
|
57
|
+
# Creates "oembed" metadata for uploaded files
|
53
58
|
files = FileOps.make_paths(dic[:options][:embed])
|
54
59
|
data = FileOps.upload_files(files)
|
55
60
|
data.map do |obj|
|
@@ -67,6 +72,7 @@ module Ayadn
|
|
67
72
|
end
|
68
73
|
|
69
74
|
def youtube(dic)
|
75
|
+
# Fetch Youtube metadata for a video
|
70
76
|
dic['link'] = dic[:options][:youtube][0]
|
71
77
|
req_url = "http://www.youtube.com/oembed?url=#{dic['link']}&format=json"
|
72
78
|
resp = CNX.download(req_url)
|
@@ -84,6 +90,8 @@ module Ayadn
|
|
84
90
|
Errors.global_error({error: e, caller: caller, data: [resp, dic]})
|
85
91
|
end
|
86
92
|
|
93
|
+
# Adds Youtube oembed metadata to the existing metadata
|
94
|
+
# Also adds a custom type for Ayadn
|
87
95
|
dic.merge!(decoded)
|
88
96
|
[{
|
89
97
|
"type" => "net.app.core.oembed",
|
@@ -152,26 +160,6 @@ module Ayadn
|
|
152
160
|
}]
|
153
161
|
end
|
154
162
|
|
155
|
-
def movie(dic)
|
156
|
-
[{
|
157
|
-
"type" => "com.ayadn.movie",
|
158
|
-
"value" => {
|
159
|
-
"title" => dic[:title],
|
160
|
-
"source" => dic[:source]
|
161
|
-
}
|
162
|
-
}]
|
163
|
-
end
|
164
|
-
|
165
|
-
def tvshow(dic)
|
166
|
-
[{
|
167
|
-
"type" => "com.ayadn.tvshow",
|
168
|
-
"value" => {
|
169
|
-
"title" => dic[:title],
|
170
|
-
"source" => dic[:source]
|
171
|
-
}
|
172
|
-
}]
|
173
|
-
end
|
174
|
-
|
175
163
|
def nowplaying_silent(dic)
|
176
164
|
[{
|
177
165
|
"type" => "com.ayadn.nowplaying",
|
data/lib/ayadn/api.rb
CHANGED
@@ -2,14 +2,13 @@
|
|
2
2
|
module Ayadn
|
3
3
|
class API
|
4
4
|
|
5
|
-
def initialize
|
6
|
-
@workers = Workers.new
|
7
|
-
@status = Status.new
|
8
|
-
end
|
9
|
-
|
10
5
|
def get_unified(options)
|
6
|
+
# "paginate" fetches last post ID we've seen if the user asks for scrolling or asks to see new posts only
|
11
7
|
options = paginate options, 'unified'
|
12
|
-
|
8
|
+
# Create the API endpoint URL
|
9
|
+
endpoint = Endpoints.new.unified(options)
|
10
|
+
# Fetch the response from the ADN servers
|
11
|
+
get_parsed_response(endpoint)
|
13
12
|
end
|
14
13
|
|
15
14
|
def get_checkins(options)
|
@@ -111,6 +110,7 @@ module Ayadn
|
|
111
110
|
build_list(username, :followers)
|
112
111
|
end
|
113
112
|
|
113
|
+
# "nil" as a first argument? the other method should be refactored
|
114
114
|
def get_muted
|
115
115
|
build_list(nil, :muted)
|
116
116
|
end
|
@@ -121,14 +121,16 @@ module Ayadn
|
|
121
121
|
|
122
122
|
def get_raw_list(username, target)
|
123
123
|
options = {:count => 200, :before_id => nil}
|
124
|
-
|
124
|
+
bucket = []
|
125
|
+
# Fetch new items until the API says no more
|
126
|
+
# This is chronologically reversed: start with current id, get 200 posts, get the post id we're at, then 200 again, etc
|
125
127
|
loop do
|
126
128
|
resp = get_parsed_response(get_list_url(username, target, options))
|
127
|
-
|
129
|
+
bucket << resp
|
128
130
|
break if resp['meta']['min_id'] == nil || resp['meta']['more'] == false
|
129
131
|
options = {:count => 200, :before_id => resp['meta']['min_id']}
|
130
132
|
end
|
131
|
-
|
133
|
+
bucket
|
132
134
|
end
|
133
135
|
|
134
136
|
def get_user(username)
|
@@ -150,8 +152,9 @@ module Ayadn
|
|
150
152
|
resp['data'].each { |p| array_of_hashes << p }
|
151
153
|
else
|
152
154
|
options = {:count => 200, :before_id => nil}
|
155
|
+
endpoints = Endpoints.new
|
153
156
|
loop do
|
154
|
-
resp = get_parsed_response(
|
157
|
+
resp = get_parsed_response(endpoints.files_list(options))
|
155
158
|
resp['data'].each { |p| array_of_hashes << p }
|
156
159
|
break unless resp['meta']['more']
|
157
160
|
options = {:count => 200, :before_id => resp['meta']['min_id']}
|
@@ -220,15 +223,6 @@ module Ayadn
|
|
220
223
|
def get_channels
|
221
224
|
options = {:count => 200, :recent_message => 1, :annotations => 1, :before_id => nil}
|
222
225
|
get_parsed_response(Endpoints.new.channels(options))
|
223
|
-
# big = []
|
224
|
-
# loop do
|
225
|
-
# resp = get_parsed_response(Endpoints.new.channels(options))
|
226
|
-
# #check_response_meta_code(resp)
|
227
|
-
# big << resp
|
228
|
-
# break if resp['meta']['more'] == false
|
229
|
-
# options = {:count => 200, :before_id => resp['meta']['min_id']}
|
230
|
-
# end
|
231
|
-
# big
|
232
226
|
end
|
233
227
|
|
234
228
|
def get_channel channel_id, options = {}
|
@@ -263,22 +257,33 @@ module Ayadn
|
|
263
257
|
end
|
264
258
|
|
265
259
|
def self.build_query(arg)
|
260
|
+
# Number of posts/messages to fetch.
|
261
|
+
# Either from CLI and integer
|
262
|
+
# or from the settings
|
266
263
|
if arg[:count].to_s.is_integer?
|
267
264
|
count = arg[:count]
|
268
265
|
else
|
269
|
-
count = Settings.options
|
266
|
+
count = Settings.options.counts.default
|
270
267
|
end
|
271
|
-
|
268
|
+
# Do we want the "directed posts"?
|
269
|
+
# Either from CLI (optional)
|
270
|
+
# or from the settings
|
271
|
+
directed = arg[:directed] || Settings.options.timeline.directed
|
272
|
+
# because I was not always consistent in the legacy code base, let's be cautious
|
272
273
|
if directed == true || directed == 1
|
273
274
|
directed = 1
|
274
275
|
else
|
275
276
|
directed = 0
|
276
277
|
end
|
278
|
+
# We *never* want the HTML in the response, we are a CLI client
|
277
279
|
html = 0
|
280
|
+
# If the user asks to see posts starting with a specific post ID
|
278
281
|
if arg[:since_id]
|
279
282
|
"&count=#{count}&include_html=#{html}&include_directed_posts=#{directed}&include_deleted=0&include_annotations=1&since_id=#{arg[:since_id]}"
|
283
|
+
# Or asks to see their recent messages
|
280
284
|
elsif arg[:recent_message]
|
281
285
|
"&count=#{count}&include_html=#{html}&include_directed_posts=#{directed}&include_deleted=0&include_annotations=1&include_recent_message=#{arg[:recent_message]}"
|
286
|
+
# Else we create a normal request URL
|
282
287
|
else
|
283
288
|
"&count=#{count}&include_html=#{html}&include_directed_posts=#{directed}&include_deleted=0&include_annotations=1"
|
284
289
|
end
|
@@ -294,24 +299,28 @@ module Ayadn
|
|
294
299
|
end
|
295
300
|
|
296
301
|
def get_parsed_response(url)
|
302
|
+
# Bool for retry if failure
|
297
303
|
working = true
|
298
304
|
begin
|
305
|
+
# Get the response from the API and decode the JSON
|
299
306
|
resp = JSON.parse(CNX.get_response_from(url))
|
300
307
|
return resp
|
301
308
|
rescue JSON::ParserError => e
|
302
|
-
if
|
309
|
+
# Retry once after 10 seconds if the response wasn't valid
|
310
|
+
status = Status.new
|
311
|
+
if working
|
303
312
|
working = false
|
304
|
-
|
313
|
+
status.server_error(true)
|
305
314
|
begin
|
306
315
|
sleep 10
|
307
316
|
rescue Interrupt
|
308
|
-
|
317
|
+
status.canceled
|
309
318
|
exit
|
310
319
|
end
|
311
|
-
|
320
|
+
View.new.clear_screen
|
312
321
|
retry
|
313
322
|
else
|
314
|
-
|
323
|
+
status.server_error(false)
|
315
324
|
Errors.global_error({error: e, caller: caller, data: [resp]})
|
316
325
|
end
|
317
326
|
end
|
@@ -326,15 +335,17 @@ module Ayadn
|
|
326
335
|
end
|
327
336
|
|
328
337
|
def build_list(username, target)
|
338
|
+
# Fetch data for each user (and verify the user isn't deleted)
|
329
339
|
options = {:count => 200, :before_id => nil}
|
330
340
|
big_hash = {}
|
341
|
+
workers= Workers.new
|
331
342
|
loop do
|
332
343
|
resp = get_parsed_response(get_list_url(username, target, options))
|
333
344
|
if resp['meta']['code'] == 404
|
334
|
-
|
345
|
+
Status.new.user_404(username)
|
335
346
|
exit
|
336
347
|
end
|
337
|
-
users =
|
348
|
+
users = workers.extract_users(resp)
|
338
349
|
big_hash.merge!(users)
|
339
350
|
break if resp['meta']['min_id'] == nil
|
340
351
|
options = {:count => 200, :before_id => resp['meta']['min_id']}
|
data/lib/ayadn/app.rb
CHANGED
@@ -4,19 +4,32 @@ module Ayadn
|
|
4
4
|
package_name "Ayadn"
|
5
5
|
|
6
6
|
begin
|
7
|
-
%w{action api descriptions endpoints cnx view workers settings post status extend databases fileops logs set alias errors blacklist mark nicerank debug check diagnostics}.each { |r| require_relative "#{r}" }
|
7
|
+
%w{action api descriptions endpoints cnx view workers settings post status extend databases fileops logs set alias errors blacklist mark nicerank debug check diagnostics stream_object post_object user_object channel_object preferences_object filtered_post_object}.each { |r| require_relative "#{r}" }
|
8
8
|
rescue Interrupt
|
9
9
|
puts "\nExit: stopped by user while launching\n\n"
|
10
10
|
exit
|
11
11
|
end
|
12
12
|
|
13
|
+
|
13
14
|
##
|
14
15
|
# These methods are intended to be called from the CLI.
|
16
|
+
# This is managed by the Thor gem.
|
17
|
+
#
|
18
|
+
|
15
19
|
|
20
|
+
# "desc" (from Thor) describes what the following method does
|
16
21
|
desc "timeline", "Show your App.net timeline, aka the Unified Stream (-tl)"
|
22
|
+
# "map" (from Thor) creates an alias for the command
|
23
|
+
# This one is officially "timeline" but also accepts "unified"
|
17
24
|
map "unified" => :timeline
|
25
|
+
# "map" (from Thor) is also used to create the command shortcut(s)
|
18
26
|
map "-tl" => :timeline
|
27
|
+
# "long_desc" (from Thor) is an optional long description for the method (is displayed in the Help)
|
19
28
|
long_desc Descriptions.unified
|
29
|
+
# "option" (from Thor) creates an available option for the command
|
30
|
+
# The option name, a symbol, is automatically stringified by Thor
|
31
|
+
# - "aliases" optionally creates the option shortcut
|
32
|
+
# - "type" is the type of argument the user can pass to the option: a bool, an array, a number, etc (string by default)
|
20
33
|
option :scroll, aliases: "-s", type: :boolean, desc: "Scroll the stream"
|
21
34
|
option :new, aliases: "-n", type: :boolean, desc: Descriptions.options_new
|
22
35
|
option :count, aliases: "-c", type: :numeric, desc: Descriptions.options_count
|
@@ -25,6 +38,7 @@ module Ayadn
|
|
25
38
|
option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
|
26
39
|
option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already"
|
27
40
|
def timeline
|
41
|
+
# "options" (the CLI arguments) is a hash automatically generated by Thor
|
28
42
|
Action.new.unified(options)
|
29
43
|
end
|
30
44
|
|
@@ -107,6 +121,8 @@ module Ayadn
|
|
107
121
|
option :raw, aliases: "-x", type: :boolean, desc: Descriptions.options_raw
|
108
122
|
option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
|
109
123
|
option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already"
|
124
|
+
# The method parameter is the CLI argument
|
125
|
+
# Here it has a star meaning it will always be an array
|
110
126
|
def mentions(*username)
|
111
127
|
Action.new.mentions(username, options)
|
112
128
|
end
|
@@ -155,6 +171,7 @@ module Ayadn
|
|
155
171
|
option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already"
|
156
172
|
option :cache, type: :boolean, desc: "Cache the results"
|
157
173
|
option :again, type: :boolean, desc: "Run the last request from cache"
|
174
|
+
# The argument has no star, it will be a string (by default)
|
158
175
|
def whoreposted(post_id)
|
159
176
|
Action.new.whoreposted(post_id, options)
|
160
177
|
end
|
@@ -468,7 +485,6 @@ module Ayadn
|
|
468
485
|
option :embed, aliases: "-E", type: :array, desc: "Embed one or several pictures in the new post"
|
469
486
|
option :youtube, aliases: "-Y", type: :array, desc: "Embed a Youtube video in the new post"
|
470
487
|
option :vimeo, aliases: "-V", type: :array, desc: "Embed a Vimeo video in the new post"
|
471
|
-
option :poster, aliases: "-M", type: :array, desc: "Embed a movie poster, from title, in the new post"
|
472
488
|
option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)"
|
473
489
|
def post(*args)
|
474
490
|
Action.new.post(args, options)
|
@@ -481,7 +497,6 @@ module Ayadn
|
|
481
497
|
option :embed, aliases: "-E", type: :array, desc: "Embed one or several pictures in the new post"
|
482
498
|
option :youtube, aliases: "-Y", type: :array, desc: "Embed a Youtube video in the new post"
|
483
499
|
option :vimeo, aliases: "-V", type: :array, desc: "Embed a Vimeo video in the new post"
|
484
|
-
option :poster, aliases: "-M", type: :array, desc: "Embed a movie poster, from title, in the new post"
|
485
500
|
option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)"
|
486
501
|
def write
|
487
502
|
Action.new.write(options)
|
@@ -492,7 +507,6 @@ module Ayadn
|
|
492
507
|
option :embed, aliases: "-E", type: :array, desc: "Embed one or several pictures in the new message"
|
493
508
|
option :youtube, aliases: "-Y", type: :array, desc: "Embed a Youtube video in the new message"
|
494
509
|
option :vimeo, aliases: "-V", type: :array, desc: "Embed a Vimeo video in the new message"
|
495
|
-
option :poster, aliases: "-M", type: :array, desc: "Embed a movie poster, from title, in the new message"
|
496
510
|
option :silent, aliases: "-z", type: :boolean, desc: "Do not mark the channel as read"
|
497
511
|
option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)"
|
498
512
|
def pm(*username)
|
@@ -505,7 +519,6 @@ module Ayadn
|
|
505
519
|
option :embed, aliases: "-E", type: :array, desc: "Embed one or several pictures in the new message"
|
506
520
|
option :youtube, aliases: "-Y", type: :array, desc: "Embed a Youtube video in the new message"
|
507
521
|
option :vimeo, aliases: "-V", type: :array, desc: "Embed a Vimeo video in the new message"
|
508
|
-
option :poster, aliases: "-M", type: :array, desc: "Embed a movie poster, from title, in the new message"
|
509
522
|
option :silent, aliases: "-z", type: :boolean, desc: "Do not mark the channel as read"
|
510
523
|
option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)"
|
511
524
|
def send_to_channel(channel_id)
|
@@ -518,7 +531,6 @@ module Ayadn
|
|
518
531
|
option :embed, aliases: "-E", type: :array, desc: "Embed one or several pictures in the new post"
|
519
532
|
option :youtube, aliases: "-Y", type: :array, desc: "Embed a Youtube video in the new post"
|
520
533
|
option :vimeo, aliases: "-V", type: :array, desc: "Embed a Vimeo video in the new post"
|
521
|
-
option :poster, aliases: "-M", type: :array, desc: "Embed a movie poster, from title, in the new post"
|
522
534
|
option :noredirect, aliases: "-n", type: :boolean, desc: "Do not respond to the original post but to the reposted one if possible"
|
523
535
|
option :force, aliases: "-f", type: :boolean, desc: Descriptions.options_force
|
524
536
|
option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)"
|
@@ -535,6 +547,7 @@ module Ayadn
|
|
535
547
|
|
536
548
|
desc "set TYPE PARAM VALUE", "Set/configure a parameter and save it"
|
537
549
|
long_desc Descriptions.set
|
550
|
+
# "subcommand" (from Thor) aliases the command to another command in the defined Thor class (here the CLI command "set" is aliased to the "set" command in the "Set" Thor class)
|
538
551
|
subcommand "set", Set
|
539
552
|
|
540
553
|
desc "alias COMMAND (PARAM)", "Create/delete/list aliases for channels (-A)"
|
@@ -574,29 +587,6 @@ module Ayadn
|
|
574
587
|
Action.new.nowplaying(options)
|
575
588
|
end
|
576
589
|
|
577
|
-
desc "movie TITLE", "Create a post from a movie title (-NW)"
|
578
|
-
map "nowwatching" => :movie
|
579
|
-
map "imdb" => :movie
|
580
|
-
map "-NW" => :movie
|
581
|
-
long_desc Descriptions.nowwatching
|
582
|
-
option :alt, aliases: "-a", type: :boolean, desc: "Select an alternative response if the first didn't match"
|
583
|
-
option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)"
|
584
|
-
def movie(*title)
|
585
|
-
require_relative("nowwatching")
|
586
|
-
Action.new.nowwatching(title, options)
|
587
|
-
end
|
588
|
-
|
589
|
-
desc "tvshow TITLE", "Create a post from a TV show title (-TV)"
|
590
|
-
map "-TV" => :tvshow
|
591
|
-
long_desc Descriptions.tvshow
|
592
|
-
option :alt, aliases: "-a", type: :boolean, desc: "Select an alternative response if the first didn't match"
|
593
|
-
option :banner, aliases: "-b", type: :boolean, desc: "Inserts the show banner instead of the show poster"
|
594
|
-
option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already (after posting)"
|
595
|
-
def tvshow(*title)
|
596
|
-
require_relative("tvshow")
|
597
|
-
Action.new.tvshow(title, options)
|
598
|
-
end
|
599
|
-
|
600
590
|
desc "random", "Show random posts from App.net (-rnd)"
|
601
591
|
map "-rnd" => :random
|
602
592
|
option :wait, aliases: "-w", type: :numeric, desc: "In seconds, time to wait before next page"
|
data/lib/ayadn/authorize.rb
CHANGED
@@ -3,17 +3,18 @@ module Ayadn
|
|
3
3
|
class Authorize
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
@thor = Thor::Shell::Color.new # local statuses
|
7
6
|
@status = Status.new # global statuses + utils
|
8
7
|
@baseURL = "https://api.app.net" # may be overriden
|
9
8
|
end
|
10
9
|
|
11
10
|
def authorize(options)
|
12
11
|
puts "\n"
|
12
|
+
# /ayadn/accounts.db is the Ayadn 1.x deprecated database
|
13
13
|
if File.exist?(Dir.home + "/ayadn/accounts.db")
|
14
14
|
@status.deprecated_ayadn
|
15
15
|
exit
|
16
16
|
end
|
17
|
+
# default config for ADN API
|
17
18
|
api_file = Dir.home + "/ayadn/.api.yml"
|
18
19
|
# overrides the default value
|
19
20
|
if File.exist?(api_file)
|
@@ -25,12 +26,12 @@ module Ayadn
|
|
25
26
|
end
|
26
27
|
puts "\e[H\e[2J"
|
27
28
|
show_link
|
29
|
+
# get the auth token from CLI or ask user
|
28
30
|
token = if options["token"]
|
29
31
|
options["token"][0]
|
30
32
|
else
|
31
33
|
get_token
|
32
34
|
end
|
33
|
-
# token = get_token
|
34
35
|
check_token(token)
|
35
36
|
puts "\e[H\e[2J"
|
36
37
|
@status.say_yellow :connexion, "downloading user info"
|
@@ -43,32 +44,34 @@ module Ayadn
|
|
43
44
|
@status.say_green :done, "user #{user.handle} is authorized"
|
44
45
|
Errors.info "#{user.handle} authorized."
|
45
46
|
@status.say { @status.say_green :end, "Thank you for using Ayadn. Enjoy!" }
|
46
|
-
Switch.new.list
|
47
|
+
Switch.new(@status).list
|
47
48
|
end
|
48
49
|
|
49
50
|
def unauthorize(user, options)
|
50
51
|
begin
|
51
|
-
@workers = Workers.new
|
52
52
|
if user.size != 1
|
53
53
|
@status.one_username
|
54
54
|
exit
|
55
55
|
end
|
56
|
-
user =
|
56
|
+
user = Workers.new.remove_arobase_if_present(user)[0]
|
57
57
|
puts "\e[H\e[2J"
|
58
|
+
thor = Thor::Shell::Color.new
|
58
59
|
if options[:delete]
|
59
|
-
sure =
|
60
|
+
sure = thor.yes?("Are you sure you want to unauthorize user @#{user} and delete its folders? [y/N]\n\n> ", :red)
|
60
61
|
else
|
61
|
-
sure =
|
62
|
+
sure = thor.yes?("Are you sure you want to unauthorize user @#{user} ? [y/N]\n\n> ", :red)
|
62
63
|
end
|
63
|
-
unless sure
|
64
|
-
|
64
|
+
unless sure
|
65
|
+
@status.canceled
|
65
66
|
exit
|
66
67
|
end
|
67
68
|
puts "\e[H\e[2J"
|
68
69
|
@status.say_yellow :delete, "database entry for @#{user}"
|
69
|
-
|
70
|
+
# load the current accounts DB
|
70
71
|
db = Amalgalite::Database.new(Dir.home + "/ayadn/accounts.sqlite")
|
71
|
-
|
72
|
+
# remember who we are
|
73
|
+
active_user = Databases.all_accounts(db).select { |acc| acc[4] == 1 }[0][0]
|
74
|
+
# remove this user from DB
|
72
75
|
Databases.remove_from_accounts(db, user)
|
73
76
|
if options[:delete]
|
74
77
|
@status.say_yellow :delete, "@#{user} user folders"
|
@@ -79,7 +82,13 @@ module Ayadn
|
|
79
82
|
if remaining.flatten.empty?
|
80
83
|
@status.say_info "accounts database is now empty"
|
81
84
|
else
|
82
|
-
|
85
|
+
# are we still here?
|
86
|
+
if !remaining.select { |arr| arr[0] == active_user }.empty?
|
87
|
+
username = active_user
|
88
|
+
else
|
89
|
+
# just to avoid having Ayadn without any user logged in
|
90
|
+
username = remaining[0][0]
|
91
|
+
end
|
83
92
|
Databases.set_active_account(db, username)
|
84
93
|
@status.say_info "user @#{username} is now the active user"
|
85
94
|
end
|
@@ -88,7 +97,7 @@ module Ayadn
|
|
88
97
|
@status.not_authorized
|
89
98
|
exit
|
90
99
|
rescue Interrupt
|
91
|
-
|
100
|
+
@status.canceled
|
92
101
|
exit
|
93
102
|
end
|
94
103
|
end
|