ayadn 1.4.6 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -1
- data/CHANGELOG.md +14 -1
- data/README.md +38 -13
- data/ayadn.gemspec +2 -2
- data/doc/01-index.md +38 -0
- data/doc/02-install.md +24 -0
- data/doc/03-first-steps.md +161 -0
- data/doc/04-options.md +13 -0
- data/doc/05-streams.md +288 -0
- data/doc/06-post.md +109 -0
- data/doc/07-actions.md +115 -0
- data/doc/08-listings.md +85 -0
- data/doc/09-accounts.md +33 -0
- data/doc/10-nicerank.md +58 -0
- data/doc/11-blacklist.md +85 -0
- data/doc/12-alias.md +57 -0
- data/doc/13-bookmark.md +51 -0
- data/doc/14-set.md +139 -0
- data/doc/15-nowplaying.md +23 -0
- data/doc/16-contact.md +29 -0
- data/doc/17-shortcuts.md +8 -0
- data/doc/18-examples.md +43 -0
- data/lib/ayadn/action.rb +147 -88
- data/lib/ayadn/api.rb +19 -37
- data/lib/ayadn/app.rb +4 -5
- data/lib/ayadn/databases.rb +0 -6
- data/lib/ayadn/debug.rb +6 -0
- data/lib/ayadn/endpoints.rb +5 -1
- data/lib/ayadn/mark.rb +2 -2
- data/lib/ayadn/nicerank.rb +34 -10
- data/lib/ayadn/post.rb +20 -0
- data/lib/ayadn/set.rb +0 -37
- data/lib/ayadn/settings.rb +32 -20
- data/lib/ayadn/version.rb +1 -1
- data/lib/ayadn/view.rb +52 -32
- data/lib/ayadn/workers.rb +54 -15
- data/spec/unit/api_spec.rb +0 -27
- data/spec/unit/view_spec.rb +11 -11
- data/spec/unit/workers_spec.rb +46 -47
- metadata +23 -5
data/lib/ayadn/api.rb
CHANGED
@@ -125,6 +125,10 @@ module Ayadn
|
|
125
125
|
get_parsed_response(Endpoints.new.user(username))
|
126
126
|
end
|
127
127
|
|
128
|
+
def get_users(usernames)
|
129
|
+
get_parsed_response(Endpoints.new.users(usernames))
|
130
|
+
end
|
131
|
+
|
128
132
|
def get_details(post_id, options = {})
|
129
133
|
get_parsed_response(Endpoints.new.single_post(post_id, options))
|
130
134
|
end
|
@@ -154,12 +158,12 @@ module Ayadn
|
|
154
158
|
JSON.parse(CNX.post(Endpoints.new.star(post_id)))
|
155
159
|
end
|
156
160
|
|
157
|
-
def follow(
|
158
|
-
JSON.parse(CNX.post(Endpoints.new.follow(
|
161
|
+
def follow(username)
|
162
|
+
JSON.parse(CNX.post(Endpoints.new.follow(username)))
|
159
163
|
end
|
160
164
|
|
161
|
-
def mute(
|
162
|
-
JSON.parse(CNX.post(Endpoints.new.mute(
|
165
|
+
def mute(username)
|
166
|
+
JSON.parse(CNX.post(Endpoints.new.mute(username)))
|
163
167
|
end
|
164
168
|
|
165
169
|
def block(username)
|
@@ -235,42 +239,19 @@ module Ayadn
|
|
235
239
|
end
|
236
240
|
|
237
241
|
def self.build_query(arg)
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
end
|
243
|
-
end
|
244
|
-
directed = Settings.options[:timeline][:directed]
|
245
|
-
if arg[:directed]
|
246
|
-
if arg[:directed] == 0 || arg[:directed] == 1
|
247
|
-
directed = arg[:directed]
|
248
|
-
end
|
249
|
-
end
|
250
|
-
deleted = Settings.options[:timeline][:deleted]
|
251
|
-
if arg[:deleted]
|
252
|
-
if arg[:deleted] == 0 || arg[:deleted] == 1
|
253
|
-
deleted = arg[:deleted]
|
254
|
-
end
|
255
|
-
end
|
256
|
-
html = Settings.options[:timeline][:html]
|
257
|
-
if arg[:html]
|
258
|
-
if arg[:html] == 0 || arg[:html] == 1
|
259
|
-
html = arg[:html]
|
260
|
-
end
|
261
|
-
end
|
262
|
-
annotations = Settings.options[:timeline][:annotations]
|
263
|
-
if arg[:annotations]
|
264
|
-
if arg[:annotations] == 0 || arg[:annotations] == 1
|
265
|
-
annotations = arg[:annotations]
|
266
|
-
end
|
242
|
+
if arg[:count].to_s.is_integer?
|
243
|
+
count = arg[:count]
|
244
|
+
else
|
245
|
+
count = Settings.options[:counts][:default]
|
267
246
|
end
|
247
|
+
directed = arg[:directed] || Settings.options[:timeline][:directed]
|
248
|
+
html = arg[:html] || Settings.options[:timeline][:html]
|
268
249
|
if arg[:since_id]
|
269
|
-
"&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted
|
250
|
+
"&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted=0&include_annotations=1&since_id=#{arg[:since_id]}"
|
270
251
|
elsif arg[:recent_message]
|
271
|
-
"&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted
|
252
|
+
"&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted=0&include_annotations=1&include_recent_message=#{arg[:recent_message]}"
|
272
253
|
else
|
273
|
-
"&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted
|
254
|
+
"&count=#{count}&include_html=#{html}&include_directed=#{directed}&include_deleted=0&include_annotations=1"
|
274
255
|
end
|
275
256
|
end
|
276
257
|
|
@@ -301,7 +282,8 @@ module Ayadn
|
|
301
282
|
loop do
|
302
283
|
resp = get_parsed_response(get_list_url(username, target, options))
|
303
284
|
abort(Status.user_404(username)) if resp['meta']['code'] == 404
|
304
|
-
|
285
|
+
users = Workers.extract_users(resp)
|
286
|
+
big_hash.merge!(users)
|
305
287
|
break if resp['meta']['min_id'] == nil
|
306
288
|
options = {:count => 200, :before_id => resp['meta']['min_id']}
|
307
289
|
end
|
data/lib/ayadn/app.rb
CHANGED
@@ -5,6 +5,9 @@ module Ayadn
|
|
5
5
|
|
6
6
|
%w{action api descriptions endpoints cnx view workers settings post status extend databases fileops logs pinboard set alias errors blacklist scroll authorize switch mark nicerank debug}.each { |r| require_relative "#{r}" }
|
7
7
|
|
8
|
+
##
|
9
|
+
# These methods are intended to be called from the CLI.
|
10
|
+
|
8
11
|
desc "timeline", "Show your App.net timeline, aka the Unified Stream (-tl)"
|
9
12
|
map "unified" => :timeline
|
10
13
|
map "-tl" => :timeline
|
@@ -455,11 +458,7 @@ module Ayadn
|
|
455
458
|
desc "version", "Show the current Ayadn version (-v)"
|
456
459
|
map "-v" => :version
|
457
460
|
def version
|
458
|
-
|
459
|
-
puts "Version:\t".color(:cyan) + "#{VERSION}\n".color(:green)
|
460
|
-
puts "Changelog:\t".color(:cyan) + "https://github.com/ericdke/na/blob/master/CHANGELOG.md\n".color(:yellow)
|
461
|
-
puts "Docs:\t\t".color(:cyan) + "http://ayadn-app.net/doc/".color(:yellow)
|
462
|
-
puts "\n"
|
461
|
+
Action.new.version
|
463
462
|
end
|
464
463
|
|
465
464
|
end
|
data/lib/ayadn/databases.rb
CHANGED
@@ -38,13 +38,7 @@ module Ayadn
|
|
38
38
|
end
|
39
39
|
|
40
40
|
def self.init(path)
|
41
|
-
# winPlatforms = ['mswin', 'mingw', 'mingw_18', 'mingw_19', 'mingw_20', 'mingw32']
|
42
|
-
# case RbConfig::CONFIG['host_os']
|
43
|
-
# when *winPlatforms
|
44
|
-
# abort("\nSorry, Ayadn doesn't work on Windows.\n\n".color(:red))
|
45
|
-
# else
|
46
41
|
Daybreak::DB.new "#{path}"
|
47
|
-
# end
|
48
42
|
end
|
49
43
|
|
50
44
|
def self.add_niceranks niceranks
|
data/lib/ayadn/debug.rb
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
module Ayadn
|
3
3
|
class Debug
|
4
4
|
|
5
|
+
def self.skipped dic
|
6
|
+
if Settings.options[:timeline][:show_debug] == true
|
7
|
+
Logs.rec.debug "SKIPPED: #{dic.keys.first.to_s.capitalize} => #{dic.values.first}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
def self.http response, url
|
6
12
|
if Settings.options[:timeline][:show_debug] == true
|
7
13
|
# deb = ":::::\n"
|
data/lib/ayadn/endpoints.rb
CHANGED
@@ -195,10 +195,14 @@ module Ayadn
|
|
195
195
|
"#{@channels_url}search?q=#{words}&order=popularity&access_token=#{Settings.user_token}#{@options_list}"
|
196
196
|
end
|
197
197
|
|
198
|
-
def user(username)
|
198
|
+
def user(username) # accepts a string
|
199
199
|
"#{@users_url}#{username}?access_token=#{Settings.user_token}&include_user_annotations=1"
|
200
200
|
end
|
201
201
|
|
202
|
+
def users(usernames) # accepts an array
|
203
|
+
"#{@users_url}?ids=#{usernames.join(',')}?access_token=#{Settings.user_token}&include_user_annotations=1"
|
204
|
+
end
|
205
|
+
|
202
206
|
def single_post(post_id, options)
|
203
207
|
"#{@posts_url}#{post_id}?access_token=#{Settings.user_token}#{API.build_query(options)}"
|
204
208
|
end
|
data/lib/ayadn/mark.rb
CHANGED
@@ -4,6 +4,7 @@ module Ayadn
|
|
4
4
|
|
5
5
|
desc "add POST_ID (TITLE)", "Create a bookmark for this conversation"
|
6
6
|
long_desc Descriptions.mark_add
|
7
|
+
map "create" => :add
|
7
8
|
def add(*args)
|
8
9
|
begin
|
9
10
|
unless args.empty?
|
@@ -50,8 +51,6 @@ module Ayadn
|
|
50
51
|
puts Status.done
|
51
52
|
rescue => e
|
52
53
|
Errors.global_error({error: e, caller: caller, data: [args]})
|
53
|
-
ensure
|
54
|
-
Databases.close_all
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
@@ -97,6 +96,7 @@ module Ayadn
|
|
97
96
|
end
|
98
97
|
|
99
98
|
desc "delete POST_ID", "Delete entry POST_ID from your bookmarked conversations"
|
99
|
+
map "remove" => :delete
|
100
100
|
long_desc Descriptions.mark_delete
|
101
101
|
def delete *args
|
102
102
|
begin
|
data/lib/ayadn/nicerank.rb
CHANGED
@@ -6,6 +6,39 @@ module Ayadn
|
|
6
6
|
@url = 'http://api.nice.social/user/nicerank?ids='
|
7
7
|
end
|
8
8
|
|
9
|
+
def get_posts_day ids
|
10
|
+
resp = JSON.parse(CNX.get("#{@url}#{ids.join(',')}&show_details=Y"))
|
11
|
+
if resp.nil? || resp['meta']['code'] != 200
|
12
|
+
[]
|
13
|
+
else
|
14
|
+
resp['data'].map do |obj|
|
15
|
+
pday = obj['user']['posts_day'] == -1 ? 0 : obj['user']['posts_day']
|
16
|
+
{
|
17
|
+
id: obj['user_id'],
|
18
|
+
posts_day:pday.round(2)
|
19
|
+
}
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def from_ids ids
|
25
|
+
blocs, ranks = [], []
|
26
|
+
blank = JSON.parse({'meta' => {'code' => 404}, 'data' => []}.to_json)
|
27
|
+
until ids.empty?
|
28
|
+
blocs << ids.shift(200)
|
29
|
+
end
|
30
|
+
blocs.each do |bloc|
|
31
|
+
got = CNX.get("#{@url}#{bloc.join(',')}&show_details=Y")
|
32
|
+
if got.nil? || got.empty?
|
33
|
+
ranks << [{}]
|
34
|
+
else
|
35
|
+
resps = JSON.parse(got)
|
36
|
+
ranks << resps['data']
|
37
|
+
end
|
38
|
+
end
|
39
|
+
return ranks.flatten!
|
40
|
+
end
|
41
|
+
|
9
42
|
def get_ranks stream
|
10
43
|
user_ids, get_these, table, niceranks = [], [], {}, {}
|
11
44
|
|
@@ -16,16 +49,7 @@ module Ayadn
|
|
16
49
|
user_ids.uniq!
|
17
50
|
|
18
51
|
db_ranks = Databases.get_niceranks user_ids
|
19
|
-
|
20
|
-
expire = 172800 # 48h
|
21
|
-
else
|
22
|
-
if Settings.options[:nicerank][:cache].nil?
|
23
|
-
Settings.options[:nicerank][:cache] = 48
|
24
|
-
expire = 172800
|
25
|
-
else
|
26
|
-
expire = Settings.options[:nicerank][:cache] * 3600
|
27
|
-
end
|
28
|
-
end
|
52
|
+
expire = Settings.options[:nicerank][:cache] * 3600 # Time.now needs seconds
|
29
53
|
|
30
54
|
db_ranks.each do |id, ranks|
|
31
55
|
if ranks.nil? || (Time.now - ranks[:cached]) > expire
|
data/lib/ayadn/post.rb
CHANGED
@@ -44,6 +44,26 @@ module Ayadn
|
|
44
44
|
|
45
45
|
def payload_nowplaying dic
|
46
46
|
ann = annotations()
|
47
|
+
if dic['visible'] == true
|
48
|
+
ann << {
|
49
|
+
"type" => "com.ayadn.nowplaying",
|
50
|
+
"value" => {
|
51
|
+
"title" => dic['title'],
|
52
|
+
"artist" => dic['artist'],
|
53
|
+
"artwork" => dic['artwork'],
|
54
|
+
"link" => dic['link'],
|
55
|
+
"source" => dic['source']
|
56
|
+
}
|
57
|
+
}
|
58
|
+
else
|
59
|
+
ann << {
|
60
|
+
"type" => "com.ayadn.nowplaying",
|
61
|
+
"value" => {
|
62
|
+
"status" => "no-url",
|
63
|
+
"source" => dic['source']
|
64
|
+
}
|
65
|
+
}
|
66
|
+
end
|
47
67
|
if dic['visible'] == true
|
48
68
|
ann << {
|
49
69
|
"type" => "net.app.core.oembed",
|
data/lib/ayadn/set.rb
CHANGED
@@ -71,12 +71,6 @@ module Ayadn
|
|
71
71
|
counts_config.save
|
72
72
|
end
|
73
73
|
|
74
|
-
# desc "format ITEM NUMBER", "Set ITEM parameter to NUMBER by default"
|
75
|
-
# map "formats" => :format
|
76
|
-
# def format(*args)
|
77
|
-
# puts args
|
78
|
-
# end
|
79
|
-
|
80
74
|
desc "color ITEM COLOR", "Set ITEM to COLOR"
|
81
75
|
long_desc Descriptions.set_color
|
82
76
|
map "colors" => :color
|
@@ -160,17 +154,6 @@ module Ayadn
|
|
160
154
|
Settings.get_token
|
161
155
|
Settings.init_config
|
162
156
|
Logs.create_logger
|
163
|
-
unless Settings.options[:nicerank]
|
164
|
-
Settings.options[:nicerank] = {
|
165
|
-
threshold: 2.1,
|
166
|
-
cache: 48,
|
167
|
-
filter: true,
|
168
|
-
filter_unranked: false
|
169
|
-
}
|
170
|
-
end
|
171
|
-
unless Settings.options[:colors][:nicerank]
|
172
|
-
Settings.options[:colors][:nicerank] = :cyan
|
173
|
-
end
|
174
157
|
end
|
175
158
|
def log(args)
|
176
159
|
x = "New value for '#{args[0]}' in 'NiceRank' => #{"%1.1f" % args[1].to_f}"
|
@@ -382,26 +365,10 @@ module Ayadn
|
|
382
365
|
def show_date(value)
|
383
366
|
Settings.options[:timeline][:show_date] = value
|
384
367
|
end
|
385
|
-
def show_nicerank value
|
386
|
-
unless Settings.options[:nicerank]
|
387
|
-
Settings.options[:nicerank] = {
|
388
|
-
threshold: 2.1,
|
389
|
-
filter: true,
|
390
|
-
filter_unranked: false
|
391
|
-
}
|
392
|
-
end
|
393
|
-
unless Settings.options[:colors][:nicerank]
|
394
|
-
Settings.options[:colors][:nicerank] = :cyan
|
395
|
-
end
|
396
|
-
Settings.options[:timeline][:show_nicerank] = value
|
397
|
-
end
|
398
368
|
def show_spinner value
|
399
369
|
Settings.options[:timeline][:show_spinner] = value
|
400
370
|
end
|
401
371
|
def show_debug value
|
402
|
-
unless Settings.options[:colors][:debug]
|
403
|
-
Settings.options[:colors][:debug] = :cyan
|
404
|
-
end
|
405
372
|
Settings.options[:timeline][:show_debug] = value
|
406
373
|
end
|
407
374
|
end
|
@@ -491,9 +458,5 @@ module Ayadn
|
|
491
458
|
def debug(color)
|
492
459
|
Settings.options[:colors][:debug] = color.to_sym
|
493
460
|
end
|
494
|
-
|
495
|
-
def nicerank(color)
|
496
|
-
Settings.options[:colors][:nicerank] = color.to_sym
|
497
|
-
end
|
498
461
|
end
|
499
462
|
end
|
data/lib/ayadn/settings.rb
CHANGED
@@ -6,7 +6,7 @@ module Ayadn
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
attr_accessor :options, :config
|
9
|
-
attr_reader :user_token
|
9
|
+
attr_reader :user_token, :default_nr
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.load_config
|
@@ -35,6 +35,12 @@ module Ayadn
|
|
35
35
|
handle: db[active][:handle]
|
36
36
|
}
|
37
37
|
}
|
38
|
+
@default_nr = {
|
39
|
+
threshold: 2.1,
|
40
|
+
cache: 48,
|
41
|
+
filter: true,
|
42
|
+
filter_unranked: false
|
43
|
+
}
|
38
44
|
db.close
|
39
45
|
@options = self.defaults
|
40
46
|
end
|
@@ -78,9 +84,21 @@ module Ayadn
|
|
78
84
|
def self.config_file
|
79
85
|
config_file = @config[:paths][:config] + "/config.yml"
|
80
86
|
if File.exist?(config_file)
|
81
|
-
# TODO: system to merge existing config file when future category are added
|
82
87
|
begin
|
83
|
-
|
88
|
+
conf = YAML.load(File.read(config_file))
|
89
|
+
|
90
|
+
# force delete obsolete keys (because legacy versions of the config file)
|
91
|
+
conf[:timeline].delete_if {|k,_| k == :show_nicerank}
|
92
|
+
conf[:colors].delete_if {|k,_| k == :nicerank}
|
93
|
+
# force create mandatory keys (idem)
|
94
|
+
conf[:nicerank] = @default_nr if conf[:nicerank].nil? || conf[:nicerank].size != 4
|
95
|
+
conf[:timeline][:show_debug] = false if conf[:timeline][:show_debug].nil?
|
96
|
+
conf[:timeline][:show_spinner] = true if conf[:timeline][:show_spinner].nil?
|
97
|
+
conf[:colors][:debug] = :red if conf[:colors][:debug].nil?
|
98
|
+
conf[:nowplaying] = {} if conf[:nowplaying].nil?
|
99
|
+
|
100
|
+
@options = conf
|
101
|
+
self.write_config_file(config_file, @options)
|
84
102
|
rescue => e
|
85
103
|
Errors.global_error({error: e, caller: caller, data: []})
|
86
104
|
end
|
@@ -152,27 +170,26 @@ module Ayadn
|
|
152
170
|
show_symbols: true,
|
153
171
|
show_real_name: true,
|
154
172
|
show_date: true,
|
155
|
-
show_nicerank: false,
|
156
173
|
show_spinner: true,
|
157
174
|
show_debug: false
|
158
175
|
},
|
159
176
|
counts: {
|
160
177
|
default: 50,
|
161
|
-
unified:
|
162
|
-
global:
|
163
|
-
checkins:
|
178
|
+
unified: 100,
|
179
|
+
global: 100,
|
180
|
+
checkins: 100,
|
164
181
|
conversations: 50,
|
165
182
|
photos: 50,
|
166
|
-
trending:
|
167
|
-
mentions:
|
168
|
-
convo:
|
169
|
-
posts:
|
183
|
+
trending: 100,
|
184
|
+
mentions: 100,
|
185
|
+
convo: 100,
|
186
|
+
posts: 100,
|
170
187
|
messages: 50,
|
171
|
-
search:
|
188
|
+
search: 200,
|
172
189
|
whoreposted: 50,
|
173
190
|
whostarred: 50,
|
174
191
|
whatstarred: 100,
|
175
|
-
files:
|
192
|
+
files: 100
|
176
193
|
},
|
177
194
|
formats: {
|
178
195
|
table: {
|
@@ -191,7 +208,6 @@ module Ayadn
|
|
191
208
|
mentions: :red,
|
192
209
|
source: :cyan,
|
193
210
|
symbols: :green,
|
194
|
-
nicerank: :cyan,
|
195
211
|
debug: :red
|
196
212
|
},
|
197
213
|
backup: {
|
@@ -202,12 +218,8 @@ module Ayadn
|
|
202
218
|
scroll: {
|
203
219
|
timer: 3
|
204
220
|
},
|
205
|
-
nicerank:
|
206
|
-
|
207
|
-
cache: 48,
|
208
|
-
filter: true,
|
209
|
-
filter_unranked: false
|
210
|
-
}
|
221
|
+
nicerank: @default_nr,
|
222
|
+
nowplaying: {}
|
211
223
|
}
|
212
224
|
end
|
213
225
|
|
data/lib/ayadn/version.rb
CHANGED