ayadn 0.6.4 → 1.0.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.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +20 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +17 -0
  5. data/Gemfile +14 -0
  6. data/Guardfile +26 -0
  7. data/LICENSE.txt +22 -0
  8. data/MANUAL.md +946 -0
  9. data/README.md +26 -411
  10. data/Rakefile +6 -0
  11. data/ayadn.gemspec +39 -0
  12. data/bin/ayadn +3 -3
  13. data/lib/ayadn.rb +12 -25
  14. data/lib/ayadn/action.rb +1121 -0
  15. data/lib/ayadn/alias.rb +106 -0
  16. data/lib/ayadn/api.rb +312 -301
  17. data/lib/ayadn/app.rb +429 -365
  18. data/lib/ayadn/authorize.rb +127 -28
  19. data/lib/ayadn/blacklist.rb +116 -0
  20. data/lib/ayadn/cnx.rb +105 -0
  21. data/lib/ayadn/databases.rb +110 -0
  22. data/lib/ayadn/descriptions.rb +1043 -0
  23. data/lib/ayadn/endpoints.rb +220 -153
  24. data/lib/ayadn/errors.rb +37 -0
  25. data/lib/ayadn/extend.rb +4 -10
  26. data/lib/ayadn/fileops.rb +48 -0
  27. data/lib/ayadn/logs.rb +32 -0
  28. data/lib/ayadn/pinboard.rb +46 -35
  29. data/lib/ayadn/post.rb +229 -212
  30. data/lib/ayadn/scroll.rb +251 -0
  31. data/lib/ayadn/set.rb +377 -0
  32. data/lib/ayadn/settings.rb +195 -0
  33. data/lib/ayadn/status.rb +226 -165
  34. data/lib/ayadn/switch.rb +72 -0
  35. data/lib/ayadn/version.rb +4 -0
  36. data/lib/ayadn/view.rb +506 -269
  37. data/lib/ayadn/workers.rb +362 -0
  38. data/spec/helpers.rb +19 -0
  39. data/spec/mock/@ericd.json +160 -0
  40. data/spec/mock/@m.json +45 -0
  41. data/spec/mock/checkins.json +1856 -0
  42. data/spec/mock/fwr_@ayadn.json +1077 -0
  43. data/spec/mock/posted.json +1 -0
  44. data/spec/mock/stream.json +1 -0
  45. data/spec/spec_helper.rb +14 -0
  46. data/spec/unit/api_spec.rb +61 -0
  47. data/spec/unit/databases_spec.rb +5 -0
  48. data/spec/unit/descriptions_spec.rb +9 -0
  49. data/spec/unit/endpoints_spec.rb +35 -0
  50. data/spec/unit/post_spec.rb +136 -0
  51. data/spec/unit/status_spec.rb +9 -0
  52. data/spec/unit/view_spec.rb +119 -0
  53. data/spec/unit/workers_spec.rb +147 -0
  54. metadata +216 -40
  55. data/CHANGELOG.md +0 -250
  56. data/CONTRIBUTORS.md +0 -5
  57. data/LICENSE.md +0 -14
  58. data/lib/ayadn/adn_files.rb +0 -84
  59. data/lib/ayadn/client-http.rb +0 -226
  60. data/lib/ayadn/colors.rb +0 -62
  61. data/lib/ayadn/config.yml +0 -35
  62. data/lib/ayadn/debug.rb +0 -36
  63. data/lib/ayadn/files.rb +0 -184
  64. data/lib/ayadn/get-api.rb +0 -43
  65. data/lib/ayadn/help.rb +0 -152
  66. data/lib/ayadn/list.rb +0 -89
  67. data/lib/ayadn/main.rb +0 -542
  68. data/lib/ayadn/requires.rb +0 -12
  69. data/lib/ayadn/skip.rb +0 -27
  70. data/lib/ayadn/tools.rb +0 -208
  71. data/lib/ayadn/user-stream.rb +0 -91
  72. data/lib/ayadn/view-channels.rb +0 -120
  73. data/lib/ayadn/view-interactions.rb +0 -57
  74. data/lib/ayadn/view-object.rb +0 -195
  75. data/lib/experiments.rb +0 -109
