class Uktt::CLI
Implemets a CLI
using Thor
Public Instance Methods
action()
click to toggle source
# File lib/uktt/cli.rb, line 155 def action if options[:goods] return :goods_nomenclatures elsif options[:note] return :note elsif options[:changes] return :changes else return :retrieve end end
chapter(chapter_id)
click to toggle source
# File lib/uktt/cli.rb, line 65 def chapter(chapter_id) if options[:goods] && options[:version] != 'v2' puts 'V2 is required. Use `-a v2`' return end uktt = Uktt::Chapter.new(options.merge(host: host, chapter_id: chapter_id)) puts uktt.send(action) end
chapters()
click to toggle source
# File lib/uktt/cli.rb, line 76 def chapters puts Uktt::Chapter.new(options.merge(host: host)).retrieve_all end
commodity(commodity_id)
click to toggle source
# File lib/uktt/cli.rb, line 95 def commodity(commodity_id) if options[:goods] || options[:note] puts 'Option not supported for this object' return end puts Uktt::Commodity.new(options.merge(host: host, commodity_id: commodity_id)).send(action) end
handle_class_options(options)
click to toggle source
# File lib/uktt/cli.rb, line 142 def handle_class_options(options) [ options[:host] || (options[:prod] ? API_HOST_PROD : API_HOST_LOCAL), options[:api_version] || 'v1', options[:json] || false, options[:debug] || false, options[:filepath] || nil, options[:goods] || false, options[:note] || false, options[:changes] || false, ] end
heading(heading_id)
click to toggle source
# File lib/uktt/cli.rb, line 81 def heading(heading_id) if options[:goods] && options[:version] != 'v2' puts 'V2 is required. Use `-a v2`' return elsif options[:note] puts 'Option not supported for this object' return end uktt = Uktt::Heading.new(options.merge(host: host, heading_id: heading_id)) puts uktt.send(action) end
host()
click to toggle source
# File lib/uktt/cli.rb, line 167 def host return ENV['HOST'] if ENV['HOST'] options[:prod] ? API_HOST_PROD : Uktt::Http.api_host end
info()
click to toggle source
# File lib/uktt/cli.rb, line 130 def info if options[:version] puts Uktt::VERSION elsif ARGV help else help end end
monetary_exchange_rates()
click to toggle source
# File lib/uktt/cli.rb, line 105 def monetary_exchange_rates puts Uktt::MonetaryExchangeRate.new(options.merge(host: host)).retrieve_all end
pdf(chapter_id)
click to toggle source
# File lib/uktt/cli.rb, line 114 def pdf(chapter_id) puts "Making a PDF for Chapter #{chapter_id}" start_time = Time.now puts "Finished #{Uktt::Pdf.new(options.merge(chapter_id: chapter_id)).make_chapter} in #{Time.now - start_time}" end
section(section_id)
click to toggle source
# File lib/uktt/cli.rb, line 46 def section(section_id) if options[:goods] && options[:version] != 'v2' puts 'V2 is required. Use `-a v2`' return elsif options[:changes] puts 'Option not supported for this object' return end uktt = Uktt::Section.new(options.merge(host: host, section_id: section_id)) puts uktt.send(action) end
sections()
click to toggle source
# File lib/uktt/cli.rb, line 60 def sections puts Uktt::Section.new(options.merge(host: host)).retrieve_all end
test()
click to toggle source
# File lib/uktt/cli.rb, line 121 def test host, version, _json, _debug, _filepath = handle_class_options(options) ver = version ? "VER=#{version} " : '' prod = host == API_HOST_PROD ? 'PROD=true ' : '' puts `#{ver}#{prod}bundle exec rspec ./spec/uktt_api_spec.rb` end