Class: Uktt::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/uktt/cli.rb

Overview

Implemets a CLI using Thor

Instance Method Summary collapse

Instance Method Details

#chapter(chapter_id) ⇒ Object



65
66
67
68
69
70
71
72
73
# 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

#chaptersObject



76
77
78
# File 'lib/uktt/cli.rb', line 76

def chapters
  puts Uktt::Chapter.new(options.merge(host: host)).retrieve_all
end

#commodity(commodity_id) ⇒ Object



95
96
97
98
99
100
101
102
# 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

#heading(heading_id) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
# 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

#infoObject



130
131
132
133
134
135
136
137
138
# File 'lib/uktt/cli.rb', line 130

def info
  if options[:version]
    puts Uktt::VERSION
  elsif ARGV
    help
  else
    help
  end
end

#monetary_exchange_ratesObject



105
106
107
# 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) ⇒ Object



114
115
116
117
118
# 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) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# 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

#sectionsObject



60
61
62
# File 'lib/uktt/cli.rb', line 60

def sections
  puts Uktt::Section.new(options.merge(host: host)).retrieve_all
end

#testObject



121
122
123
124
125
126
# 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