Class: Oja::CLI

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

Class Method Summary collapse

Instance Method Summary collapse

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_receiptObject



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(message)
  $stderr.puts(message)
end

#passwordObject



21
22
23
# File 'lib/oja/cli.rb', line 21

def password
  @options['p'] || @options['password']
end


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_filenameObject



17
18
19
# File 'lib/oja/cli.rb', line 17

def receipt_filename
  @argv[0]
end

#runObject



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

#usageObject



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