oja 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/lib/oja.rb +33 -4
  2. data/lib/oja/cli.rb +9 -2
  3. data/lib/oja/receipt.rb +8 -4
  4. metadata +2 -2
data/lib/oja.rb CHANGED
@@ -3,13 +3,42 @@ require 'oja/request'
3
3
  require 'oja/response'
4
4
 
5
5
  module Oja
6
- def self.verify(data)
7
- receipt = Oja::Receipt.new(:data => data)
6
+ # Verify a receipt data with the App Store. You can either pass the receipt
7
+ # and password as two arguments or as a option hash.
8
+ #
9
+ # Receipt data should be raw, not Base64 encoded. It usually begins with
10
+ # ‘{ "signature" = ’.
11
+ #
12
+ # Example:
13
+ # Oja.verify(receipt_data, password)
14
+ # Oja.verify(:data => receipt_data, :password => password)
15
+ def self.verify(*args)
16
+ receipt = Oja::Receipt.new(argument_hash(*args, [:data, :password]))
8
17
  receipt.verify
9
18
  end
10
19
 
11
- def self.verify_filename(receipt_filename)
12
- receipt = Oja::Receipt.new(:filename => receipt_filename)
20
+ # Verify a receipt file with the App Store. You can either pass the filename
21
+ # and password as two arguments or as a option hash.
22
+ #
23
+ # Example:
24
+ # Oja.verify_filename(filename, password)
25
+ # Oja.verify(:filename => filename, :password => password)
26
+ def self.verify_filename(*args)
27
+ receipt = Oja::Receipt.new(argument_hash(*args, [:filename, :password]))
13
28
  receipt.verify
14
29
  end
30
+
31
+ private
32
+
33
+ def self.argument_hash(*args)
34
+ args = args.dup
35
+ parts = args.pop
36
+ if args[0].kind_of?(Hash)
37
+ args[0]
38
+ else
39
+ h = {}; parts.each_with_index do |part, index|
40
+ h[part] = args[index]
41
+ end; h
42
+ end
43
+ end
15
44
  end
@@ -8,13 +8,20 @@ module Oja
8
8
  end
9
9
 
10
10
  def usage
11
- puts "Usage: #{File.basename($0)} <receipt-file>"
11
+ puts "Usage: #{File.basename($0)} <receipt-file> [options]"
12
+ puts ""
13
+ puts "Options"
14
+ puts " -p, --password <password>"
12
15
  end
13
16
 
14
17
  def receipt_filename
15
18
  @argv[0]
16
19
  end
17
20
 
21
+ def password
22
+ @options['p'] || @options['password']
23
+ end
24
+
18
25
  def print_receipt_details(receipt_data)
19
26
  receipt_data.each do |key, value|
20
27
  puts "#{key}: #{value}"
@@ -22,7 +29,7 @@ module Oja
22
29
  end
23
30
 
24
31
  def check_receipt
25
- if response = Oja.verify_filename(receipt_filename)
32
+ if response = Oja.verify_filename(:filename => receipt_filename, :password => password)
26
33
  if response.active?
27
34
  puts "[!] Receipt appears to be valid and active"
28
35
  puts
@@ -2,7 +2,7 @@ require 'base64'
2
2
 
3
3
  module Oja
4
4
  class Receipt
5
- attr_accessor :filename
5
+ attr_accessor :filename, :password
6
6
  attr_writer :data
7
7
 
8
8
  def initialize(attributes)
@@ -31,10 +31,14 @@ module Oja
31
31
  Base64.encode64(data)
32
32
  end
33
33
 
34
+ def attributes
35
+ attributes = { 'receipt-data' => receipt_data }
36
+ attributes['password'] = password if password
37
+ attributes
38
+ end
39
+
34
40
  def to_json
35
- JSON.dump(
36
- 'receipt-data' => receipt_data
37
- )
41
+ JSON.dump(attributes)
38
42
  end
39
43
 
40
44
  def verify
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oja
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-25 00:00:00.000000000 Z
12
+ date: 2012-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nap