lib/TokiCLI/app.rb in TokiCLI-0.1.1 vs lib/TokiCLI/app.rb in TokiCLI-0.2.0

- old
+ new

@@ -2,10 +2,26 @@ module TokiCLI class App < Thor package_name "TokiCLI" %w{get_messages search_messages get_channels status view authorize export import scan ../API/dbapi}.each {|r| require_relative "#{r}"} + desc "version", "Toki version" + map "-v" => :version + def version + puts "\n-- TokiCLI --\n\nVersion:\t#{VERSION}\nUrl:\t\thttp://github.com/ericdke/TokiCLI\n\n" + end + + desc "serve", "Start a local Toki API server" + map "server" => :serve + def serve + require_relative '../TokiServer/tokiserver' + #View.new.clear + puts "\nStarting the Toki API server...\n\nPress [CTRL-C] to stop.\n\nThe index page URL is: http://localhost:4567\n\n" + TokiServer.run! + puts "\nToki API server has been shut down.\n\n" + end + desc "auth", "App.net login" def auth begin toki = DBAPI.new adn = Authorize.new(toki.helpers.toki_path) @@ -26,11 +42,16 @@ option :json, aliases: '-j', type: :boolean, desc: 'Export the results as a JSON file' option :csv, aliases: '-c', type: :boolean, desc: 'Export the results as a CSV file' def total toki, view = DBAPI.new, View.new apps = JSON.parse toki.apps_total - view.total_table apps + if apps['meta']['code'] == 200 + view.total_table apps + else + puts "\nError:\n\n#{apps}\n\n" + exit + end if (options[:json] || options[:csv]) export = Export.new toki, view export.apps_total options, apps, 'total' end end @@ -40,11 +61,16 @@ option :json, aliases: '-j', type: :boolean, desc: 'Export the results as a JSON file' option :csv, aliases: '-c', type: :boolean, desc: 'Export the results as a CSV file' def top toki, view = DBAPI.new, View.new apps = JSON.parse toki.apps_top(options[:number] || 5) - view.total_table apps + if apps['meta']['code'] == 200 + view.total_table apps + else + puts "\nError:\n\n#{apps}\n\n" + exit + end if (options[:json] || options[:csv]) export = Export.new toki, view export.apps_total options, apps, 'top' end end @@ -59,11 +85,16 @@ rescue ArgumentError abort(Status.specify_day) end toki, view = DBAPI.new, View.new apps = JSON.parse toki.apps_day args[0] - view.total_table apps + if apps['meta']['code'] == 200 + view.total_table apps + else + puts "\nError:\n\n#{apps}\n\n" + exit + end if (options[:json] || options[:csv]) export = Export.new toki, view export.apps_total options, apps, "day-#{args[0]}" end end @@ -78,11 +109,16 @@ rescue ArgumentError abort Status.specify_day end toki, view = DBAPI.new, View.new apps = JSON.parse toki.apps_since args[0] - view.total_table apps + if apps['meta']['code'] == 200 + view.total_table apps + else + puts "\nError:\n\n#{apps}\n\n" + exit + end if (options[:json] || options[:csv]) export = Export.new toki, view export.apps_total options, apps, "since-#{args[0]}" end end @@ -97,11 +133,16 @@ rescue ArgumentError abort Status.specify_day end toki, view = DBAPI.new, View.new apps = JSON.parse toki.apps_before args[0] - view.total_table apps + if apps['meta']['code'] == 200 + view.total_table apps + else + puts "\nError:\n\n#{apps}\n\n" + exit + end if (options[:json] || options[:csv]) export = Export.new toki, view export.apps_total options, apps, "before-#{args[0]}" end end @@ -117,11 +158,16 @@ rescue ArgumentError abort(Status.specify_range) end toki, view = DBAPI.new, View.new apps = JSON.parse toki.apps_range args[0], args[1] - view.total_table apps + if apps['meta']['code'] == 200 + view.total_table apps + else + puts "\nError:\n\n#{apps}\n\n" + exit + end if (options[:json] || options[:csv]) export = Export.new toki, view export.apps_total options, apps, "range-#{args[0]}_#{args[1]}" end end @@ -138,11 +184,16 @@ log = if options[:bundle] JSON.parse toki.bundle_log asked else JSON.parse toki.name_log asked end - view.app_table asked, log + if log['meta']['code'] == 200 + view.app_table asked, log + else + puts "\nError:\n\n#{log}\n\n" + exit + end if (options[:json] || options[:csv]) export = Export.new toki, view export.log options, log, "log-#{log['data']['bundle'].gsub('.', '_')}" end end @@ -159,11 +210,16 @@ app = if options[:bundle] JSON.parse toki.bundle_total asked else JSON.parse toki.name_total asked end - view.total_table app + if app['meta']['code'] == 200 + view.total_table app + else + puts "\nError:\n\n#{app}\n\n" + exit + end if (options[:json] || options[:csv]) export = Export.new toki, view export.app_total options, app, "app-#{app['data']['bundle'].gsub('.', '_')}" end end @@ -186,11 +242,16 @@ app = if options[:bundle] JSON.parse toki.bundle_total_before asked, date else JSON.parse toki.name_total_before asked, date end - view.total_table app + if app['meta']['code'] == 200 + view.total_table app + else + puts "\nError:\n\n#{app}\n\n" + exit + end if (options[:json] || options[:csv]) export = Export.new toki, view export.app_total options, app, "app_before-#{app['data']['bundle'].gsub('.', '_')}_#{args[1]}" end end @@ -213,11 +274,16 @@ app = if options[:bundle] JSON.parse toki.bundle_total_since asked, date else JSON.parse toki.name_total_since asked, date end - view.total_table app + if app['meta']['code'] == 200 + view.total_table app + else + puts "\nError:\n\n#{app}\n\n" + exit + end if (options[:json] || options[:csv]) export = Export.new toki, view export.app_total options, app, "app_since-#{app['data']['bundle'].gsub('.', '_')}_#{date}" end end @@ -240,11 +306,16 @@ app = if options[:bundle] JSON.parse toki.bundle_total_day asked, date else JSON.parse toki.name_total_day asked, date end - view.total_table app + if app['meta']['code'] == 200 + view.total_table app + else + puts "\nError:\n\n#{app}\n\n" + exit + end if (options[:json] || options[:csv]) export = Export.new toki, view export.app_total options, app, "app_day-#{app['data']['bundle'].gsub('.', '_')}_#{date}" end end @@ -266,10 +337,15 @@ app = if options[:bundle] JSON.parse toki.bundle_total_range args[0], args[1], args[2] else JSON.parse toki.name_total_range args[0], args[1], args[2] end - view.total_table app + if app['meta']['code'] == 200 + view.total_table app + else + puts "\nError:\n\n#{app}\n\n" + exit + end if (options[:json] || options[:csv]) export = Export.new toki, view export.app_total options, app, "app_range-#{app['data']['bundle'].gsub('.', '_')}_#{args[1]}_#{args[2]}" end end