Class: Oja::CLI
- Inherits:
-
Object
- Object
- Oja::CLI
- Defined in:
- lib/oja/cli.rb
Class Method Summary collapse
Instance Method Summary collapse
- #check_receipt ⇒ Object
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #log(message) ⇒ Object
- #password ⇒ Object
- #print_receipt_details(receipt_data) ⇒ Object
- #receipt_filename ⇒ Object
- #run ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
6 7 8 |
# File 'lib/oja/cli.rb', line 6 def initialize(argv) @options, @argv = Oja::OptionParser.parse(argv) end |
Class Method Details
.run(argv) ⇒ Object
57 58 59 60 |
# File 'lib/oja/cli.rb', line 57 def self.run(argv) cli = new(argv.dup) cli.run end |
Instance Method Details
#check_receipt ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/oja/cli.rb', line 31 def check_receipt if response = Oja.verify_filename(:filename => receipt_filename, :password => password) if response.active? puts "[!] Receipt appears to be valid and active" puts print_receipt_details(response.receipt_data) else puts "[!] Receipt is invalid (#{response.humanized_status})" end else log("[!] Apple Store seems inacessible") end end |
#log(message) ⇒ Object
53 54 55 |
# File 'lib/oja/cli.rb', line 53 def log() $stderr.puts() end |
#password ⇒ Object
21 22 23 |
# File 'lib/oja/cli.rb', line 21 def password @options['p'] || @options['password'] end |
#print_receipt_details(receipt_data) ⇒ Object
25 26 27 28 29 |
# File 'lib/oja/cli.rb', line 25 def print_receipt_details(receipt_data) receipt_data.each do |key, value| puts "#{key}: #{value}" end end |
#receipt_filename ⇒ Object
17 18 19 |
# File 'lib/oja/cli.rb', line 17 def receipt_filename @argv[0] end |
#run ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/oja/cli.rb', line 45 def run if receipt_filename check_receipt else usage end end |
#usage ⇒ Object
10 11 12 13 14 15 |
# File 'lib/oja/cli.rb', line 10 def usage puts "Usage: #{File.basename($0)} <receipt-file> [options]" puts "" puts "Options" puts " -p, --password <password>" end |