ayadn 1.6.0 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/doc/05-streams.md +17 -0
- data/doc/06-post.md +41 -6
- data/lib/ayadn/action.rb +68 -123
- data/lib/ayadn/annotations.rb +191 -0
- data/lib/ayadn/app.rb +29 -5
- data/lib/ayadn/databases.rb +8 -2
- data/lib/ayadn/debug.rb +6 -6
- data/lib/ayadn/descriptions.rb +55 -2
- data/lib/ayadn/endpoints.rb +11 -3
- data/lib/ayadn/logs.rb +0 -17
- data/lib/ayadn/mark.rb +5 -2
- data/lib/ayadn/nowplaying.rb +17 -16
- data/lib/ayadn/nowwatching.rb +34 -9
- data/lib/ayadn/post.rb +46 -256
- data/lib/ayadn/scroll.rb +10 -8
- data/lib/ayadn/search.rb +2 -0
- data/lib/ayadn/set.rb +83 -198
- data/lib/ayadn/status.rb +3 -0
- data/lib/ayadn/stream.rb +27 -40
- data/lib/ayadn/tvshow.rb +8 -6
- data/lib/ayadn/version.rb +1 -1
- data/lib/ayadn/view.rb +8 -0
- data/lib/ayadn/workers.rb +41 -36
- data/spec/unit/post_spec.rb +19 -19
- metadata +3 -3
- data/doc/shortcuts.md +0 -8
data/lib/ayadn/post.rb
CHANGED
@@ -2,175 +2,79 @@
|
|
2
2
|
module Ayadn
|
3
3
|
class Post
|
4
4
|
|
5
|
-
def post(
|
6
|
-
|
7
|
-
send_post(args.join(" "))
|
8
|
-
else
|
9
|
-
error_text_empty
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def compose
|
14
|
-
readline()
|
15
|
-
end
|
16
|
-
|
17
|
-
def send_embedded text, files
|
18
|
-
send_embedded_pictures({'text' => text, 'data' => FileOps.upload_files(files)})
|
19
|
-
end
|
20
|
-
|
21
|
-
def send_reply_embedded text, reply_to, files
|
22
|
-
send_reply_embedded_pictures({'text' => text, 'reply_to' => reply_to, 'data' => FileOps.upload_files(files)})
|
23
|
-
end
|
24
|
-
|
25
|
-
def send_pm_embedded username, text, files
|
26
|
-
send_pm_embedded_pictures({'text' => text, 'username' => username, 'data' => FileOps.upload_files(files)})
|
5
|
+
def post(dic)
|
6
|
+
send_content(Endpoints.new.posts_url, payload_basic(dic))
|
27
7
|
end
|
28
8
|
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
9
|
+
def reply(dic)
|
10
|
+
replied_to = dic[:reply_to].values[0]
|
11
|
+
reply = replied_to[:handle].dup
|
12
|
+
reply << " #{dic[:text]}"
|
13
|
+
replied_to[:mentions].uniq!
|
14
|
+
replied_to[:mentions].each do |m|
|
15
|
+
next if m == replied_to[:username]
|
16
|
+
next if m == Settings.config[:identity][:username]
|
17
|
+
reply << " @#{m}"
|
18
|
+
end
|
19
|
+
dic[:text] = reply
|
20
|
+
dic[:reply_to] = dic[:id]
|
21
|
+
send_content(Endpoints.new.posts_url, payload_reply(dic))
|
39
22
|
end
|
40
23
|
|
41
|
-
def
|
42
|
-
send_content(Endpoints.new.
|
24
|
+
def pm(dic)
|
25
|
+
send_content(Endpoints.new.pm_url, payload_pm(dic))
|
43
26
|
end
|
44
27
|
|
45
|
-
def
|
46
|
-
send_content(Endpoints.new.
|
28
|
+
def message(dic)
|
29
|
+
send_content(Endpoints.new.messages(dic[:id]), payload_basic(dic))
|
47
30
|
end
|
48
31
|
|
49
|
-
|
50
|
-
send_content(Endpoints.new.posts_url, payload_tvshow(dic))
|
51
|
-
end
|
32
|
+
# -----
|
52
33
|
|
53
|
-
def
|
54
|
-
ann = annotations_embedded(dic)
|
55
|
-
ann << {
|
56
|
-
"type" => "com.ayadn.movie",
|
57
|
-
"value" => {
|
58
|
-
"title" => dic['title'],
|
59
|
-
"source" => dic['source']
|
60
|
-
}
|
61
|
-
}
|
34
|
+
def payload_basic(dic)
|
62
35
|
{
|
63
|
-
"text" => dic[
|
64
|
-
"entities" => entities,
|
65
|
-
"annotations" =>
|
36
|
+
"text" => dic[:text],
|
37
|
+
"entities" => entities(),
|
38
|
+
"annotations" => Annotations.new(dic).content
|
66
39
|
}
|
67
40
|
end
|
68
41
|
|
69
|
-
def
|
70
|
-
ann = annotations_embedded(dic)
|
71
|
-
ann << {
|
72
|
-
"type" => "com.ayadn.tvshow",
|
73
|
-
"value" => {
|
74
|
-
"title" => dic['title'],
|
75
|
-
"source" => dic['source']
|
76
|
-
}
|
77
|
-
}
|
42
|
+
def payload_pm(dic)
|
78
43
|
{
|
79
|
-
"text" => dic[
|
80
|
-
"entities" => entities,
|
81
|
-
"
|
44
|
+
"text" => dic[:text],
|
45
|
+
"entities" => entities(),
|
46
|
+
"destinations" => dic[:username],
|
47
|
+
"annotations" => Annotations.new(dic).content
|
82
48
|
}
|
83
49
|
end
|
84
50
|
|
85
|
-
def
|
86
|
-
ann = annotations()
|
87
|
-
if dic['visible'] == true
|
88
|
-
ann << {
|
89
|
-
"type" => "com.ayadn.nowplaying",
|
90
|
-
"value" => {
|
91
|
-
"title" => dic['title'],
|
92
|
-
"artist" => dic['artist'],
|
93
|
-
"artwork" => dic['artwork'],
|
94
|
-
"link" => dic['link'],
|
95
|
-
"source" => dic['source']
|
96
|
-
}
|
97
|
-
}
|
98
|
-
else
|
99
|
-
ann << {
|
100
|
-
"type" => "com.ayadn.nowplaying",
|
101
|
-
"value" => {
|
102
|
-
"status" => "no-url",
|
103
|
-
"source" => dic['source']
|
104
|
-
}
|
105
|
-
}
|
106
|
-
end
|
107
|
-
if dic['visible'] == true
|
108
|
-
ann << {
|
109
|
-
"type" => "net.app.core.oembed",
|
110
|
-
"value" => {
|
111
|
-
"version" => "1.0",
|
112
|
-
"type" => "photo",
|
113
|
-
"width" => dic['width'],
|
114
|
-
"height" => dic['height'],
|
115
|
-
"title" => dic['title'],
|
116
|
-
"url" => dic['artwork'],
|
117
|
-
"embeddable_url" => dic['artwork'],
|
118
|
-
"provider_url" => "https://itunes.apple.com",
|
119
|
-
"provider_name" => "iTunes",
|
120
|
-
"thumbnail_url" => dic['artwork_thumb'],
|
121
|
-
"thumbnail_width" => dic['width_thumb'],
|
122
|
-
"thumbnail_height" => dic['height_thumb']
|
123
|
-
}
|
124
|
-
}
|
125
|
-
end
|
51
|
+
def payload_reply(dic)
|
126
52
|
{
|
127
|
-
"text" => dic[
|
128
|
-
"
|
129
|
-
"
|
53
|
+
"text" => dic[:text],
|
54
|
+
"reply_to" => dic[:reply_to],
|
55
|
+
"entities" => entities(),
|
56
|
+
"annotations" => Annotations.new(dic).content
|
130
57
|
}
|
131
58
|
end
|
132
59
|
|
133
|
-
def
|
60
|
+
def entities
|
134
61
|
{
|
135
|
-
"
|
136
|
-
"
|
137
|
-
"annotations" => annotations_embedded(dic)
|
62
|
+
"parse_markdown_links" => true,
|
63
|
+
"parse_links" => true
|
138
64
|
}
|
139
65
|
end
|
140
66
|
|
141
|
-
|
142
|
-
{
|
143
|
-
"text" => dic['text'],
|
144
|
-
"reply_to" => dic['reply_to'],
|
145
|
-
"entities" => entities,
|
146
|
-
"annotations" => annotations_embedded(dic)
|
147
|
-
}
|
148
|
-
end
|
67
|
+
# -----
|
149
68
|
|
150
|
-
def
|
151
|
-
{
|
152
|
-
|
153
|
-
"entities" => entities,
|
154
|
-
"destinations" => dic['username'],
|
155
|
-
"annotations" => annotations_embedded(dic)
|
156
|
-
}
|
69
|
+
def send_content(url, payload)
|
70
|
+
url << "?include_annotations=1&access_token=#{Ayadn::Settings.user_token}"
|
71
|
+
JSON.parse(CNX.post(url, payload))
|
157
72
|
end
|
158
73
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
"type" => "net.app.core.oembed",
|
164
|
-
"value" => {
|
165
|
-
"+net.app.core.file" => {
|
166
|
-
"file_id" => obj['data']['id'],
|
167
|
-
"file_token" => obj['data']['file_token'],
|
168
|
-
"format" => "oembed"
|
169
|
-
}
|
170
|
-
}
|
171
|
-
}
|
172
|
-
end
|
173
|
-
return base
|
74
|
+
# -----
|
75
|
+
|
76
|
+
def compose
|
77
|
+
readline()
|
174
78
|
end
|
175
79
|
|
176
80
|
def auto_readline
|
@@ -178,7 +82,7 @@ module Ayadn
|
|
178
82
|
begin
|
179
83
|
#while buffer = Readline.readline("#{Settings.config[:identity][:handle]} >> ".color(:red))
|
180
84
|
while buffer = Readline.readline(">> ".color(:red))
|
181
|
-
|
85
|
+
post({text: buffer})
|
182
86
|
puts Status.done
|
183
87
|
end
|
184
88
|
rescue Interrupt
|
@@ -200,45 +104,6 @@ module Ayadn
|
|
200
104
|
post
|
201
105
|
end
|
202
106
|
|
203
|
-
def reply(new_post, replied_to)
|
204
|
-
replied_to = replied_to.values[0]
|
205
|
-
reply = replied_to[:handle].dup
|
206
|
-
reply << " #{new_post}"
|
207
|
-
replied_to[:mentions].uniq!
|
208
|
-
replied_to[:mentions].each do |m|
|
209
|
-
next if m == replied_to[:username]
|
210
|
-
next if m == Settings.config[:identity][:username]
|
211
|
-
reply << " @#{m}"
|
212
|
-
end
|
213
|
-
reply
|
214
|
-
end
|
215
|
-
|
216
|
-
def send_pm(username, text)
|
217
|
-
send_content(Endpoints.new.pm_url, payload_pm(username, text))
|
218
|
-
end
|
219
|
-
|
220
|
-
def send_message(channel_id, text)
|
221
|
-
send_content(Endpoints.new.messages(channel_id, {}), payload_basic(text))
|
222
|
-
end
|
223
|
-
|
224
|
-
# def send_log(data)
|
225
|
-
# url = Endpoints.new.ayadnlog
|
226
|
-
# send_content(url, payload_log(data))
|
227
|
-
# end
|
228
|
-
|
229
|
-
def send_post(text)
|
230
|
-
send_content(Endpoints.new.posts_url, payload_basic(text))
|
231
|
-
end
|
232
|
-
|
233
|
-
def send_reply(text, post_id)
|
234
|
-
send_content(Endpoints.new.posts_url, payload_reply(text, post_id))
|
235
|
-
end
|
236
|
-
|
237
|
-
def send_content(url, payload)
|
238
|
-
url << "?include_annotations=1&access_token=#{Ayadn::Settings.user_token}"
|
239
|
-
JSON.parse(CNX.post(url, payload))
|
240
|
-
end
|
241
|
-
|
242
107
|
def check_post_length(lines_array)
|
243
108
|
check_length(lines_array, Settings.config[:post_max_length])
|
244
109
|
end
|
@@ -278,80 +143,5 @@ module Ayadn
|
|
278
143
|
Errors.warn "-Post without text-"
|
279
144
|
end
|
280
145
|
|
281
|
-
def annotations
|
282
|
-
[
|
283
|
-
{
|
284
|
-
"type" => "com.ayadn.user",
|
285
|
-
"value" => {
|
286
|
-
"+net.app.core.user" => {
|
287
|
-
"user_id" => "#{Settings.config[:identity][:handle]}",
|
288
|
-
"format" => "basic"
|
289
|
-
}
|
290
|
-
}
|
291
|
-
},
|
292
|
-
{
|
293
|
-
"type" => "com.ayadn.client",
|
294
|
-
"value" => {
|
295
|
-
"url" => "http://ayadn-app.net",
|
296
|
-
"author" => {
|
297
|
-
"name" => "Eric Dejonckheere",
|
298
|
-
"username" => "ericd",
|
299
|
-
"id" => "69904",
|
300
|
-
"email" => "eric@aya.io"
|
301
|
-
},
|
302
|
-
"version" => "#{Settings.config[:version]}"
|
303
|
-
}
|
304
|
-
}
|
305
|
-
]
|
306
|
-
end
|
307
|
-
|
308
|
-
def entities
|
309
|
-
{
|
310
|
-
"parse_markdown_links" => true,
|
311
|
-
"parse_links" => true
|
312
|
-
}
|
313
|
-
end
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
def payload_basic(text)
|
318
|
-
{
|
319
|
-
"text" => text,
|
320
|
-
"entities" => entities,
|
321
|
-
"annotations" => annotations
|
322
|
-
}
|
323
|
-
end
|
324
|
-
|
325
|
-
def payload_pm(username, text)
|
326
|
-
{
|
327
|
-
"text" => text,
|
328
|
-
"entities" => entities,
|
329
|
-
"destinations" => username,
|
330
|
-
"annotations" => annotations
|
331
|
-
}
|
332
|
-
end
|
333
|
-
|
334
|
-
def payload_reply(text, reply_to)
|
335
|
-
{
|
336
|
-
"text" => text,
|
337
|
-
"reply_to" => reply_to,
|
338
|
-
"entities" => entities,
|
339
|
-
"annotations" => annotations
|
340
|
-
}
|
341
|
-
end
|
342
|
-
|
343
|
-
# def payload_log(data)
|
344
|
-
# extended = annotations
|
345
|
-
# extended << {
|
346
|
-
# "type" => "com.ayadn.log",
|
347
|
-
# "value" => data
|
348
|
-
# }
|
349
|
-
# return {
|
350
|
-
# "text" => "#ayadnlog",
|
351
|
-
# "entities" => entities,
|
352
|
-
# "annotations" => extended
|
353
|
-
# }
|
354
|
-
# end
|
355
|
-
|
356
146
|
end
|
357
147
|
end
|
data/lib/ayadn/scroll.rb
CHANGED
@@ -5,7 +5,9 @@ module Ayadn
|
|
5
5
|
def initialize(api, view)
|
6
6
|
@api = api
|
7
7
|
@view = view
|
8
|
+
@view.hide_cursor
|
8
9
|
@chars = %w{ | / - \\ }
|
10
|
+
at_exit { @view.show_cursor }
|
9
11
|
end
|
10
12
|
|
11
13
|
def method_missing(meth, options)
|
@@ -26,10 +28,10 @@ module Ayadn
|
|
26
28
|
stream = get(target, options)
|
27
29
|
stream['data'].empty? ? niceranks = {} : niceranks = @nr.get_ranks(stream)
|
28
30
|
Debug.stream stream, options, target
|
29
|
-
target = "explore:#{target}" if explore?(target)
|
31
|
+
target = "explore:#{target}" if explore?(target) # explore but not global
|
30
32
|
show_if_new(stream, options, target, niceranks)
|
31
33
|
target = orig_target if target =~ /explore/
|
32
|
-
options = save_then_return(stream, options)
|
34
|
+
options = save_then_return(stream, options, target)
|
33
35
|
countdown
|
34
36
|
rescue Interrupt
|
35
37
|
canceled
|
@@ -45,7 +47,7 @@ module Ayadn
|
|
45
47
|
stream = @api.get_mentions(username, options)
|
46
48
|
Debug.stream stream, options, username
|
47
49
|
show_if_new(stream, options, "mentions:#{id}")
|
48
|
-
options = save_then_return(stream, options)
|
50
|
+
options = save_then_return(stream, options, "mentions:#{id}")
|
49
51
|
countdown
|
50
52
|
rescue Interrupt
|
51
53
|
canceled
|
@@ -61,7 +63,7 @@ module Ayadn
|
|
61
63
|
stream = @api.get_posts(username, options)
|
62
64
|
Debug.stream stream, options, username
|
63
65
|
show_if_new(stream, options, "posts:#{id}")
|
64
|
-
options = save_then_return(stream, options)
|
66
|
+
options = save_then_return(stream, options, "posts:#{id}")
|
65
67
|
countdown
|
66
68
|
rescue Interrupt
|
67
69
|
canceled
|
@@ -76,7 +78,7 @@ module Ayadn
|
|
76
78
|
stream = @api.get_convo(post_id, options)
|
77
79
|
Debug.stream stream, options, post_id
|
78
80
|
show_if_new(stream, options, "replies:#{post_id}")
|
79
|
-
options = save_then_return(stream, options)
|
81
|
+
options = save_then_return(stream, options, "replies:#{post_id}")
|
80
82
|
countdown
|
81
83
|
rescue Interrupt
|
82
84
|
canceled
|
@@ -91,7 +93,7 @@ module Ayadn
|
|
91
93
|
stream = @api.get_messages(channel_id, options)
|
92
94
|
Debug.stream stream, options, channel_id
|
93
95
|
show_if_new(stream, options, "channel:#{channel_id}")
|
94
|
-
options = save_then_return(stream, options)
|
96
|
+
options = save_then_return(stream, options, "channel:#{channel_id}")
|
95
97
|
countdown
|
96
98
|
rescue Interrupt
|
97
99
|
canceled
|
@@ -156,9 +158,9 @@ module Ayadn
|
|
156
158
|
show(stream, options, niceranks) if Databases.has_new?(stream, target)
|
157
159
|
end
|
158
160
|
|
159
|
-
def save_then_return(stream, options)
|
161
|
+
def save_then_return(stream, options, name = 'unknown')
|
160
162
|
unless stream['meta']['max_id'].nil?
|
161
|
-
Databases.save_max_id(stream)
|
163
|
+
Databases.save_max_id(stream, name)
|
162
164
|
return options_hash(stream, options)
|
163
165
|
end
|
164
166
|
options
|
data/lib/ayadn/search.rb
CHANGED
@@ -10,6 +10,7 @@ module Ayadn
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def hashtag(hashtag, options)
|
13
|
+
Settings.options[:force] = true if options[:force]
|
13
14
|
@view.downloading(options)
|
14
15
|
stream = @api.get_hashtag(hashtag)
|
15
16
|
Check.no_data(stream, 'hashtag')
|
@@ -21,6 +22,7 @@ module Ayadn
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def find(words, options)
|
25
|
+
Settings.options[:force] = true if options[:force]
|
24
26
|
@view.downloading(options)
|
25
27
|
stream = get_stream(words, options)
|
26
28
|
Check.no_data(stream, 'search')
|