@@ -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
@@ -0,0 +1,4 @@
1
+ # encoding: utf-8
2
+ module Ayadn
3
+ VERSION = "1.0.0"
4
+ end
data/lib/ayadn/view.rb CHANGED
@@ -1,270 +1,507 @@
1
- #!/usr/bin/env ruby
2
1
  # encoding: utf-8
3
- class AyaDN
4
- class View
5
- def initialize(hash)
6
- @hash = hash
7
- end
8
- def getData(hash)
9
- hash['data'].reverse
10
- end
11
- def getDataNormal(hash)
12
- hash['data']
13
- end
14
- def showMessagesFromChannel
15
- buildMessages(getData(@hash))
16
- end
17
- def showStream
18
- $tools.config['timeline']['downside'] ? the_hash = getData(@hash) : the_hash = getDataNormal(@hash)
19
- buildStream(the_hash)
20
- end
21
- def showCompleteStream
22
- $tools.config['timeline']['downside'] ? the_hash = getData(@hash) : the_hash = getDataNormal(@hash)
23
- stream, pagination_array = buildCompleteStream(the_hash)
24
- end
25
- def show_pm_channels
26
- stream, pagination_array = build_pm_channels_infos
27
- end
28
- def show_channels
29
- stream, pagination_array = build_channels_infos
30
- end
31
- def showDebugStream
32
- begin
33
- puts "\n"
34
- jj getDataNormal(@hash)
35
- rescue => e
36
- puts "\n"
37
- jj @hash
38
- puts e.inspect
39
- end
40
- end
41
- def showUsersList
42
- buildUsersList(getDataNormal(@hash))
43
- end
44
- def showInteractions
45
- buildInteractions(getData(@hash))
46
- end
47
- def showUsers
48
- users = ""
49
- @hash = @hash.sort_by {|id, arr| arr[0]}
50
- @hash.each do |id, arr|
51
- users << "#{arr[0]} ".red.ljust(30) + "#{arr[1]}\n".green
52
- end
53
- return users, @hash.length
54
- end
55
- def showUsersInfos(name)
56
- buildUserInfos(name, getDataNormal(@hash))
57
- end
58
- def showPostInfos(post_id, is_mine)
59
- buildPostInfo(getDataNormal(@hash), is_mine)
60
- end
61
- def showFileInfo(with_url)
62
- buildFileInfo(getDataNormal(@hash), with_url)
63
- end
64
- def buildStream(post_hash)
65
- post_string = "\n"
66
- post_string << post_hash.map {|item| create_content_string(item, nil, false)}
67
- return post_string
68
- end
69
- def buildMessages(messages_stream)
70
- messages_string = "\n"
71
- for item in messages_stream do
72
- @source_name_and_link = objectSource(item)
73
- messages_string << create_content_string(item, checkins_annotations(item), false) # create_content_string(item, annotations, me_mentioned)
74
- end
75
- last_viewed = messages_stream.last
76
- last_id = last_viewed['pagination_id'] unless last_viewed == nil
77
- return messages_string, last_id
78
- end
79
- def buildCompleteStream(post_hash)
80
- post_string = ""
81
- pagination_array = []
82
- saved_tags = []
83
- if $tools.config['skipped']['hashtags'] != nil
84
- saved_tags = $tools.config['skipped']['hashtags'].map {|tag| tag.downcase}
85
- end
86
- for item in post_hash do
87
- pagination_array.push(item['pagination_id'])
88
- next if item['text'] == nil
89
- @source_name_and_link = objectSource(item)
90
- case @source_name_and_link[:name]
91
- when *$tools.config['skipped']['sources']
92
- next
93
- end
94
- next if skip_hashtags(item, saved_tags)
95
- postMentionsArray = []
96
- @skipped_mentions_encountered = false
97
- for mention in item['entities']['mentions'] do
98
- case mention['name']
99
- when *$tools.config['skipped']['mentions']
100
- @skipped_mentions_encountered = true
101
- next
102
- end
103
- postMentionsArray.push(mention['name'])
104
- end
105
- next if @skipped_mentions_encountered
106
- me_mentioned = false
107
- for name in postMentionsArray do
108
- if name == ($tools.config['identity']['prefix'] || $files.users_read("me"))
109
- me_mentioned = true
110
- end
111
- end
112
- post_string << create_content_string(item, checkins_annotations(item), me_mentioned)
113
- end
114
- return post_string, pagination_array
115
- end
116
- def buildSimplePost(post_hash)
117
- create_content_string(post_hash, nil, false)
118
- end
119
- def buildSimplePostInfo(post_hash)
120
- #the_post_id = post_hash['id']
121
- post_text = post_hash['text']
122
- post_URL = post_hash['canonical_url']
123
- post_details = "\nPost URL: ".cyan + post_URL.brown + "\n"
124
- is_reply = post_hash['reply_to']
125
- post_details << ("This post is a reply to post ".cyan + is_reply.brown + "\n") if is_reply != nil
126
- if post_text != nil
127
- without_braces = $tools.withoutSquareBraces($tools.getMarkdownText(post_text.dup))
128
- post_details << "\nLength: ".cyan + without_braces.length.to_s.reddish
129
- end
130
- return post_details + "\n\n"
131
- end
132
- def buildPostInfo(post_hash, is_mine)
133
- post_text = post_hash['text']
134
- post_text != nil ? (colored_post = $tools.colorize(post_text)) : (puts "\n--Post deleted--\n\n".red; exit)
135
- params = objectNames(post_hash['user'])
136
- created_day, created_hour = objectDate(post_hash)
137
- post_details = "\n" + created_day.cyan + ' ' + created_hour.cyan + ' ' + params[:user_handle].green
138
- post_details << (" [#{params[:user_real_name]}]".reddish) if !params[:user_real_name].empty?
139
- post_details << " (follows you)".blue if post_hash['user']['follows_you']
140
- post_details << " (you follow)".blue if post_hash['user']['you_follow']
141
- unless post_hash['user']['follows_you'] || post_hash['user']['you_follow']
142
- post_details << " (you don't follow, doesn't follow you)".blue unless params[:user_name] == $tools.config['identity']['prefix']
143
- end
144
- post_details << "\n"
145
- post_details << "\n" + colored_post + "\n\n"
146
- post_details << "ID: ".cyan + post_hash['id'].to_s.green + "\n"
147
- post_details << objectLinks(post_hash)
148
- post_details << "Post URL: ".cyan + post_hash['canonical_url'].brown
149
- is_reply = post_hash['reply_to']
150
- repost_of = post_hash['repost_of']
151
- post_details << ("\nThis post is a reply to post ".cyan + is_reply.brown) if is_reply != nil
152
- if is_mine == false
153
- if repost_of != nil
154
- post_details << "\nThis post is a repost of post ".cyan + repost_of['id'].brown
155
- else
156
- post_details << "\nReplies: ".cyan + post_hash['num_replies'].to_s.reddish
157
- post_details << " Reposts: ".cyan + post_hash['num_reposts'].to_s.reddish
158
- post_details << " Stars: ".cyan + post_hash['num_stars'].to_s.reddish
159
- end
160
- post_details << ("\nYou reposted this post.".cyan) if post_hash['you_reposted']
161
- post_details << ("\nYou starred this post.".cyan) if post_hash['you_starred']
162
- post_details << "\nPosted with: ".cyan + post_hash['source']['name'].reddish
163
- post_details << " Locale: ".cyan + post_hash['user']['locale'].reddish
164
- post_details << " Timezone: ".cyan + post_hash['user']['timezone'].reddish
165
- else
166
- without_braces = $tools.withoutSquareBraces($tools.getMarkdownText(post_text.dup))
167
- post_details << "\nLength: ".cyan + without_braces.length.to_s.reddish
168
- end
169
- post_details << "\n\n\n"
170
- end
171
- def buildUsersList(users_hash)
172
- users_string = "\n"
173
- users_hash.each do |item|
174
- param = objectNames(item)
175
- users_string << param[:user_real_name].green + " #{param[:user_handle]}\n".cyan
176
- end
177
- users_string << "\n\n"
178
- end
179
- def buildFollowList
180
- users_hash = {}
181
- @hash['data'].each do |item|
182
- user_handle = "@" + item['username']
183
- users_hash[item['id']] = [user_handle, item['name']]
184
- end
185
- return users_hash, @hash['meta']['min_id']
186
- end
187
- def buildFileInfo(resp_hash, with_url)
188
- files_details_hash = filesDetails(resp_hash)
189
- #file_url_expires = resp_hash['url_expires']
190
- #derived_files = resp_hash['derived_files']
191
- list_string = file_view(files_details_hash)
192
- if files_details_hash[:file_is_public]
193
- list_string << "\nThis file is ".cyan + "public".blue
194
- file_url = files_details_hash[:file_url]
195
- else
196
- list_string << "\nThis file is ".cyan + "private".red
197
- file_url = resp_hash['url']
198
- end
199
- if with_url
200
- list_string << "\nURL: ".cyan + file_url
201
- #list_string << derivedFilesDetails(derived_files)
202
- end
203
- list_string << "\n\n"
204
- return list_string, file_url, files_details_hash[:name]
205
- end
206
- def showFilesList(with_url, reverse)
207
- reverse ? resp_hash = getDataNormal(@hash) : resp_hash = getData(@hash)
208
- list_string = ""
209
- file_url = nil
210
- pagination_array = []
211
- resp_hash.each do |item|
212
- pagination_array.push(item['pagination_id'])
213
- files_details_hash = filesDetails(item)
214
- #file_url_expires = item['url_expires']
215
- #derived_files = item['derived_files']
216
- list_string << "\nID: ".cyan + files_details_hash[:id].brown
217
- list_string << file_view(files_details_hash)
218
- if files_details_hash[:file_is_public]
219
- list_string << "\nThis file is ".cyan + "public".blue
220
- list_string << "\nLink: ".cyan + item['url_permanent'].magenta
221
- else
222
- list_string << "\nThis file is ".cyan + "private".red
223
- if with_url
224
- file_url = item['url']
225
- list_string << "\nURL: ".cyan + file_url.brown
226
- #list_string << derivedFilesDetails(derived_files)
227
- end
228
- end
229
- list_string << "\n"
230
- end
231
- list_string << "\n"
232
- return list_string, file_url, pagination_array
233
- end
234
- def buildUserInfos(name, adn_data)
235
- name_params = objectNames(adn_data)
236
- $files.users_write("me", name_params[:user_name]) if name == "me"
237
- $files.users_write(adn_data['id'], name_params[:user_name]) if $files.users_read(adn_data['id']) == nil
238
- created_at = adn_data['created_at']
239
- user_show = "\nID: ".cyan.ljust(22) + adn_data['id'].green + "\n"
240
- user_show << ("Name: ".cyan.ljust(21) + name_params[:user_real_name].green + "\n") if name_params[:user_real_name] != nil
241
- adn_data['description'] != nil ? user_descr = adn_data['description']['text'] : user_descr = "No description available.".cyan
242
- user_timezone = adn_data['timezone']
243
- user_show << ("Timezone: ".cyan.ljust(21) + user_timezone.green + "\n") if user_timezone != nil
244
- locale = adn_data['locale']
245
- user_show << ("Locale: ".cyan.ljust(21) + locale.green + "\n") if locale != nil
246
- user_show << "Posts: ".cyan.ljust(21) + adn_data['counts']['posts'].to_s.green + "\n" + "Followers: ".cyan.ljust(21) + adn_data['counts']['followers'].to_s.green + "\n" + "Following: ".cyan.ljust(21) + adn_data['counts']['following'].to_s.green + "\n"
247
- user_show << "Web: ".cyan.ljust(21) + "http://".green + adn_data['verified_domain'].green + "\n" if adn_data['verified_domain'] != nil
248
- user_show << "Joined: ".cyan.ljust(21) + created_at[0...10].green + " " + created_at[11...19].green + "\n"
249
- user_show << "\n"
250
- user_show << name_params[:user_handle].brown
251
- if name != "me"
252
- if adn_data['follows_you']
253
- user_show << " follows you\n".green
254
- else
255
- user_show << " doesn't follow you\n".reddish
256
- end
257
- if adn_data['you_follow']
258
- user_show << "You follow ".green + name_params[:user_handle].brown + "\n"
259
- else
260
- user_show << "You don't follow ".reddish + name_params[:user_handle].brown + "\n"
261
- end
262
- user_show << ("You muted ".reddish + name_params[:user_handle].brown + "\n") if adn_data['you_muted']
263
- else
264
- user_show << " => " + "yourself!".brown + "\n"
265
- end
266
- user_show << "\n"
267
- user_show << "Bio: \n\n".cyan + user_descr + "\n\n"
268
- end
269
- end
270
- end
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