lib/TokiCLI/app.rb in TokiCLI-0.0.1 vs lib/TokiCLI/app.rb in TokiCLI-0.0.2
- old
+ new
@@ -5,57 +5,66 @@
%w{get_messages search_messages get_channels module status view}.each {|r| require_relative "#{r}"}
desc "total", "Shows the total usage of all apps"
option :adn, aliases: '-a', type: :boolean, desc: 'Select ADN channel as source (toki total -a)'
def total
- if options[:adn]
- toki = total_adn
- else
- toki = total_db
- end
+ toki = create_toki(options)
get_total(toki, options)
end
+ desc "top", "Shows your most used apps"
+ option :adn, aliases: '-a', type: :boolean, desc: 'Select ADN channel as source (toki top -a)'
+ option :number, aliases: '-n', type: :numeric, desc: 'Specifi the number of apps (toki top -n 10)'
+ def top
+ toki = create_toki(options)
+ entries = toki.get_content(options)
+ clear
+ hits = toki.top(entries, options[:number] || 5)
+ puts TokiCLI::View.new.hits_table(hits.reverse)
+ puts "\n"
+ end
+
desc "auth", "Input your App.net token for authorization"
def auth
puts Status.paste_token
token = STDIN.gets.chomp!
- unless token.nil?
- save_token(token)
- else
- abort(Status.no_token)
- end
+ abort(Status.no_token) if token == ''
+ save_token(token)
puts Status.done
end
desc "log APP", "Shows the complete log for an app"
- option :adn, aliases: '-a', type: :boolean, desc: 'Select ADN channel as source (toki total -a)'
+ option :adn, aliases: '-a', type: :boolean, desc: 'Select ADN channel as source (toki log -a)'
def log(*args)
abort(Status.specify_name) if args.empty?
- if options[:adn]
- toki = total_adn
- else
- toki = total_db
- end
asked = args[0]
- synced = toki.get_content(options)
- app_data = toki.get_app(asked, synced)
+ toki = create_toki(options)
+ entries = toki.get_content(options)
+ app_data = toki.get_app(asked, entries)
v = TokiCLI::View.new
puts v.app_table(asked, app_data)
puts "\n"
end
private
+ def create_toki(options)
+ if options[:adn]
+ total_adn
+ else
+ total_db
+ end
+ end
+
def total_adn
clear
puts Status.get_all
init_toki_adn
end
def total_db
clear
- puts "getting data from db\n"
+ #puts "getting data from db\n"
init_toki_db
end
def get_total(toki, options)
begin