Class: Ayadn::View
- Inherits:
-
Object
- Object
- Ayadn::View
- Defined in:
- lib/ayadn/view.rb
Instance Method Summary collapse
- #all_hashtag_links(stream, hashtag) ⇒ Object
- #all_search_links(stream, words) ⇒ Object
- #all_stars_links(stream) ⇒ Object
- #big_separator ⇒ Object
- #clear_screen ⇒ Object
- #downloading(options = {}) ⇒ Object
- #get(stream, options = {}, niceranks = {}) ⇒ Object
- #get_simple_view(stream) ⇒ Object
- #if_raw(what, options) ⇒ Object
- #infos(stream, token) ⇒ Object
-
#initialize ⇒ View
constructor
A new instance of View.
- #list(what, list, target) ⇒ Object
- #page(msg) ⇒ Object
- #render(stream, options = {}, niceranks = {}) ⇒ Object
- #show_channels(resp, options = {}) ⇒ Object
- #show_files_list(list) ⇒ Object
- #show_interactions(stream) ⇒ Object
- #show_links(links) ⇒ Object
- #show_list_blocked(list) ⇒ Object
- #show_list_followers(list, target) ⇒ Object
- #show_list_followings(list, target) ⇒ Object
- #show_list_muted(list) ⇒ Object
- #show_list_reposted(list, target) ⇒ Object
- #show_list_starred(list, target) ⇒ Object
- #show_posted(resp) ⇒ Object
- #show_posts(data, options, niceranks = {}) ⇒ Object
- #show_posts_with_index(data, options, niceranks = {}) ⇒ Object
- #show_raw(stream, options = {}) ⇒ Object
- #show_settings ⇒ Object
- #show_simple_post(post, options) ⇒ Object
- #show_simple_stream(stream) ⇒ Object
- #show_userinfos(content, token, show_ranks = false) ⇒ Object
- #winsize ⇒ Object
Constructor Details
Instance Method Details
#all_hashtag_links(stream, hashtag) ⇒ Object
326 327 328 329 330 |
# File 'lib/ayadn/view.rb', line 326 def all_hashtag_links(stream, hashtag) clear_screen() puts "Links from posts containing hashtag '##{hashtag}': \n".color(:cyan) show_links(@workers.links_from_posts(stream)) end |
#all_search_links(stream, words) ⇒ Object
332 333 334 335 336 |
# File 'lib/ayadn/view.rb', line 332 def all_search_links(stream, words) clear_screen() puts "Links from posts containing word(s) '#{words}': \n".color(:cyan) show_links(@workers.links_from_posts(stream)) end |
#all_stars_links(stream) ⇒ Object
338 339 340 341 342 |
# File 'lib/ayadn/view.rb', line 338 def all_stars_links(stream) clear_screen() puts "Links from your starred posts: \n".color(:cyan) show_links(@workers.links_from_posts(stream)) end |
#big_separator ⇒ Object
374 375 376 |
# File 'lib/ayadn/view.rb', line 374 def big_separator "----------\n\n\n" end |
#clear_screen ⇒ Object
308 309 310 |
# File 'lib/ayadn/view.rb', line 308 def clear_screen puts "\e[H\e[2J" end |
#downloading(options = {}) ⇒ Object
349 350 351 352 353 354 |
# File 'lib/ayadn/view.rb', line 349 def downloading( = {}) unless [:raw] clear_screen() print Status.downloading end end |
#get(stream, options = {}, niceranks = {}) ⇒ Object
294 295 296 297 298 299 300 301 |
# File 'lib/ayadn/view.rb', line 294 def get(stream, = {}, niceranks = {}) clear_screen() if [:index] show_posts_with_index(stream, , niceranks) else show_posts(stream, , niceranks) end end |
#get_simple_view(stream) ⇒ Object
303 304 305 306 |
# File 'lib/ayadn/view.rb', line 303 def get_simple_view(stream) clear_screen() show_simple_stream(stream) end |
#if_raw(what, options) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/ayadn/view.rb', line 20 def if_raw what, if [:raw] show_raw(what, ) exit end end |
#infos(stream, token) ⇒ Object
344 345 346 347 |
# File 'lib/ayadn/view.rb', line 344 def infos(stream, token) clear_screen() show_userinfos(stream, token, true) end |
#list(what, list, target) ⇒ Object
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/ayadn/view.rb', line 356 def list(what, list, target) clear_screen() case what when :whoreposted show_list_reposted(list, target) when :whostarred show_list_starred(list, target) when :followings show_list_followings(list, target) when :followers show_list_followers(list, target) when :muted show_list_muted(list) when :blocked show_list_blocked(list) end end |
#page(msg) ⇒ Object
312 313 314 315 316 |
# File 'lib/ayadn/view.rb', line 312 def page msg clear_screen puts msg puts "\n" end |
#render(stream, options = {}, niceranks = {}) ⇒ Object
286 287 288 289 290 291 292 |
# File 'lib/ayadn/view.rb', line 286 def render(stream, = {}, niceranks = {}) unless [:raw] get(stream['data'], , niceranks) else show_raw(stream) end end |
#show_channels(resp, options = {}) ⇒ Object
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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/ayadn/view.rb', line 204 def show_channels(resp, = {}) view = "" bucket = @workers.build_channels(resp['data'], ) bucket.reverse.each do |ch| view << "\n" ch_alias = false Databases.aliases.each do |k,v| if v == "#{ch.id}" ch_alias = k break end end view << "ID: ".color(:cyan) view << "#{ch.id}".color(Settings.[:colors][:id]) view << "\n" if ch_alias view << "Alias: ".color(:cyan) view << "#{ch_alias}".color(Settings.[:colors][:username]) view << "\n" end view << "Messages: ".color(:cyan) view << "#{ch.}".color(Settings.[:colors][:symbols]) view << "\n" if ch.owner view << "Owner: ".color(:cyan) view << "@#{ch.owner['username']}".color(Settings.[:colors][:username]) # + (#{ch.owner['name']}) if ch.owner['name'] view << "\n" end unless [:channels] # unless the request comes from Search view << "Writers: ".color(:cyan) view << "#{ch.writers}".color(Settings.[:colors][:name]) view << "\n" end view << "Type: ".color(:cyan) view << "#{ch.type}".color(Settings.[:colors][:id]) view << "\n" if ch.type == "net.patter-app.room" ann = ch.annotations.select {|a| a['type'] == "net.patter-app.settings"} view << "Name: ".color(:cyan) view << "#{ann[0]['value']['name']}".color(Settings.[:colors][:link]) view << "\n" view << "Description: ".color(:cyan) view << "#{ann[0]['value']['blurb']}".color(Settings.[:colors][:username]) view << "\n" ann = ch.annotations.select {|a| a['type'] == "net.app.core.fallback_url"} view << "URL: ".color(:cyan) view << "#{ann[0]['value']['url']}".color(Settings.[:colors][:link]) view << "\n" end if ch.type == "net.app.core.broadcast" ann = ch.annotations.select {|a| a['type'] == "net.app.core.broadcast.metadata"} view << "Title: ".color(:cyan) view << "#{ann[0]['value']['title']}".color(Settings.[:colors][:link]) view << "\n" view << "Description: ".color(:cyan) view << "#{ann[0]['value']['description']}".color(Settings.[:colors][:username]) view << "\n" ann = ch.annotations.select {|a| a['type'] == "net.app.core.fallback_url"} view << "URL: ".color(:cyan) view << "#{ann[0]['value']['url']}".color(Settings.[:colors][:link]) view << "\n" end unless ch..nil? unless ch.['text'].nil? view << "Most recent message (#{@workers.parsed_time(ch.['created_at'])}): ".color(:cyan) view << "\n" view << "---\n#{ch.['text']}\n---" end end if ch.type == "net.paste-app.clips" ann = ch.['annotations'].select {|a| a['type'] == "net.paste-app.clip"} view << "\n\n" view << ann[0]['value']['content'] view << "\n" end view << "\n\n" end view << "\nYour account is currently linked to #{bucket.length} channels.\n\n".color(:green) unless [:channels] puts view end |
#show_files_list(list) ⇒ Object
81 82 83 |
# File 'lib/ayadn/view.rb', line 81 def show_files_list(list) puts build_files_list(list) end |
#show_interactions(stream) ⇒ Object
76 77 78 79 |
# File 'lib/ayadn/view.rb', line 76 def show_interactions(stream) #puts "\n" puts build_interactions_stream(stream) end |
#show_links(links) ⇒ Object
322 323 324 |
# File 'lib/ayadn/view.rb', line 322 def show_links(links) links.each {|l| puts "#{l}\n".color(Settings.[:colors][:link])} end |
#show_list_blocked(list) ⇒ Object
71 72 73 74 |
# File 'lib/ayadn/view.rb', line 71 def show_list_blocked(list) puts @workers.build_blocked_list(list) puts "\n" end |
#show_list_followers(list, target) ⇒ Object
61 62 63 64 |
# File 'lib/ayadn/view.rb', line 61 def show_list_followers(list, target) puts @workers.build_followers_list(list, target) puts "\n" end |
#show_list_followings(list, target) ⇒ Object
56 57 58 59 |
# File 'lib/ayadn/view.rb', line 56 def show_list_followings(list, target) puts @workers.build_followings_list(list, target) puts "\n" end |
#show_list_muted(list) ⇒ Object
66 67 68 69 |
# File 'lib/ayadn/view.rb', line 66 def show_list_muted(list) puts @workers.build_muted_list(list) puts "\n" end |
#show_list_reposted(list, target) ⇒ Object
44 45 46 47 48 |
# File 'lib/ayadn/view.rb', line 44 def show_list_reposted(list, target) users_list, table = @workers.build_reposted_list(list, target) puts @workers.build_users_list(users_list, table) puts "\n" end |
#show_list_starred(list, target) ⇒ Object
50 51 52 53 54 |
# File 'lib/ayadn/view.rb', line 50 def show_list_starred(list, target) users_list, table = @workers.build_starred_list(list, target) puts @workers.build_users_list(users_list, table) puts "\n" end |
#show_posted(resp) ⇒ Object
36 37 38 |
# File 'lib/ayadn/view.rb', line 36 def show_posted(resp) show_simple_post([resp['data']], {}) end |
#show_posts(data, options, niceranks = {}) ⇒ Object
15 16 17 18 |
# File 'lib/ayadn/view.rb', line 15 def show_posts(data, , niceranks = {}) resp = build_stream_without_index(data, , niceranks) puts resp unless resp == "" end |
#show_posts_with_index(data, options, niceranks = {}) ⇒ Object
9 10 11 12 13 |
# File 'lib/ayadn/view.rb', line 9 def show_posts_with_index(data, , niceranks = {}) posts, view = build_stream_with_index(data, , niceranks) puts view unless view == "" Databases.save_indexed_posts(posts) end |
#show_raw(stream, options = {}) ⇒ Object
27 28 29 30 |
# File 'lib/ayadn/view.rb', line 27 def show_raw(stream, = {}) #puts stream.to_json jj stream end |
#show_settings ⇒ Object
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 |
# File 'lib/ayadn/view.rb', line 85 def show_settings table = Terminal::Table.new do |t| t.style = { :width => Settings.[:formats][:table][:width], border_x: ' ', border_i: ' ', border_y: ' ' } t.title = "Current Ayadn settings".color(:cyan) t.headings = [ "Category".color(:red), "Parameter".color(:red), "Value(s)".color(:red) ] @iter = 0 opts = Settings..dup opts.each do |k,v| v.delete_if {|ke,_| ke == :deleted || ke == :annotations} # don't show immutable values v.each do |x,y| t << :separator if @iter >= 1 unless y.is_a?(Hash) t << [ k.to_s.color(:cyan), x.to_s.color(:yellow), y.to_s.color(:green) ] else y.each do |c| t << [ k.to_s.color(:cyan), x.to_s.color(:yellow), "#{c[0]} = #{c[1]}".color(:green) ] end end @iter += 1 end end end clear_screen() puts table end |
#show_simple_post(post, options) ⇒ Object
32 33 34 |
# File 'lib/ayadn/view.rb', line 32 def show_simple_post(post, ) puts build_stream_without_index(post, , {}) end |
#show_simple_stream(stream) ⇒ Object
40 41 42 |
# File 'lib/ayadn/view.rb', line 40 def show_simple_stream(stream) puts stream end |
#show_userinfos(content, token, show_ranks = false) ⇒ Object
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 |
# File 'lib/ayadn/view.rb', line 111 def show_userinfos(content, token, show_ranks = false) if content['name'] view = "Name\t\t\t".color(:cyan) + content['name'].color(Settings.[:colors][:name]) else view = "Name\t\t\t".color(:cyan) + "(no name)".color(:red) end view << "\n\nUsername\t\t".color(:cyan) + "@#{content['username']}".color(Settings.[:colors][:id]) view << "\n\nID\t\t\t".color(:cyan) + content['id'].color(Settings.[:colors][:username]) view << "\n\nURL\t\t\t".color(:cyan) + content['canonical_url'].color(Settings.[:colors][:link]) unless content['verified_domain'].nil? if content['verified_domain'] =~ (/http/ || /https/) domain = content['verified_domain'] else domain = "http://#{content['verified_domain']}" end view << "\nVerified domain\t\t".color(:cyan) + domain.color(Settings.[:colors][:link]) end view << "\n\nAccount creation\t".color(:cyan) + @workers.parsed_time(content['created_at']).color(:green) view << "\n\nTimeZone\t\t".color(:cyan) + content['timezone'].color(:green) view << "\nLocale\t\t\t".color(:cyan) + content['locale'].color(:green) view << "\n\nPosts\t\t\t".color(:cyan) + content['counts']['posts'].to_s.color(:green) unless show_ranks == false # this is ok for one user, but do not call this in a loop # do call them all at once instead if many ranks = NiceRank.new.get_posts_day([content['id'].to_i]) unless ranks.empty? view << "\n\nPosts/day\t\t".color(:cyan) + ranks[0][:posts_day].to_s.color(:green) end end view << "\n\nFollowing\t\t".color(:cyan) + content['counts']['following'].to_s.color(:green) view << "\nFollowers\t\t".color(:cyan) + content['counts']['followers'].to_s.color(:green) if content['username'] == Settings.config[:identity][:username] && !token.nil? view << "\n\nStorage used\t\t".color(:cyan) + "#{token['storage']['used'].to_filesize}".color(:red) view << "\nStorage available\t".color(:cyan) + "#{token['storage']['available'].to_filesize}".color(:green) end #view << "\nStars\t\t\t".color(:cyan) + content['counts']['stars'].to_s.color(:yellow) unless content['username'] == Settings.config[:identity][:username] if content['you_follow'] view << "\n\nYou follow ".color(:cyan) + "@#{content['username']}".color(Settings.[:colors][:username]) else view << "\n\nYou don't follow ".color(:cyan) + "@#{content['username']}".color(Settings.[:colors][:username]) end if content['follows_you'] view << "\n" + "@#{content['username']}".color(Settings.[:colors][:username]) + " follows you".color(:cyan) else view << "\n" + "@#{content['username']}".color(Settings.[:colors][:username]) + " doesn't follow you".color(:cyan) end if content['you_muted'] view << "\nYou muted " + "@#{content['username']}".color(Settings.[:colors][:username]) end if content['you_blocked'] view << "\nYou blocked " + "@#{content['username']}".color(Settings.[:colors][:username]) end end unless content['annotations'].empty? view << "\n" end content['annotations'].each do |anno| case anno['type'] when "net.app.core.directory.blog" view << "\nBlog\t\t\t".color(:cyan) + "#{anno['value']['url']}".color(Settings.[:colors][:link]) when "net.app.core.directory.twitter" view << "\nTwitter\t\t\t".color(:cyan) + "#{anno['value']['username']}".color(:green) when "com.appnetizens.userinput.birthday" view << "\nBirthday\t\t".color(:cyan) + "#{anno['value']['birthday']}".color(:green) end end #view << "\n\nAvatar URL\t\t".color(:cyan) + content['avatar_image']['url'] if content['description'] view << "\n\n#{content['description']['text']}\n".color(:magenta) + "\n\n" end puts view end |
#winsize ⇒ Object
318 319 320 |
# File 'lib/ayadn/view.rb', line 318 def winsize IO.console.winsize end |