#!/usr/bin/env ruby $:.push(File.expand_path("../../lib", __FILE__)) require 'optparse' require "veritrans/version" OPERATIONS = %w(testhook) CONFIG = {} option_parser = OptionParser.new do |opts| opts.banner = "Veritrans #{Veritrans::VERSION}" "Usage: veritrans testhook [options] {url}\n" + " -o specify order id" opts.on("-h", "--help", "Show help") do puts option_parser.help exit end opts.on("-o [ORDER_ID]", "--order [ORDER_ID]", "Select order") do |order| CONFIG[:order] = order end opts.on("-c [PATH]", "--config [PATH]", "Path to config (defualt .)") do |config| CONFIG[:config_path] = config end opts.separator <<-EOS Supported commands: testhook [url] Send testing webhook to specified url Example: veritrans testhook http://localhost:3000/vt_events veritrans testhook -o my-order-1 -c ~/path/to/veritrans.yml http://localhost:3000/vt_events EOS end option_parser.parse! op = ARGV.shift if OPERATIONS.include?(op) require 'veritrans' require 'veritrans/cli' begin case op when "testhook" then Veritrans::CLI.test_webhook(ARGV) end rescue Veritrans::CLI::OrderNotFound, Veritrans::CLI::AuthenticationError => ex puts ex.message rescue ArgumentError => ex puts ex.message rescue Exception => e puts "Uh oh, I didn't expect this:" puts e.message puts e.backtrace.join("\n") end else puts option_parser.help end