ruby-client/lib/bitpay/cli.rb
Paul Daigle 33025f2b8e Changes for the 2.0.0 version. Detailed changes are on the 2.0.0 branch.
The library now uses the crpytographically secure API.

more tests plus CLI enhancements

Library no longer supporting ruby 1.9.x

1.9.x will be deprecated in February of 2015, so there is little
incentive to write our new library to support it. 1.9.x users should
still be able to use V1 of the API.

This commit adds some changes, such as named arguments, that are
incompatible with 1.9.x.

Add Rake tasks to clear limiters

When many integration tests are run in a short period, the local bitpay server
will refuse to create new keys due to the rate limiting function. This
rake task clears the ratelimiters database.
2014-10-08 13:21:00 -04:00

64 lines
2.1 KiB
Ruby

# license Copyright 2011-2014 BitPay, Inc., MIT License
# see http://opensource.org/licenses/MIT
# or https://github.com/bitpay/php-bitpay-client/blob/master/LICENSE
require 'rubygems'
require 'commander/import'
program :name, 'BitPay Ruby Library CLI'
program :version, BitPay::VERSION
program :description, 'Official BitPay Ruby API Client. Use to securely register your client with the BitPay API endpoint. '
program :help_formatter, :compact
command :pair do |c|
c.syntax = 'bitpay pair <code>'
c.summary = "Pair the local keys to a bitpay account."
c.option '--test', "Use the bitpay test server"
c.option '--custom <custom>', "Use a custom bitpay URI"
c.option '--insecure <insecure>', "Use an insecure custom bitpay URI"
c.action do |args, options|
raise ArgumentError, "Pairing failed, please call argument as 'bitpay pair <code> [options]'" unless args.first
case
when options.test
client = BitPay::Client.new(api_uri: "https://test.bitpay.com")
message = "Paired with test.bitpay.com"
when options.custom
client = BitPay::Client.new(api_uri: options.custom)
message = "Paired with #{options.custom}"
when options.insecure
client = BitPay::Client.new(insecure: true, api_uri: options.insecure)
message = "Paired with #{options.insecure}"
else
client = BitPay::Client.new
message = "Paired with bitpay.com"
end
begin
client.pair_pos_client args.first
puts message
rescue Exception => e
puts e.message
end
end
end
command :show_keys do |c|
c.syntax = 'bitpay show_keys'
c.summary = "Read current environment's key information to STDOUT"
c.description = ''
c.example 'description', 'command example'
c.action do |args, options|
pem = BitPay::KeyUtils.get_local_pem_file
private_key = BitPay::KeyUtils.get_private_key_from_pem pem
public_key = BitPay::KeyUtils.get_public_key_from_pem pem
client_id = BitPay::KeyUtils.generate_sin_from_pem pem
puts "Current BitPay Client Keys:\n"
puts "Private Key: #{private_key}"
puts "Public Key: #{public_key}"
puts "Client ID: #{client_id}"
end
end