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/check.rb
CHANGED
@@ -3,185 +3,192 @@ module Ayadn
|
|
3
3
|
|
4
4
|
class Check
|
5
5
|
|
6
|
-
def
|
6
|
+
def initialize
|
7
|
+
@status = Status.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def same_username(stream)
|
7
11
|
stream['data']['username'] == Settings.config[:identity][:username]
|
8
12
|
end
|
9
13
|
|
10
|
-
def
|
11
|
-
FileOps.save_muted_list(list) if Settings.options[:backup][:
|
14
|
+
def auto_save_muted(list)
|
15
|
+
FileOps.save_muted_list(list) if Settings.options[:backup][:lists]
|
12
16
|
end
|
13
17
|
|
14
|
-
def
|
15
|
-
FileOps.save_followers_list(list) if Settings.options[:backup][:
|
18
|
+
def auto_save_followers(list)
|
19
|
+
FileOps.save_followers_list(list) if Settings.options[:backup][:lists]
|
16
20
|
end
|
17
21
|
|
18
|
-
def
|
19
|
-
FileOps.save_followings_list(list) if Settings.options[:backup][:
|
22
|
+
def auto_save_followings(list)
|
23
|
+
FileOps.save_followings_list(list) if Settings.options[:backup][:lists]
|
20
24
|
end
|
21
25
|
|
22
|
-
def
|
23
|
-
|
26
|
+
def no_username username
|
27
|
+
if username.empty?
|
28
|
+
@status.error_missing_username
|
29
|
+
exit
|
30
|
+
end
|
24
31
|
end
|
25
32
|
|
26
|
-
def
|
33
|
+
def no_data stream, target
|
27
34
|
if stream['data'].empty?
|
28
35
|
Errors.warn "In action/#{target}: no data"
|
29
|
-
|
36
|
+
@status.empty_list
|
37
|
+
exit
|
30
38
|
end
|
31
39
|
end
|
32
40
|
|
33
|
-
def
|
34
|
-
if options[:new]
|
41
|
+
def no_new_posts stream, options, title
|
42
|
+
if options[:new] == true
|
35
43
|
unless Databases.has_new?(stream, title)
|
36
|
-
|
44
|
+
@status.no_new_posts
|
45
|
+
exit
|
37
46
|
end
|
38
47
|
end
|
39
48
|
end
|
40
49
|
|
41
|
-
def
|
50
|
+
def no_post stream, post_id
|
42
51
|
if stream['meta']['code'] == 404
|
43
|
-
|
52
|
+
@status.post_404(post_id)
|
44
53
|
Errors.info("Impossible to find #{post_id}")
|
45
54
|
exit
|
46
55
|
end
|
47
56
|
end
|
48
57
|
|
49
|
-
def
|
50
|
-
|
58
|
+
def bad_post_id post_id
|
59
|
+
unless post_id.is_integer?
|
60
|
+
@status.error_missing_post_id
|
61
|
+
exit
|
62
|
+
end
|
51
63
|
end
|
52
64
|
|
53
|
-
def
|
65
|
+
def bad_post_ids(post_ids)
|
66
|
+
post_ids.each do |id|
|
67
|
+
unless id.is_integer?
|
68
|
+
@status.error_missing_post_id
|
69
|
+
exit
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def no_user stream, username
|
54
75
|
if stream['meta']['code'] == 404
|
55
|
-
|
76
|
+
@status.user_404(username)
|
56
77
|
Errors.info("User #{username} doesn't exist")
|
57
78
|
exit
|
58
79
|
end
|
59
80
|
end
|
60
81
|
|
61
|
-
def
|
82
|
+
def has_been_unfollowed(username, resp)
|
62
83
|
if resp['meta']['code'] == 200
|
63
|
-
|
64
|
-
Logs.rec.info "Unfollowed #{username}."
|
84
|
+
@status.unfollowed(username)
|
65
85
|
else
|
66
|
-
|
86
|
+
@status.not_unfollowed(username)
|
67
87
|
end
|
68
88
|
end
|
69
89
|
|
70
|
-
def
|
90
|
+
def has_been_unmuted(username, resp)
|
71
91
|
if resp['meta']['code'] == 200
|
72
|
-
|
73
|
-
Logs.rec.info "Unmuted #{username}."
|
92
|
+
@status.unmuted(username)
|
74
93
|
else
|
75
|
-
|
94
|
+
@status.not_unmuted(username)
|
76
95
|
end
|
77
96
|
end
|
78
97
|
|
79
|
-
def
|
98
|
+
def already_starred(resp)
|
80
99
|
if resp['data']['you_starred']
|
81
|
-
|
100
|
+
@status.already_starred
|
82
101
|
exit
|
83
102
|
end
|
84
103
|
end
|
85
104
|
|
86
|
-
def
|
105
|
+
def already_reposted(resp)
|
87
106
|
if resp['data']['you_reposted']
|
88
|
-
|
107
|
+
@status.already_reposted
|
89
108
|
exit
|
90
109
|
end
|
91
110
|
end
|
92
111
|
|
93
|
-
def
|
112
|
+
def has_been_starred(post_id, resp)
|
94
113
|
if resp['meta']['code'] == 200
|
95
|
-
|
96
|
-
Logs.rec.info "Starred #{post_id}."
|
114
|
+
@status.starred(post_id)
|
97
115
|
else
|
98
|
-
|
116
|
+
@status.not_starred(post_id)
|
99
117
|
end
|
100
118
|
end
|
101
119
|
|
102
|
-
def
|
120
|
+
def has_been_reposted(post_id, resp)
|
103
121
|
if resp['meta']['code'] == 200
|
104
|
-
|
105
|
-
Logs.rec.info "Reposted #{post_id}."
|
122
|
+
@status.reposted(post_id)
|
106
123
|
else
|
107
|
-
|
124
|
+
@status.not_reposted(post_id)
|
108
125
|
end
|
109
126
|
end
|
110
127
|
|
111
|
-
def
|
128
|
+
def has_been_blocked(username, resp)
|
112
129
|
if resp['meta']['code'] == 200
|
113
|
-
|
114
|
-
Logs.rec.info "Blocked #{username}."
|
130
|
+
@status.blocked(username)
|
115
131
|
else
|
116
|
-
|
132
|
+
@status.not_blocked(username)
|
117
133
|
end
|
118
134
|
end
|
119
135
|
|
120
|
-
def
|
136
|
+
def has_been_muted(username, resp)
|
121
137
|
if resp['meta']['code'] == 200
|
122
|
-
|
123
|
-
Logs.rec.info "Muted #{username}."
|
138
|
+
@status.muted(username)
|
124
139
|
else
|
125
|
-
|
140
|
+
@status.not_muted(username)
|
126
141
|
end
|
127
142
|
end
|
128
143
|
|
129
|
-
def
|
144
|
+
def has_been_followed(username, resp)
|
130
145
|
if resp['meta']['code'] == 200
|
131
|
-
|
132
|
-
Logs.rec.info "Followed #{username}."
|
146
|
+
@status.followed(username)
|
133
147
|
else
|
134
|
-
|
148
|
+
@status.not_followed(username)
|
135
149
|
end
|
136
150
|
end
|
137
151
|
|
138
|
-
def
|
152
|
+
def has_been_deleted(post_id, resp)
|
139
153
|
if resp['meta']['code'] == 200
|
140
|
-
|
141
|
-
Logs.rec.info "Deleted post #{post_id}."
|
154
|
+
@status.deleted(post_id)
|
142
155
|
else
|
143
|
-
|
156
|
+
@status.not_deleted(post_id)
|
144
157
|
end
|
145
158
|
end
|
146
159
|
|
147
|
-
def
|
160
|
+
def message_has_been_deleted(message_id, resp)
|
148
161
|
if resp['meta']['code'] == 200
|
149
|
-
|
150
|
-
Logs.rec.info "Deleted message #{message_id}."
|
162
|
+
@status.deleted_m(message_id)
|
151
163
|
else
|
152
|
-
|
164
|
+
@status.not_deleted_m(message_id)
|
153
165
|
end
|
154
166
|
end
|
155
167
|
|
156
|
-
def
|
168
|
+
def has_been_unblocked(username, resp)
|
157
169
|
if resp['meta']['code'] == 200
|
158
|
-
|
159
|
-
Logs.rec.info "Unblocked #{username}."
|
170
|
+
@status.unblocked(username)
|
160
171
|
else
|
161
|
-
|
172
|
+
@status.not_unblocked(username)
|
162
173
|
end
|
163
174
|
end
|
164
175
|
|
165
|
-
def
|
176
|
+
def has_been_unstarred(post_id, resp)
|
166
177
|
if resp['meta']['code'] == 200
|
167
|
-
|
168
|
-
Logs.rec.info "Unstarred #{post_id}."
|
178
|
+
@status.unstarred(post_id)
|
169
179
|
else
|
170
|
-
|
180
|
+
@status.not_unstarred(post_id)
|
171
181
|
end
|
172
182
|
end
|
173
183
|
|
174
|
-
def
|
184
|
+
def has_been_unreposted(post_id, resp)
|
175
185
|
if resp['meta']['code'] == 200
|
176
|
-
|
177
|
-
Logs.rec.info "Unreposted #{post_id}."
|
186
|
+
@status.unreposted(post_id)
|
178
187
|
else
|
179
|
-
|
188
|
+
@status.not_unreposted(post_id)
|
180
189
|
end
|
181
190
|
end
|
182
191
|
|
183
|
-
|
184
|
-
|
185
192
|
end
|
186
193
|
|
187
194
|
end
|
data/lib/ayadn/cnx.rb
CHANGED
@@ -7,14 +7,22 @@ module Ayadn
|
|
7
7
|
begin
|
8
8
|
RestClient.get(url) {|response, request, result| response}
|
9
9
|
rescue SocketError, SystemCallError, OpenSSL::SSL::SSLError, RestClient::RequestTimeout => e
|
10
|
+
thor = Thor::Shell::Color.new
|
10
11
|
if working == true
|
11
12
|
working = false
|
12
|
-
|
13
|
+
thor.say_status :error, "'#{url}' didn't respond", :red
|
14
|
+
thor.say_status :info, "trying again in 5 secs", :yellow
|
13
15
|
sleep 5
|
14
16
|
retry
|
15
17
|
end
|
16
|
-
|
18
|
+
thor.say_status :error, "connection problem", :red
|
17
19
|
Errors.global_error({error: e, caller: caller, data: [url]})
|
20
|
+
rescue Interrupt
|
21
|
+
thor = Thor::Shell::Color.new
|
22
|
+
puts "\n"
|
23
|
+
thor.say_status :canceled, "connection canceled", :red
|
24
|
+
puts "\n"
|
25
|
+
exit
|
18
26
|
rescue => e
|
19
27
|
Errors.global_error({error: e, caller: caller, data: [url]})
|
20
28
|
end
|
@@ -35,6 +43,12 @@ module Ayadn
|
|
35
43
|
end
|
36
44
|
Errors.nr "URL: #{url}"
|
37
45
|
return {'meta' => {'code' => 666}, 'data' => "#{e}"}.to_json
|
46
|
+
rescue Interrupt
|
47
|
+
thor = Thor::Shell::Color.new
|
48
|
+
puts "\n"
|
49
|
+
thor.say_status :canceled, "connection canceled", :red
|
50
|
+
puts "\n"
|
51
|
+
exit
|
38
52
|
rescue => e
|
39
53
|
Errors.global_error({error: e, caller: caller, data: [url]})
|
40
54
|
end
|
@@ -64,19 +78,27 @@ module Ayadn
|
|
64
78
|
try_cnx = retry_adn 10, try_cnx
|
65
79
|
retry
|
66
80
|
end
|
67
|
-
|
81
|
+
Thor::Shell::Color.new.say_status :error, "connection problem", :red
|
68
82
|
Errors.global_error({error: e, caller: caller, data: [url]})
|
69
83
|
rescue URI::InvalidURIError => e
|
70
|
-
|
84
|
+
Thor::Shell::Color.new.say_status :error, "connection or authorization problem", :red
|
71
85
|
Errors.global_error({error: e, caller: caller, data: [url]})
|
86
|
+
rescue Interrupt
|
87
|
+
thor = Thor::Shell::Color.new
|
88
|
+
puts "\n"
|
89
|
+
thor.say_status :canceled, "connection canceled", :red
|
90
|
+
puts "\n"
|
91
|
+
exit
|
72
92
|
rescue => e
|
73
93
|
Errors.global_error({error: e, caller: caller, data: [url]})
|
74
94
|
end
|
75
95
|
end
|
76
96
|
|
77
97
|
def self.retry_adn seconds, try_cnx
|
98
|
+
thor = Thor::Shell::Color.new
|
99
|
+
thor.say_status :error, "unable to connect to App.net", :red
|
100
|
+
thor.say_status :info, "trying again in #{seconds} seconds (#{try_cnx}/3)", :yellow
|
78
101
|
Errors.warn "Unable to connect to App.net"
|
79
|
-
puts "\n\nUnable to connect to App.net\nRetrying in #{seconds} seconds... (#{try_cnx}/3)\n".color(:red)
|
80
102
|
try_cnx += 1
|
81
103
|
sleep seconds
|
82
104
|
puts "\e[H\e[2J"
|
@@ -84,35 +106,40 @@ module Ayadn
|
|
84
106
|
end
|
85
107
|
|
86
108
|
def self.check response
|
87
|
-
|
109
|
+
if response.code != 200
|
110
|
+
res = JSON.parse(response)
|
111
|
+
message = res['meta']['error_message']
|
112
|
+
thor = Thor::Shell::Color.new
|
113
|
+
puts "\n"
|
114
|
+
end
|
88
115
|
case response.code
|
89
116
|
when 200
|
90
117
|
response
|
91
118
|
when 204
|
92
|
-
|
93
|
-
Errors.global_error({error:
|
119
|
+
thor.say_status :error, message.upcase, :red
|
120
|
+
Errors.global_error({error: message, caller: caller, data: [res]})
|
94
121
|
when 400
|
95
|
-
|
96
|
-
Errors.global_error({error:
|
122
|
+
thor.say_status :error, message.upcase, :red
|
123
|
+
Errors.global_error({error: message, caller: caller, data: [res]})
|
97
124
|
when 401
|
98
|
-
|
99
|
-
Errors.global_error({error:
|
125
|
+
thor.say_status :error, message.upcase, :red
|
126
|
+
Errors.global_error({error: message, caller: caller, data: [res]})
|
100
127
|
when 403
|
101
|
-
|
102
|
-
Errors.global_error({error:
|
128
|
+
thor.say_status :error, message.upcase, :red
|
129
|
+
Errors.global_error({error: message, caller: caller, data: [res]})
|
103
130
|
when 405
|
104
|
-
|
105
|
-
Errors.global_error({error:
|
131
|
+
thor.say_status :error, message.upcase, :red
|
132
|
+
Errors.global_error({error: message, caller: caller, data: [res]})
|
106
133
|
when 429
|
107
|
-
|
134
|
+
thor.say_status :error, message.upcase, :red
|
108
135
|
puts "\n\nAyadn made too many requests to the App.net API. You should wait at least ".color(:cyan) + "#{response.headers[:retry_after]} ".color(:red) + "seconds before trying again. Maybe you launched a lot of Ayadn instances at the same time? That's no problem, but in this case you should increase the value of the scroll timer (with `ayadn set scroll timer 5` for example). App.net allows 5000 requests per hour per account maximum.".color(:cyan)
|
109
|
-
Errors.global_error({error:
|
136
|
+
Errors.global_error({error: message, caller: caller, data: [res]})
|
110
137
|
when 500
|
111
|
-
|
112
|
-
Errors.global_error({error:
|
138
|
+
thor.say_status :error, message.upcase, :red
|
139
|
+
Errors.global_error({error: message, caller: caller, data: [res]})
|
113
140
|
when 507
|
114
|
-
|
115
|
-
Errors.global_error({error:
|
141
|
+
thor.say_status :error, message.upcase, :red
|
142
|
+
Errors.global_error({error: message, caller: caller, data: [res]})
|
116
143
|
else
|
117
144
|
response
|
118
145
|
end
|
@@ -125,8 +152,14 @@ module Ayadn
|
|
125
152
|
check response
|
126
153
|
end
|
127
154
|
rescue SocketError, SystemCallError => e
|
128
|
-
|
155
|
+
Thor::Shell::Color.new.say_status :error, "connection problem", :red
|
129
156
|
Errors.global_error({error: e, caller: caller, data: [url]})
|
157
|
+
rescue Interrupt
|
158
|
+
thor = Thor::Shell::Color.new
|
159
|
+
puts "\n"
|
160
|
+
thor.say_status :canceled, "connection canceled", :red
|
161
|
+
puts "\n"
|
162
|
+
exit
|
130
163
|
rescue => e
|
131
164
|
Errors.global_error({error: e, caller: caller, data: [url]})
|
132
165
|
end
|
@@ -139,8 +172,14 @@ module Ayadn
|
|
139
172
|
check response
|
140
173
|
end
|
141
174
|
rescue SocketError, SystemCallError => e
|
142
|
-
|
175
|
+
Thor::Shell::Color.new.say_status :error, "connection problem", :red
|
143
176
|
Errors.global_error({error: e, caller: caller, data: [url, payload]})
|
177
|
+
rescue Interrupt
|
178
|
+
thor = Thor::Shell::Color.new
|
179
|
+
puts "\n"
|
180
|
+
thor.say_status :canceled, "connection canceled", :red
|
181
|
+
puts "\n"
|
182
|
+
exit
|
144
183
|
rescue => e
|
145
184
|
Errors.global_error({error: e, caller: caller, data: [url, payload]})
|
146
185
|
end
|
@@ -153,8 +192,14 @@ module Ayadn
|
|
153
192
|
check response
|
154
193
|
end
|
155
194
|
rescue SocketError, SystemCallError => e
|
156
|
-
|
195
|
+
Thor::Shell::Color.new.say_status :error, "connection problem", :red
|
157
196
|
Errors.global_error({error: e, caller: caller, data: [url, payload]})
|
197
|
+
rescue Interrupt
|
198
|
+
thor = Thor::Shell::Color.new
|
199
|
+
puts "\n"
|
200
|
+
thor.say_status :canceled, "connection canceled", :red
|
201
|
+
puts "\n"
|
202
|
+
exit
|
158
203
|
rescue => e
|
159
204
|
Errors.global_error({error: e, caller: caller, data: [url, payload]})
|
160
205
|
end
|
@@ -167,8 +212,14 @@ module Ayadn
|
|
167
212
|
check response
|
168
213
|
end
|
169
214
|
rescue SocketError, SystemCallError => e
|
170
|
-
|
215
|
+
Thor::Shell::Color.new.say_status :error, "connection problem", :red
|
171
216
|
Errors.global_error({error: e, caller: caller, data: [url, payload]})
|
217
|
+
rescue Interrupt
|
218
|
+
thor = Thor::Shell::Color.new
|
219
|
+
puts "\n"
|
220
|
+
thor.say_status :canceled, "connection canceled", :red
|
221
|
+
puts "\n"
|
222
|
+
exit
|
172
223
|
rescue => e
|
173
224
|
Errors.global_error({error: e, caller: caller, data: [url, payload]})
|
174
225
|
end
|