Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Send a password with the verification request when it's configured.

  • Loading branch information...
commit 7e26340cf2f6a58ea2363b7f211dfd07edc3cf78 1 parent 8d275ff
Manfred Stienstra Manfred authored
37 lib/oja.rb
View
@@ -3,13 +3,42 @@
require 'oja/response'
module Oja
- def self.verify(data)
- receipt = Oja::Receipt.new(:data => data)
+ # Verify a receipt data with the App Store. You can either pass the receipt
+ # and password as two arguments or as a option hash.
+ #
+ # Receipt data should be raw, not Base64 encoded. It usually begins with
+ # ‘{ "signature" = ’.
+ #
+ # Example:
+ # Oja.verify(receipt_data, password)
+ # Oja.verify(:data => receipt_data, :password => password)
+ def self.verify(*args)
+ receipt = Oja::Receipt.new(argument_hash(*args, [:data, :password]))
receipt.verify
end
- def self.verify_filename(receipt_filename)
- receipt = Oja::Receipt.new(:filename => receipt_filename)
+ # Verify a receipt file with the App Store. You can either pass the filename
+ # and password as two arguments or as a option hash.
+ #
+ # Example:
+ # Oja.verify_filename(filename, password)
+ # Oja.verify(:filename => filename, :password => password)
+ def self.verify_filename(*args)
+ receipt = Oja::Receipt.new(argument_hash(*args, [:filename, :password]))
receipt.verify
end
+
+ private
+
+ def self.argument_hash(*args)
+ args = args.dup
+ parts = args.pop
+ if args[0].kind_of?(Hash)
+ args[0]
+ else
+ h = {}; parts.each_with_index do |part, index|
+ h[part] = args[index]
+ end; h
+ end
+ end
end
12 lib/oja/receipt.rb
View
@@ -2,7 +2,7 @@
module Oja
class Receipt
- attr_accessor :filename
+ attr_accessor :filename, :password
attr_writer :data
def initialize(attributes)
@@ -31,10 +31,14 @@ def receipt_data
Base64.encode64(data)
end
+ def attributes
+ attributes = { 'receipt-data' => receipt_data }
+ attributes['password'] = password if password
+ attributes
+ end
+
def to_json
- JSON.dump(
- 'receipt-data' => receipt_data
- )
+ JSON.dump(attributes)
end
def verify
12 spec/oja_spec.rb
View
@@ -8,6 +8,18 @@
response.should.be.active
end
+ it "verifies receipt data with a password" do
+ response = Oja.verify(receipt_data('receipt'), 'secret')
+ # The default for the mock response is success
+ response.should.be.active
+ end
+
+ it "verifies receipt data passed in an option hash" do
+ response = Oja.verify(:data => receipt_data('receipt'))
+ # The default for the mock response is success
+ response.should.be.active
+ end
+
it "verifies an active receipt from disk" do
response = Oja.verify_filename(receipt_filename('receipt'))
# The default for the mock response is success
16 spec/receipt_spec.rb
View
@@ -10,4 +10,20 @@
receipt = Oja::Receipt.new(:data => receipt_data('receipt'))
receipt.data.should == receipt_data('receipt')
end
+
+ it "includes the Base64 encoded receipt data in its attributes" do
+ data = receipt_data('receipt')
+ receipt = Oja::Receipt.new(:data => data)
+ receipt.attributes['receipt-data'].should == Base64.encode64(data)
+ end
+
+ it "includes the password in its attributes when it's configured" do
+ receipt = Oja::Receipt.new(:data => receipt_data('receipt'), :password => 'secret')
+ receipt.attributes['password'].should == 'secret'
+ end
+
+ it "includes the password in its JSON when it's configured" do
+ receipt = Oja::Receipt.new(:data => receipt_data('receipt'), :password => 'secret')
+ JSON.parse(receipt.to_json)['password'].should == 'secret'
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.