ayadn 1.8.2 → 2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/authorize.rb
CHANGED
@@ -2,50 +2,95 @@
|
|
2
2
|
module Ayadn
|
3
3
|
class Authorize
|
4
4
|
|
5
|
+
def initialize
|
6
|
+
@thor = Thor::Shell::Color.new # local statuses
|
7
|
+
@status = Status.new # global statuses + utils
|
8
|
+
end
|
9
|
+
|
5
10
|
def authorize
|
11
|
+
puts "\n"
|
12
|
+
if File.exist?(Dir.home + "/ayadn/accounts.db")
|
13
|
+
@status.has_to_migrate
|
14
|
+
exit
|
15
|
+
end
|
6
16
|
puts "\e[H\e[2J"
|
7
|
-
try_remove_old_ayadn
|
8
17
|
show_link
|
9
18
|
token = get_token
|
10
19
|
check_token(token)
|
11
|
-
puts "\
|
20
|
+
puts "\e[H\e[2J"
|
21
|
+
@thor.say_status :connexion, "downloading user info", :yellow
|
12
22
|
user = create_user_data(token, Dir.home + "/ayadn")
|
13
23
|
prepare(user)
|
14
|
-
|
24
|
+
@thor.say_status :create, "configuration", :yellow
|
15
25
|
Settings.load_config
|
16
26
|
Logs.create_logger
|
17
27
|
install
|
18
|
-
|
19
|
-
Errors.info "
|
20
|
-
|
28
|
+
@thor.say_status :done, "user #{user.handle} is authorized", :green
|
29
|
+
Errors.info "#{user.handle} authorized."
|
30
|
+
@status.say { @thor.say_status :end, "Thank you for using Ayadn. Enjoy!", :green }
|
31
|
+
Switch.new.list
|
32
|
+
end
|
33
|
+
|
34
|
+
def unauthorize(user, options)
|
35
|
+
begin
|
36
|
+
@workers = Workers.new
|
37
|
+
if user.size > 1
|
38
|
+
@status.one_username
|
39
|
+
exit
|
40
|
+
end
|
41
|
+
user = @workers.remove_arobase_if_present(user)[0]
|
42
|
+
puts "\e[H\e[2J"
|
43
|
+
if options[:delete]
|
44
|
+
sure = @thor.yes?("Are you sure you want to unauthorize user @#{user} and delete its folders?\n\n> ", :red)
|
45
|
+
else
|
46
|
+
sure = @thor.yes?("Are you sure you want to unauthorize user @#{user} ?\n\n> ", :red)
|
47
|
+
end
|
48
|
+
unless sure == true
|
49
|
+
Status.new.canceled
|
50
|
+
exit
|
51
|
+
end
|
52
|
+
puts "\e[H\e[2J"
|
53
|
+
@thor.say_status :delete, "database entry for @#{user}", :yellow
|
54
|
+
db = Amalgalite::Database.new(Dir.home + "/ayadn/accounts.sqlite")
|
55
|
+
Databases.remove_from_accounts(db, user)
|
56
|
+
if options[:delete]
|
57
|
+
@thor.say_status :delete, "@#{user} user folders", :yellow
|
58
|
+
FileUtils.remove_dir(Dir.home + "/ayadn/#{user}")
|
59
|
+
end
|
60
|
+
@thor.say_status :done, "user @#{user} has been unauthorized", :green
|
61
|
+
puts "\n"
|
62
|
+
rescue Interrupt
|
63
|
+
Status.new.canceled
|
64
|
+
exit
|
65
|
+
end
|
21
66
|
end
|
22
67
|
|
23
68
|
private
|
24
69
|
|
25
70
|
def prepare(user)
|
26
|
-
|
71
|
+
@thor.say_status :create, "user folders", :yellow
|
27
72
|
create_config_folders(user)
|
28
|
-
|
73
|
+
@thor.say_status :save, "user token", :yellow
|
29
74
|
create_token_file(user)
|
30
|
-
|
31
|
-
|
32
|
-
|
75
|
+
@thor.say_status :create, "Ayadn account", :yellow
|
76
|
+
acc_db = Amalgalite::Database.new(Dir.home + "/ayadn/accounts.sqlite")
|
77
|
+
user_db = Amalgalite::Database.new("#{user.user_path}/db/ayadn.sqlite")
|
78
|
+
if user_db.schema.tables.empty?
|
79
|
+
Databases.create_tables(user)
|
80
|
+
end
|
81
|
+
if acc_db.schema.tables.empty?
|
82
|
+
Databases.create_account_table(acc_db)
|
83
|
+
end
|
84
|
+
Databases.create_account(acc_db, user)
|
33
85
|
end
|
34
86
|
|
35
87
|
def install
|
36
|
-
|
37
|
-
Errors.info "Creating api
|
88
|
+
@thor.say_status :create, "api and config files", :yellow
|
89
|
+
Errors.info "Creating api and config files..."
|
38
90
|
Errors.info "Creating version file..."
|
39
91
|
Settings.init_config
|
40
92
|
end
|
41
93
|
|
42
|
-
def create_account(user, accounts_db)
|
43
|
-
accounts_db[user.username] = {username: user.username, id: user.id, handle: user.handle, path: user.user_path}
|
44
|
-
accounts_db['ACTIVE'] = user.username
|
45
|
-
accounts_db.flush
|
46
|
-
accounts_db.close
|
47
|
-
end
|
48
|
-
|
49
94
|
def create_token_file(user)
|
50
95
|
File.write("#{user.user_path}/auth/token", user.token)
|
51
96
|
end
|
@@ -53,70 +98,60 @@ module Ayadn
|
|
53
98
|
def create_config_folders(user)
|
54
99
|
begin
|
55
100
|
FileUtils.mkdir_p(user.user_path)
|
56
|
-
%w{log db
|
101
|
+
%w{log db config auth downloads posts messages lists}.each do |target|
|
57
102
|
Dir.mkdir("#{user.user_path}/#{target}") unless Dir.exist?("#{user.user_path}/#{target}")
|
58
103
|
end
|
59
104
|
rescue => e
|
60
|
-
|
61
|
-
|
105
|
+
@status.say do
|
106
|
+
@thor.say_status :error, "can't create #{user.handle} account folders", :red
|
107
|
+
end
|
108
|
+
@status.say { puts "\nError: #{e}" }
|
62
109
|
exit
|
63
110
|
end
|
64
111
|
end
|
65
112
|
|
66
113
|
def show_link
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
114
|
+
@status.say do
|
115
|
+
@thor.say_status :please, "click or copy/paste this URL in a browser", :yellow
|
116
|
+
puts "\n"
|
117
|
+
puts "\t#{Endpoints.new.authorize_url}"
|
118
|
+
puts "\n"
|
119
|
+
@thor.say_status :next, "log in to authorize Ayadn", :cyan
|
120
|
+
@thor.say_status nil, "you will be redirected to your 'user token'"
|
121
|
+
@thor.say_status :please, "copy/paste the token here:", :yellow
|
122
|
+
end
|
123
|
+
print "\t> "
|
74
124
|
end
|
75
125
|
|
76
126
|
def get_user(token)
|
77
|
-
|
127
|
+
begin
|
128
|
+
JSON.parse(RestClient.get("https://api.app.net/users/me?access_token=#{token}", :verify_ssl => OpenSSL::SSL::VERIFY_NONE) {|response, request, result| response })
|
129
|
+
rescue Exception => e
|
130
|
+
@status.say do
|
131
|
+
@thor.say_status :error, "connection problem", :red
|
132
|
+
end
|
133
|
+
puts "#{e}"
|
134
|
+
end
|
78
135
|
end
|
79
136
|
|
80
137
|
def get_token
|
81
138
|
begin
|
82
139
|
STDIN.gets.chomp()
|
83
140
|
rescue Interrupt
|
84
|
-
|
141
|
+
@status.canceled
|
85
142
|
exit
|
86
143
|
end
|
87
144
|
end
|
88
145
|
|
89
146
|
def check_token(token)
|
90
147
|
if token.empty? || token.nil?
|
91
|
-
|
92
|
-
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def try_remove_old_ayadn
|
97
|
-
if FileOps.old_ayadn?
|
98
|
-
answer = ask_del_old_ayadn
|
99
|
-
unless answer.downcase == "y"
|
100
|
-
puts Status.canceled
|
101
|
-
exit
|
102
|
-
end
|
103
|
-
puts "\nDeleting old version...\n".color(:green)
|
104
|
-
begin
|
105
|
-
old_dir = Dir.home + "/ayadn"
|
106
|
-
FileUtils.remove_dir(old_dir)
|
107
|
-
rescue => e
|
108
|
-
puts "Unable to remove folder: #{old_dir}\n\n".color(:red)
|
109
|
-
raise e
|
148
|
+
@status.say do
|
149
|
+
@thor.say_status :error, "couldn't get the token", :red
|
110
150
|
end
|
151
|
+
exit
|
111
152
|
end
|
112
153
|
end
|
113
154
|
|
114
|
-
def ask_del_old_ayadn
|
115
|
-
puts "\nAn obsolete version of Ayadn has been detected and will be deleted. Install and authorize the new version? [y/N]\n".color(:red)
|
116
|
-
print "> "
|
117
|
-
STDIN.getch
|
118
|
-
end
|
119
|
-
|
120
155
|
def create_user_data(token, home_path)
|
121
156
|
resp = get_user(token)
|
122
157
|
model = Struct.new(:resp, :username, :id, :handle, :home_path, :user_path, :token)
|
data/lib/ayadn/blacklist.rb
CHANGED
@@ -5,44 +5,44 @@ module Ayadn
|
|
5
5
|
map "create" => :add
|
6
6
|
long_desc Descriptions.blacklist_add
|
7
7
|
def add(*args)
|
8
|
-
|
8
|
+
if args.length < 2
|
9
|
+
Status.new.type_and_target_missing
|
10
|
+
exit
|
11
|
+
end
|
9
12
|
BlacklistWorkers.new.add(args)
|
10
|
-
|
13
|
+
Status.new.done
|
11
14
|
end
|
12
15
|
|
13
16
|
desc "remove TYPE TARGET", "Removes a mention, hashtag, client or username from your blacklist"
|
14
17
|
map "delete" => :remove
|
15
18
|
long_desc Descriptions.blacklist_remove
|
16
19
|
def remove(*args)
|
17
|
-
|
20
|
+
if args.length < 2
|
21
|
+
Status.new.type_and_target_missing
|
22
|
+
exit
|
23
|
+
end
|
18
24
|
BlacklistWorkers.new.remove(args)
|
19
|
-
|
25
|
+
Status.new.done
|
20
26
|
end
|
21
27
|
|
22
28
|
desc "list", "List the content of your blacklist"
|
23
29
|
long_desc Descriptions.blacklist_list
|
24
30
|
option :raw, aliases: "-x", type: :boolean, desc: "Outputs the raw list in CSV"
|
31
|
+
option :compact, aliases: "-k", type: :boolean, desc: "Force the view to be compact if not already"
|
25
32
|
def list
|
26
33
|
BlacklistWorkers.new.list(options)
|
27
34
|
end
|
28
35
|
|
29
|
-
desc "import DATABASE", "Imports a blacklist database from another Ayadn account"
|
30
|
-
long_desc Descriptions.blacklist_import
|
31
|
-
def import(database)
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
desc "convert", "Convert your current blacklist database to the new format"
|
36
|
-
long_desc Descriptions.blacklist_convert
|
37
|
-
def convert
|
38
|
-
BlacklistWorkers.new.convert
|
39
|
-
puts Status.done
|
40
|
-
end
|
36
|
+
# desc "import DATABASE", "Imports a blacklist database from another Ayadn account"
|
37
|
+
# long_desc Descriptions.blacklist_import
|
38
|
+
# def import(database)
|
39
|
+
# BlacklistWorkers.new.import(database)
|
40
|
+
# end
|
41
41
|
|
42
42
|
desc "clear", "Clear your blacklist database"
|
43
43
|
def clear
|
44
44
|
BlacklistWorkers.new.clear
|
45
|
-
|
45
|
+
Status.new.done
|
46
46
|
end
|
47
47
|
|
48
48
|
end
|
@@ -56,39 +56,29 @@ module Ayadn
|
|
56
56
|
Databases.open_databases
|
57
57
|
@workers = Workers.new
|
58
58
|
end
|
59
|
-
def import(database)
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
73
|
-
def convert
|
74
|
-
begin
|
75
|
-
Databases.convert_blacklist
|
76
|
-
ensure
|
77
|
-
Databases.close_all
|
78
|
-
end
|
79
|
-
end
|
59
|
+
# def import(database)
|
60
|
+
# begin
|
61
|
+
# new_db = File.realpath(database)
|
62
|
+
# if File.exist?(new_db)
|
63
|
+
# Databases.import_blacklist(new_db)
|
64
|
+
# Logs.rec.info "Imported '#{new_db}' values in blacklist database."
|
65
|
+
# else
|
66
|
+
# puts "\nFile '#{new_db}' doesn't exist.\n\n".color(:red)
|
67
|
+
# Logs.rec.warn "File '#{new_db}' doesn't exist."
|
68
|
+
# end
|
69
|
+
# end
|
70
|
+
# end
|
80
71
|
def clear
|
81
72
|
begin
|
82
|
-
|
73
|
+
Status.new.ask_clear_blacklist
|
83
74
|
input = STDIN.getch
|
84
75
|
if input == 'y' || input == 'Y'
|
85
76
|
Databases.clear_blacklist
|
86
77
|
Logs.rec.info "Cleared the blacklist database."
|
87
78
|
else
|
88
|
-
|
79
|
+
Status.new.canceled
|
80
|
+
exit
|
89
81
|
end
|
90
|
-
ensure
|
91
|
-
Databases.close_all
|
92
82
|
end
|
93
83
|
end
|
94
84
|
def add(args)
|
@@ -96,24 +86,24 @@ module Ayadn
|
|
96
86
|
type = args.shift
|
97
87
|
case type
|
98
88
|
when 'user', 'username', 'account'
|
89
|
+
target = @workers.remove_arobase_if_present(args)
|
90
|
+
Databases.add_to_blacklist('user', target)
|
99
91
|
target = @workers.add_arobases_to_usernames args
|
100
|
-
Databases.add_user_to_blacklist(target)
|
101
92
|
Logs.rec.info "Added '#{target}' to blacklist of users."
|
102
93
|
when 'mention', 'mentions'
|
94
|
+
target = @workers.remove_arobase_if_present(args)
|
95
|
+
Databases.add_to_blacklist('mention', target)
|
103
96
|
target = @workers.add_arobases_to_usernames args
|
104
|
-
Databases.add_mention_to_blacklist(target)
|
105
97
|
Logs.rec.info "Added '#{target}' to blacklist of mentions."
|
106
98
|
when 'client', 'source'
|
107
|
-
Databases.
|
99
|
+
Databases.add_to_blacklist('client', args)
|
108
100
|
Logs.rec.info "Added '#{args}' to blacklist of clients."
|
109
101
|
when 'hashtag', 'tag'
|
110
|
-
Databases.
|
102
|
+
Databases.add_to_blacklist('hashtag', args)
|
111
103
|
Logs.rec.info "Added '#{args}' to blacklist of hashtags."
|
112
104
|
else
|
113
|
-
|
105
|
+
Status.new.wrong_arguments
|
114
106
|
end
|
115
|
-
ensure
|
116
|
-
Databases.close_all
|
117
107
|
end
|
118
108
|
end
|
119
109
|
def remove(args)
|
@@ -121,44 +111,44 @@ module Ayadn
|
|
121
111
|
type = args.shift
|
122
112
|
case type
|
123
113
|
when 'user', 'username', 'account'
|
124
|
-
|
125
|
-
target =
|
126
|
-
Databases.remove_from_blacklist(target)
|
114
|
+
Databases.remove_from_blacklist(args)
|
115
|
+
target = @workers.add_arobases_to_usernames(args)
|
127
116
|
Logs.rec.info "Removed '#{target}' from blacklist of users."
|
128
117
|
when 'mention', 'mentions'
|
129
|
-
|
130
|
-
|
118
|
+
Databases.remove_from_blacklist(args)
|
119
|
+
target = @workers.add_arobases_to_usernames(args)
|
131
120
|
Logs.rec.info "Removed '#{target}' from blacklist of mentions."
|
132
121
|
when 'client', 'source', 'hashtag', 'tag'
|
133
122
|
Databases.remove_from_blacklist(args)
|
134
123
|
Logs.rec.info "Removed '#{type}:#{args}' from blacklist."
|
135
124
|
else
|
136
|
-
|
125
|
+
Status.new.wrong_arguments
|
137
126
|
end
|
138
|
-
ensure
|
139
|
-
Databases.close_all
|
140
127
|
end
|
141
128
|
end
|
142
129
|
def list(options)
|
143
130
|
begin
|
131
|
+
Settings.options[:timeline][:compact] = true if options[:compact] == true
|
144
132
|
show_list(options)
|
145
|
-
ensure
|
146
|
-
Databases.close_all
|
147
133
|
end
|
148
134
|
end
|
149
135
|
|
150
136
|
private
|
151
137
|
|
152
138
|
def show_list(options)
|
153
|
-
list = Databases.
|
139
|
+
list = Databases.all_blacklist
|
154
140
|
unless list.empty?
|
155
141
|
if options[:raw]
|
156
|
-
list.
|
142
|
+
xx = list.map {|obj| [obj[0], obj[1].to_s.force_encoding("UTF-8")] }
|
143
|
+
puts xx.to_json
|
157
144
|
else
|
145
|
+
puts "\n"
|
158
146
|
puts Workers.new.build_blacklist_list(list)
|
147
|
+
puts "\n"
|
159
148
|
end
|
160
149
|
else
|
161
|
-
|
150
|
+
Status.new.empty_list
|
151
|
+
exit
|
162
152
|
end
|
163
153
|
end
|
164
154
|
end
|