ayadn 0.6.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +20 -0
- data/.rspec +2 -0
- data/.travis.yml +17 -0
- data/Gemfile +14 -0
- data/Guardfile +26 -0
- data/LICENSE.txt +22 -0
- data/MANUAL.md +946 -0
- data/README.md +26 -411
- data/Rakefile +6 -0
- data/ayadn.gemspec +39 -0
- data/bin/ayadn +3 -3
- data/lib/ayadn.rb +12 -25
- data/lib/ayadn/action.rb +1121 -0
- data/lib/ayadn/alias.rb +106 -0
- data/lib/ayadn/api.rb +312 -301
- data/lib/ayadn/app.rb +429 -365
- data/lib/ayadn/authorize.rb +127 -28
- data/lib/ayadn/blacklist.rb +116 -0
- data/lib/ayadn/cnx.rb +105 -0
- data/lib/ayadn/databases.rb +110 -0
- data/lib/ayadn/descriptions.rb +1043 -0
- data/lib/ayadn/endpoints.rb +220 -153
- data/lib/ayadn/errors.rb +37 -0
- data/lib/ayadn/extend.rb +4 -10
- data/lib/ayadn/fileops.rb +48 -0
- data/lib/ayadn/logs.rb +32 -0
- data/lib/ayadn/pinboard.rb +46 -35
- data/lib/ayadn/post.rb +229 -212
- data/lib/ayadn/scroll.rb +251 -0
- data/lib/ayadn/set.rb +377 -0
- data/lib/ayadn/settings.rb +195 -0
- data/lib/ayadn/status.rb +226 -165
- data/lib/ayadn/switch.rb +72 -0
- data/lib/ayadn/version.rb +4 -0
- data/lib/ayadn/view.rb +506 -269
- data/lib/ayadn/workers.rb +362 -0
- data/spec/helpers.rb +19 -0
- data/spec/mock/@ericd.json +160 -0
- data/spec/mock/@m.json +45 -0
- data/spec/mock/checkins.json +1856 -0
- data/spec/mock/fwr_@ayadn.json +1077 -0
- data/spec/mock/posted.json +1 -0
- data/spec/mock/stream.json +1 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/unit/api_spec.rb +61 -0
- data/spec/unit/databases_spec.rb +5 -0
- data/spec/unit/descriptions_spec.rb +9 -0
- data/spec/unit/endpoints_spec.rb +35 -0
- data/spec/unit/post_spec.rb +136 -0
- data/spec/unit/status_spec.rb +9 -0
- data/spec/unit/view_spec.rb +119 -0
- data/spec/unit/workers_spec.rb +147 -0
- metadata +216 -40
- data/CHANGELOG.md +0 -250
- data/CONTRIBUTORS.md +0 -5
- data/LICENSE.md +0 -14
- data/lib/ayadn/adn_files.rb +0 -84
- data/lib/ayadn/client-http.rb +0 -226
- data/lib/ayadn/colors.rb +0 -62
- data/lib/ayadn/config.yml +0 -35
- data/lib/ayadn/debug.rb +0 -36
- data/lib/ayadn/files.rb +0 -184
- data/lib/ayadn/get-api.rb +0 -43
- data/lib/ayadn/help.rb +0 -152
- data/lib/ayadn/list.rb +0 -89
- data/lib/ayadn/main.rb +0 -542
- data/lib/ayadn/requires.rb +0 -12
- data/lib/ayadn/skip.rb +0 -27
- data/lib/ayadn/tools.rb +0 -208
- data/lib/ayadn/user-stream.rb +0 -91
- data/lib/ayadn/view-channels.rb +0 -120
- data/lib/ayadn/view-interactions.rb +0 -57
- data/lib/ayadn/view-object.rb +0 -195
- data/lib/experiments.rb +0 -109
data/lib/ayadn/switch.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
module Ayadn
|
3
|
+
class Switch
|
4
|
+
def list
|
5
|
+
home_path = Dir.home + "/ayadn"
|
6
|
+
if File.exist?("#{home_path}/accounts.db")
|
7
|
+
accounts_db = Daybreak::DB.new("#{home_path}/accounts.db")
|
8
|
+
active = accounts_db['ACTIVE']
|
9
|
+
begin
|
10
|
+
puts "\nCurrently authorized accounts:\n".color(:cyan)
|
11
|
+
accounts_db.each do |acc|
|
12
|
+
next if acc[0] == 'ACTIVE'
|
13
|
+
if acc[1][:username] == active
|
14
|
+
puts "#{acc[1][:handle]}".color(:red)
|
15
|
+
else
|
16
|
+
puts "#{acc[1][:handle]}".color(:green)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
puts "\n"
|
20
|
+
ensure
|
21
|
+
close_db(accounts_db)
|
22
|
+
end
|
23
|
+
else
|
24
|
+
please
|
25
|
+
end
|
26
|
+
end
|
27
|
+
def switch(user)
|
28
|
+
if user.empty? || user.nil?
|
29
|
+
puts "\n\nOops, something went wrong, I couldn't get your username. Please try again.\n\n".color(:red)
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
#puts "\e[H\e[2J"
|
33
|
+
username = Workers.remove_arobase_if_present(user.first)
|
34
|
+
home_path = Dir.home + "/ayadn"
|
35
|
+
if File.exist?("#{home_path}/accounts.db")
|
36
|
+
accounts_db = Daybreak::DB.new("#{home_path}/accounts.db")
|
37
|
+
active = accounts_db['ACTIVE']
|
38
|
+
if username == accounts_db[active][:username]
|
39
|
+
puts "\nYou're already authorized with username '#{accounts_db[active][:handle]}'.\n".color(:red)
|
40
|
+
cancel(accounts_db)
|
41
|
+
end
|
42
|
+
if accounts_db[username]
|
43
|
+
puts "\nSwitching to account @#{username}...".color(:green)
|
44
|
+
accounts_db['ACTIVE'] = username
|
45
|
+
close_db(accounts_db)
|
46
|
+
puts Status.done
|
47
|
+
exit
|
48
|
+
else
|
49
|
+
puts "\nThis account isn't in the database. Please run 'ayadn authorize'.\n".color(:red)
|
50
|
+
cancel(accounts_db)
|
51
|
+
end
|
52
|
+
else
|
53
|
+
please
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def cancel(accounts_db)
|
60
|
+
accounts_db.close
|
61
|
+
exit
|
62
|
+
end
|
63
|
+
def close_db(db)
|
64
|
+
db.flush
|
65
|
+
db.close
|
66
|
+
end
|
67
|
+
def please
|
68
|
+
puts "\nPlease run 'ayadn authorize' first.\n".color(:red)
|
69
|
+
exit
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
data/lib/ayadn/view.rb
CHANGED
@@ -1,270 +1,507 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
1
|
# encoding: utf-8
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
2
|
+
module Ayadn
|
3
|
+
class View
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@workers = Workers.new
|
7
|
+
end
|
8
|
+
|
9
|
+
def show_posts_with_index(data, options)
|
10
|
+
posts, view = build_stream_with_index(data, options)
|
11
|
+
puts view
|
12
|
+
Databases.save_indexed_posts(posts)
|
13
|
+
end
|
14
|
+
|
15
|
+
def show_posts(data, options)
|
16
|
+
puts build_stream_without_index(data, options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def show_raw(stream)
|
20
|
+
#puts stream.to_json
|
21
|
+
jj stream
|
22
|
+
end
|
23
|
+
|
24
|
+
def show_simple_post(post, options)
|
25
|
+
view = build_stream_without_index(post, options)
|
26
|
+
puts view
|
27
|
+
end
|
28
|
+
|
29
|
+
def show_posted(resp)
|
30
|
+
show_simple_post([resp['data']], {})
|
31
|
+
end
|
32
|
+
|
33
|
+
def show_simple_stream(stream)
|
34
|
+
puts stream
|
35
|
+
end
|
36
|
+
|
37
|
+
def show_list_reposted(list, target)
|
38
|
+
users_list, table = @workers.build_reposted_list(list, target)
|
39
|
+
puts @workers.build_users_list(users_list, table)
|
40
|
+
puts "\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
def show_list_starred(list, target)
|
44
|
+
users_list, table = @workers.build_starred_list(list, target)
|
45
|
+
puts @workers.build_users_list(users_list, table)
|
46
|
+
puts "\n"
|
47
|
+
end
|
48
|
+
|
49
|
+
def show_list_followings(list, target)
|
50
|
+
puts @workers.build_followings_list(list, target)
|
51
|
+
puts "\n"
|
52
|
+
end
|
53
|
+
|
54
|
+
def show_list_followers(list, target)
|
55
|
+
puts @workers.build_followers_list(list, target)
|
56
|
+
puts "\n"
|
57
|
+
end
|
58
|
+
|
59
|
+
def show_list_muted(list)
|
60
|
+
puts @workers.build_muted_list(list)
|
61
|
+
puts "\n"
|
62
|
+
end
|
63
|
+
|
64
|
+
def show_list_blocked(list)
|
65
|
+
puts @workers.build_blocked_list(list)
|
66
|
+
puts "\n"
|
67
|
+
end
|
68
|
+
|
69
|
+
def show_interactions(stream)
|
70
|
+
#puts "\n"
|
71
|
+
puts build_interactions_stream(stream)
|
72
|
+
end
|
73
|
+
|
74
|
+
def show_files_list(list)
|
75
|
+
puts build_files_list(list)
|
76
|
+
end
|
77
|
+
|
78
|
+
def show_settings
|
79
|
+
table = Terminal::Table.new do |t|
|
80
|
+
t.style = { :width => Settings.options[:formats][:table][:width] }
|
81
|
+
t.title = "Current Ayadn settings".color(:cyan)
|
82
|
+
t.headings = [ "Category".color(:red), "Parameter".color(:red), "Value(s)".color(:red) ]
|
83
|
+
@iter = 0
|
84
|
+
Settings.options.each do |k,v|
|
85
|
+
v.each do |x,y|
|
86
|
+
t << :separator if @iter >= 1
|
87
|
+
unless y.is_a?(Hash)
|
88
|
+
t << [ k.to_s.color(:cyan), x.to_s.color(:yellow), y.to_s.color(:green) ]
|
89
|
+
else
|
90
|
+
y.each do |c|
|
91
|
+
t << [ k.to_s.color(:cyan), x.to_s.color(:yellow), "#{c[0]} = #{c[1]}".color(:green) ]
|
92
|
+
end
|
93
|
+
end
|
94
|
+
@iter += 1
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
puts table
|
99
|
+
end
|
100
|
+
|
101
|
+
def show_userinfos(content, token)
|
102
|
+
if content['name']
|
103
|
+
view = "Name\t\t\t".color(:cyan) + content['name'].color(Settings.options[:colors][:name])
|
104
|
+
else
|
105
|
+
view = "Name\t\t\t".color(:cyan) + "(no name)".color(:red)
|
106
|
+
end
|
107
|
+
|
108
|
+
view << "\n\nUsername\t\t".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:id])
|
109
|
+
|
110
|
+
view << "\n\nID\t\t\t".color(:cyan) + content['id'].color(Settings.options[:colors][:username])
|
111
|
+
|
112
|
+
view << "\n\nURL\t\t\t".color(:cyan) + content['canonical_url'].color(Settings.options[:colors][:link])
|
113
|
+
|
114
|
+
unless content['verified_domain'].nil?
|
115
|
+
if content['verified_domain'] =~ (/http/ || /https/)
|
116
|
+
domain = content['verified_domain']
|
117
|
+
else
|
118
|
+
domain = "http://#{content['verified_domain']}"
|
119
|
+
end
|
120
|
+
view << "\nVerified domain\t\t".color(:cyan) + domain.color(Settings.options[:colors][:link])
|
121
|
+
end
|
122
|
+
|
123
|
+
|
124
|
+
view << "\n\nAccount creation\t".color(:cyan) + @workers.parsed_time(content['created_at']).color(:green)
|
125
|
+
view << "\n\nTimeZone\t\t".color(:cyan) + content['timezone'].color(:green)
|
126
|
+
view << "\nLocale\t\t\t".color(:cyan) + content['locale'].color(:green)
|
127
|
+
|
128
|
+
view << "\n\nPosts\t\t\t".color(:cyan) + content['counts']['posts'].to_s.color(:green)
|
129
|
+
|
130
|
+
view << "\n\nFollowing\t\t".color(:cyan) + content['counts']['following'].to_s.color(:green)
|
131
|
+
view << "\nFollowers\t\t".color(:cyan) + content['counts']['followers'].to_s.color(:green)
|
132
|
+
|
133
|
+
if content['username'] == Settings.config[:identity][:username]
|
134
|
+
view << "\n\nStorage used\t\t".color(:cyan) + "#{token['storage']['used'].to_filesize}".color(:red)
|
135
|
+
view << "\nStorage available\t".color(:cyan) + "#{token['storage']['available'].to_filesize}".color(:green)
|
136
|
+
end
|
137
|
+
|
138
|
+
#view << "\nStars\t\t\t".color(:cyan) + content['counts']['stars'].to_s.color(:yellow)
|
139
|
+
|
140
|
+
unless content['username'] == Settings.config[:identity][:username]
|
141
|
+
if content['you_follow']
|
142
|
+
view << "\n\nYou follow ".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:username])
|
143
|
+
else
|
144
|
+
view << "\n\nYou don't follow ".color(:cyan) + "@#{content['username']}".color(Settings.options[:colors][:username])
|
145
|
+
end
|
146
|
+
if content['follows_you']
|
147
|
+
view << "\n" + "@#{content['username']}".color(Settings.options[:colors][:username]) + " follows you".color(:cyan)
|
148
|
+
else
|
149
|
+
view << "\n" + "@#{content['username']}".color(Settings.options[:colors][:username]) + " doesn't follow you".color(:cyan)
|
150
|
+
end
|
151
|
+
if content['you_muted']
|
152
|
+
view << "\nYou muted " + "@#{content['username']}".color(Settings.options[:colors][:username])
|
153
|
+
end
|
154
|
+
if content['you_blocked']
|
155
|
+
view << "\nYou blocked " + "@#{content['username']}".color(Settings.options[:colors][:username])
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
unless content['annotations'].empty?
|
160
|
+
view << "\n"
|
161
|
+
end
|
162
|
+
content['annotations'].each do |anno|
|
163
|
+
case anno['type']
|
164
|
+
when "net.app.core.directory.blog"
|
165
|
+
view << "\nBlog\t\t\t".color(:cyan) + "#{anno['value']['url']}".color(Settings.options[:colors][:link])
|
166
|
+
when "net.app.core.directory.twitter"
|
167
|
+
view << "\nTwitter\t\t\t".color(:cyan) + "#{anno['value']['username']}".color(:green)
|
168
|
+
when "com.appnetizens.userinput.birthday"
|
169
|
+
view << "\nBirthday\t\t".color(:cyan) + "#{anno['value']['birthday']}".color(:green)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
#view << "\n\nAvatar URL\t\t".color(:cyan) + content['avatar_image']['url']
|
175
|
+
|
176
|
+
if content['description']
|
177
|
+
view << "\n\n#{content['description']['text']}\n".color(:magenta) + "\n\n"
|
178
|
+
end
|
179
|
+
|
180
|
+
puts view
|
181
|
+
|
182
|
+
end
|
183
|
+
|
184
|
+
def show_channels(resp)
|
185
|
+
view = ""
|
186
|
+
bucket = @workers.build_channels(resp['data'])
|
187
|
+
bucket.reverse.each do |ch|
|
188
|
+
view << "\n"
|
189
|
+
ch_alias = false
|
190
|
+
Databases.aliases.each do |k,v|
|
191
|
+
if v == "#{ch.id}"
|
192
|
+
ch_alias = k
|
193
|
+
break
|
194
|
+
end
|
195
|
+
end
|
196
|
+
view << "ID: ".color(:cyan)
|
197
|
+
view << "#{ch.id}".color(Settings.options[:colors][:id])
|
198
|
+
view << "\n"
|
199
|
+
if ch_alias
|
200
|
+
view << "Alias: ".color(:cyan)
|
201
|
+
view << "#{ch_alias}".color(Settings.options[:colors][:username])
|
202
|
+
view << "\n"
|
203
|
+
end
|
204
|
+
view << "Messages: ".color(:cyan)
|
205
|
+
view << "#{ch.num_messages}".color(Settings.options[:colors][:symbols])
|
206
|
+
view << "\n"
|
207
|
+
if ch.owner
|
208
|
+
view << "Owner: ".color(:cyan)
|
209
|
+
view << "@#{ch.owner['username']}".color(Settings.options[:colors][:username])
|
210
|
+
# + (#{ch.owner['name']}) if ch.owner['name']
|
211
|
+
view << "\n"
|
212
|
+
end
|
213
|
+
view << "Writers: ".color(:cyan)
|
214
|
+
view << "#{ch.writers}".color(Settings.options[:colors][:name])
|
215
|
+
view << "\n"
|
216
|
+
view << "Type: ".color(:cyan)
|
217
|
+
view << "#{ch.type}".color(Settings.options[:colors][:id])
|
218
|
+
view << "\n"
|
219
|
+
if ch.type == "net.patter-app.room"
|
220
|
+
ann = ch.annotations.select {|a| a['type'] == "net.patter-app.settings"}
|
221
|
+
view << "Name: ".color(:cyan)
|
222
|
+
view << "#{ann[0]['value']['name']}".color(Settings.options[:colors][:link])
|
223
|
+
view << "\n"
|
224
|
+
view << "Description: ".color(:cyan)
|
225
|
+
view << "#{ann[0]['value']['blurb']}".color(Settings.options[:colors][:username])
|
226
|
+
view << "\n"
|
227
|
+
ann = ch.annotations.select {|a| a['type'] == "net.app.core.fallback_url"}
|
228
|
+
view << "URL: ".color(:cyan)
|
229
|
+
view << "#{ann[0]['value']['url']}".color(Settings.options[:colors][:link])
|
230
|
+
view << "\n"
|
231
|
+
end
|
232
|
+
if ch.type == "net.app.core.broadcast"
|
233
|
+
ann = ch.annotations.select {|a| a['type'] == "net.app.core.broadcast.metadata"}
|
234
|
+
view << "Title: ".color(:cyan)
|
235
|
+
view << "#{ann[0]['value']['title']}".color(Settings.options[:colors][:link])
|
236
|
+
view << "\n"
|
237
|
+
view << "Description: ".color(:cyan)
|
238
|
+
view << "#{ann[0]['value']['description']}".color(Settings.options[:colors][:username])
|
239
|
+
view << "\n"
|
240
|
+
ann = ch.annotations.select {|a| a['type'] == "net.app.core.fallback_url"}
|
241
|
+
view << "URL: ".color(:cyan)
|
242
|
+
view << "#{ann[0]['value']['url']}".color(Settings.options[:colors][:link])
|
243
|
+
view << "\n"
|
244
|
+
end
|
245
|
+
unless ch.recent_message.nil?
|
246
|
+
unless ch.recent_message['text'].nil?
|
247
|
+
view << "Most recent message (#{Workers.new.parsed_time(ch.recent_message['created_at'])}): ".color(:cyan)
|
248
|
+
view << "\n"
|
249
|
+
view << "---\n#{ch.recent_message['text']}\n---"
|
250
|
+
end
|
251
|
+
end
|
252
|
+
if ch.type == "net.paste-app.clips"
|
253
|
+
ann = ch.recent_message['annotations'].select {|a| a['type'] == "net.paste-app.clip"}
|
254
|
+
view << "\n\n"
|
255
|
+
view << ann[0]['value']['content']
|
256
|
+
view << "\n"
|
257
|
+
end
|
258
|
+
view << "\n\n"
|
259
|
+
end
|
260
|
+
view << "\nYour account is currently linked to #{bucket.length} channels.\n\n".color(:green)
|
261
|
+
puts view
|
262
|
+
end
|
263
|
+
|
264
|
+
def clear_screen
|
265
|
+
puts "\e[H\e[2J"
|
266
|
+
end
|
267
|
+
|
268
|
+
private
|
269
|
+
|
270
|
+
def get_broadcast_alias_from_id(event_id)
|
271
|
+
al = Databases.get_alias_from_id(event_id)
|
272
|
+
unless al.nil?
|
273
|
+
al
|
274
|
+
else
|
275
|
+
event_id
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
def build_stream_with_index(data, options) #expects an array
|
280
|
+
@view = ""
|
281
|
+
posts = @workers.build_posts(data.reverse)
|
282
|
+
posts.each do |id,content|
|
283
|
+
count = "%03d" % content[:count]
|
284
|
+
if content[:username] == Settings.config[:identity][:username]
|
285
|
+
@view << count.color(Settings.options[:colors][:index]).inverse
|
286
|
+
elsif content[:mentions].include?(Settings.config[:identity][:username]) && options[:in_mentions].nil?
|
287
|
+
@view << count.color(Settings.options[:colors][:mentions]).inverse
|
288
|
+
else
|
289
|
+
@view << count.color(Settings.options[:colors][:index])
|
290
|
+
end
|
291
|
+
@view << ": ".color(Settings.options[:colors][:index])
|
292
|
+
@view << build_content(content)
|
293
|
+
end
|
294
|
+
return posts, @view
|
295
|
+
end
|
296
|
+
|
297
|
+
def build_stream_without_index(data, options) #expects an array
|
298
|
+
@view = ""
|
299
|
+
posts = @workers.build_posts(data.reverse)
|
300
|
+
posts.each do |id,content|
|
301
|
+
if content[:username] == Settings.config[:identity][:username]
|
302
|
+
@view << content[:id].to_s.color(Settings.options[:colors][:id]).inverse + " "
|
303
|
+
elsif content[:mentions].include?(Settings.config[:identity][:username]) && options[:in_mentions].nil?
|
304
|
+
@view << content[:id].to_s.color(Settings.options[:colors][:mentions]).inverse + " "
|
305
|
+
else
|
306
|
+
@view << content[:id].to_s.color(Settings.options[:colors][:id]) + " "
|
307
|
+
end
|
308
|
+
@view << build_content(content)
|
309
|
+
end
|
310
|
+
@view
|
311
|
+
end
|
312
|
+
|
313
|
+
def build_interactions_stream(data)
|
314
|
+
inter = ""
|
315
|
+
data.reverse.each do |event|
|
316
|
+
users_array = []
|
317
|
+
inter << "#{@workers.parsed_time(event['event_date'])}".color(Settings.options[:colors][:date])
|
318
|
+
inter << " => "
|
319
|
+
event['users'].each do |u|
|
320
|
+
users_array << "@" + u['username']
|
321
|
+
end
|
322
|
+
case event['action']
|
323
|
+
when "broadcast_subscribe"
|
324
|
+
broadcast = get_broadcast_alias_from_id(event['objects'][0]['id'])
|
325
|
+
inter << "#{users_array.join(", ")} ".color(:magenta)
|
326
|
+
inter << "subscribed to your broadcast ".color(:green)
|
327
|
+
inter << "#{broadcast}".color(:red)
|
328
|
+
when "broadcast_unsubscribe"
|
329
|
+
broadcast = get_broadcast_alias_from_id(event['objects'][0]['id'])
|
330
|
+
inter << "#{users_array.join(", ")} ".color(:magenta)
|
331
|
+
inter << "unsubscribed from your broadcast ".color(:green)
|
332
|
+
inter << "#{broadcast}".color(:red)
|
333
|
+
when "follow", "unfollow"
|
334
|
+
inter << "#{users_array.join(", ")} ".color(:magenta)
|
335
|
+
inter << "#{event['action']}ed you".color(:green)
|
336
|
+
when "mute", "unmute"
|
337
|
+
inter << "#{users_array.join(", ")} ".color(:magenta)
|
338
|
+
inter << "#{event['action']}d you".color(:green)
|
339
|
+
when "star", "unstar"
|
340
|
+
inter << "#{users_array.join(", ")} ".color(:magenta)
|
341
|
+
inter << "#{event['action']}red post ".color(:green)
|
342
|
+
inter << "#{event['objects'][0]['id']}".color(:red)
|
343
|
+
when "repost", "unrepost"
|
344
|
+
inter << "#{users_array.join(", ")} ".color(:magenta)
|
345
|
+
inter << "#{event['action']}ed post ".color(:green)
|
346
|
+
inter << "#{event['objects'][0]['id']}".color(:red)
|
347
|
+
when "reply"
|
348
|
+
inter << "#{users_array.join(", ")} ".color(:magenta)
|
349
|
+
inter << "replied to post ".color(:green)
|
350
|
+
inter << "#{event['objects'][0]['id']}".color(:red)
|
351
|
+
when "welcome"
|
352
|
+
inter << "App.net ".color(:cyan)
|
353
|
+
inter << "welcomed ".color(:green)
|
354
|
+
inter << "you!".color(:yellow)
|
355
|
+
end
|
356
|
+
inter << "\n\n"
|
357
|
+
end
|
358
|
+
inter
|
359
|
+
end
|
360
|
+
|
361
|
+
def build_files_list(list)
|
362
|
+
data = list.reverse
|
363
|
+
view = "\n"
|
364
|
+
data.each do |file|
|
365
|
+
view << "ID\t\t".color(:cyan)
|
366
|
+
view << file['id'].color(Settings.options[:colors][:id])
|
367
|
+
view << "\n"
|
368
|
+
view << "Name\t\t".color(:cyan)
|
369
|
+
view << file['name'].color(Settings.options[:colors][:name])
|
370
|
+
view << "\n"
|
371
|
+
view << "Kind\t\t".color(:cyan)
|
372
|
+
view << file['kind'].color(Settings.options[:colors][:username])
|
373
|
+
view << " (#{file['mime_type']})".color(Settings.options[:colors][:username]) if file['mime_type']
|
374
|
+
if file['image_info']
|
375
|
+
view << "\n"
|
376
|
+
view << "Dimensions\t".color(:cyan)
|
377
|
+
view << "#{file['image_info']['width']} x #{file['image_info']['height']}".color(Settings.options[:colors][:username])
|
378
|
+
end
|
379
|
+
view << "\n"
|
380
|
+
view << "Size\t\t".color(:cyan)
|
381
|
+
view << file['size'].to_filesize.color(:yellow)
|
382
|
+
view << "\n"
|
383
|
+
view << "Date\t\t".color(:cyan)
|
384
|
+
view << @workers.parsed_time(file['created_at']).color(:green)
|
385
|
+
view << "\n"
|
386
|
+
view << "Source\t\t".color(:cyan)
|
387
|
+
view << file['source']['name'].color(Settings.options[:colors][:source])
|
388
|
+
view << "\n"
|
389
|
+
view << "State\t\t".color(:cyan)
|
390
|
+
if file['public']
|
391
|
+
view << "Public".color(Settings.options[:colors][:id])
|
392
|
+
view << "\n"
|
393
|
+
view << "Link\t\t".color(:cyan)
|
394
|
+
view << file['url_short'].color(Settings.options[:colors][:link])
|
395
|
+
else
|
396
|
+
view << "Private".color(Settings.options[:colors][:id])
|
397
|
+
end
|
398
|
+
|
399
|
+
view << "\n\n"
|
400
|
+
end
|
401
|
+
view
|
402
|
+
end
|
403
|
+
|
404
|
+
def build_content(content)
|
405
|
+
view = ""
|
406
|
+
view << build_header(content)
|
407
|
+
view << "\n"
|
408
|
+
view << content[:text]
|
409
|
+
view << "\n"
|
410
|
+
if content[:has_checkins]
|
411
|
+
view << build_checkins(content)
|
412
|
+
view << "\n"
|
413
|
+
end
|
414
|
+
unless content[:links].empty?
|
415
|
+
view << "\n"
|
416
|
+
content[:links].each do |link|
|
417
|
+
view << link.color(Settings.options[:colors][:link])
|
418
|
+
view << "\n"
|
419
|
+
end
|
420
|
+
end
|
421
|
+
view << "\n\n"
|
422
|
+
end
|
423
|
+
|
424
|
+
def build_header(content)
|
425
|
+
header = ""
|
426
|
+
header << content[:handle].color(Settings.options[:colors][:username])
|
427
|
+
if Settings.options[:timeline][:show_real_name]
|
428
|
+
header << " "
|
429
|
+
header << content[:name].color(Settings.options[:colors][:name])
|
430
|
+
end
|
431
|
+
if Settings.options[:timeline][:show_date]
|
432
|
+
header << " "
|
433
|
+
header << content[:date].color(Settings.options[:colors][:date])
|
434
|
+
end
|
435
|
+
if Settings.options[:timeline][:show_source]
|
436
|
+
header << " "
|
437
|
+
header << "[#{content[:source_name]}]".color(Settings.options[:colors][:source])
|
438
|
+
end
|
439
|
+
if Settings.options[:timeline][:show_symbols]
|
440
|
+
header << " <".color(Settings.options[:colors][:symbols]) if content[:is_reply]
|
441
|
+
header << " #{content[:num_stars]}*".color(Settings.options[:colors][:symbols]) if content[:is_starred]
|
442
|
+
header << " >".color(Settings.options[:colors][:symbols]) if content[:num_replies] > 0
|
443
|
+
header << " #{content[:num_reposts]}x".color(Settings.options[:colors][:symbols]) if content[:num_reposts] > 0
|
444
|
+
end
|
445
|
+
header << "\n"
|
446
|
+
end
|
447
|
+
|
448
|
+
def build_checkins(content)
|
449
|
+
unless content[:checkins][:name].nil?
|
450
|
+
num_dots = content[:checkins][:name].length
|
451
|
+
else
|
452
|
+
num_dots = 10
|
453
|
+
end
|
454
|
+
hd = (".".color(Settings.options[:colors][:dots])) * num_dots
|
455
|
+
hd << "\n"
|
456
|
+
formatted = { header: hd }
|
457
|
+
content[:checkins].each do |key, val|
|
458
|
+
formatted[key] = val unless (val.nil? || !val)
|
459
|
+
end
|
460
|
+
|
461
|
+
chk = formatted[:header]
|
462
|
+
unless formatted[:name].nil?
|
463
|
+
chk << formatted[:name].color(Settings.options[:colors][:dots])
|
464
|
+
chk << "\n"
|
465
|
+
end
|
466
|
+
unless formatted[:address].nil?
|
467
|
+
chk << formatted[:address]
|
468
|
+
chk << "\n"
|
469
|
+
end
|
470
|
+
unless formatted[:address_extended].nil?
|
471
|
+
chk << formatted[:address_extended]
|
472
|
+
chk << "\n"
|
473
|
+
end
|
474
|
+
unless formatted[:country_code].nil?
|
475
|
+
cc = "(#{formatted[:country_code]})".upcase
|
476
|
+
else
|
477
|
+
cc = ""
|
478
|
+
end
|
479
|
+
unless formatted[:postcode].nil?
|
480
|
+
unless formatted[:locality].nil?
|
481
|
+
chk << "#{formatted[:postcode]}, #{formatted[:locality]} #{cc}"
|
482
|
+
chk << "\n"
|
483
|
+
end
|
484
|
+
else
|
485
|
+
unless formatted[:locality].nil?
|
486
|
+
chk << "#{formatted[:locality]} #{cc}"
|
487
|
+
chk << "\n"
|
488
|
+
end
|
489
|
+
end
|
490
|
+
unless formatted[:website].nil?
|
491
|
+
chk << formatted[:website]
|
492
|
+
chk << "\n"
|
493
|
+
end
|
494
|
+
unless formatted[:telephone].nil?
|
495
|
+
chk << formatted[:telephone]
|
496
|
+
chk << "\n"
|
497
|
+
end
|
498
|
+
unless formatted[:categories].nil?
|
499
|
+
chk << formatted[:categories]
|
500
|
+
chk << "\n"
|
501
|
+
end
|
502
|
+
|
503
|
+
chk.chomp
|
504
|
+
end
|
505
|
+
|
506
|
+
end
|
507
|
+
end
|