class Middlecoin::CLI::Application
Public Class Methods
new()
click to toggle source
Initializes a CLI
Application
# File lib/middlecoin/cli/application.rb, line 28 def initialize @options = {} end
Public Instance Methods
parse_options()
click to toggle source
Parses all the command line options
# File lib/middlecoin/cli/application.rb, line 33 def parse_options begin opts = OptionParser.new do |opt| opt.banner = "#{APP_NAME} v#{VERSION}\nJacob Hammack\nhttp://www.hammackj.com\n\n" opt.banner << "Usage: #{APP_NAME} [options] <BTC Address>" opt.separator '' opt.separator 'Other Options' opt.on_tail('-v', '--version', "Shows application version information") do puts "#{APP_NAME}: #{VERSION}\nRuby Version: #{RUBY_VERSION}\nRubygems Version: #{Gem::VERSION}" exit end opt.on_tail("-?", "--help", "Show this message") do puts opt.to_s + "\n" exit end end if ARGV.length != 0 opts.parse! else puts opts.to_s + "\n" exit end rescue OptionParser::MissingArgument => m puts opts.to_s + "\n" exit rescue OptionParser::InvalidOption => i puts opts.to_s + "\n" exit end end
run()
click to toggle source
Main Application loop, handles all of the command line arguments and
parsing of files on the command line
# File lib/middlecoin/cli/application.rb, line 69 def run parse_options api = Middlecoin::Core::MiddlecoinAPI.new api.fetch_report ARGV.each do |address| begin puts "[*] Checking Address #{address}" Middlecoin::Core::BitcoinAddress.validate address result = api.lookup address if result == nil puts "[!] Address not found" next end puts "Address: #{result[:address]}" puts "Megahash/s: #{result[:megahashesPerSecond]}" puts "Rejected MHs: #{result[:rejectedMegahashesPerSecond]}" puts "Last hour shares: #{result[:lastHourShares]}" puts "Last hour rejected shares: #{result[:lastHourRejectedShares]}" puts "Immature Balance: #{result[:immatureBalance]}" puts "Unexchanged Balance: #{result[:unexchangedBalance]}" puts "Bitcoin Balance: #{result[:bitcoinBalance]}" puts "Total paid out: #{result[:paidOut]}\n" rescue Middlecoin::MiddlecoinAPIError => a puts "[!] Error: #{i.message}" break rescue Middlecoin::InvalidBitcoinAddressError => i puts "[!] Error: #{i.message}" next rescue => e puts e.inspect puts e.backtrace puts "[!] Error: #{address}" next end end end