Class: Venice::Client
- Inherits:
-
Object
- Object
- Venice::Client
- Defined in:
- lib/venice/client.rb
Defined Under Namespace
Classes: InvalidResponseError, TimeoutError
Instance Attribute Summary collapse
-
#exclude_old_transactions ⇒ Object
writeonly
Sets the attribute exclude_old_transactions.
-
#shared_secret ⇒ Object
writeonly
Sets the attribute shared_secret.
-
#verification_url ⇒ Object
Returns the value of attribute verification_url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #verify!(data, options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
28 29 30 |
# File 'lib/venice/client.rb', line 28 def initialize @verification_url = ENV['IAP_VERIFICATION_ENDPOINT'] end |
Instance Attribute Details
#exclude_old_transactions=(value) ⇒ Object (writeonly)
Sets the attribute exclude_old_transactions
12 13 14 |
# File 'lib/venice/client.rb', line 12 def exclude_old_transactions=(value) @exclude_old_transactions = value end |
#shared_secret=(value) ⇒ Object (writeonly)
Sets the attribute shared_secret
11 12 13 |
# File 'lib/venice/client.rb', line 11 def shared_secret=(value) @shared_secret = value end |
#verification_url ⇒ Object
Returns the value of attribute verification_url.
10 11 12 |
# File 'lib/venice/client.rb', line 10 def verification_url @verification_url end |
Class Method Details
.development ⇒ Object
15 16 17 18 19 |
# File 'lib/venice/client.rb', line 15 def development client = new client.verification_url = ITUNES_DEVELOPMENT_RECEIPT_VERIFICATION_ENDPOINT client end |
.production ⇒ Object
21 22 23 24 25 |
# File 'lib/venice/client.rb', line 21 def production client = new client.verification_url = ITUNES_PRODUCTION_RECEIPT_VERIFICATION_ENDPOINT client end |
Instance Method Details
#verify!(data, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/venice/client.rb', line 32 def verify!(data, = {}) @shared_secret = [:shared_secret] if [:shared_secret] @exclude_old_transactions = [:exclude_old_transactions] if [:exclude_old_transactions] json = (data, ) receipt_attributes = json['receipt'].dup if json['receipt'] receipt_attributes['original_json_response'] = json if receipt_attributes case json['status'].to_i when 0, 21006 receipt = Receipt.new(receipt_attributes) # From Apple docs: # > Only returned for iOS 6 style transaction receipts for auto-renewable subscriptions. # > The JSON representation of the receipt for the most recent renewal if latest_receipt_info_attributes = json['latest_receipt_info'] latest_receipt_info_attributes = [latest_receipt_info_attributes] if latest_receipt_info_attributes.is_a?(Hash) # AppStore returns 'latest_receipt_info' even if we use over iOS 6. Besides, its format is an Array. if latest_receipt_info_attributes.is_a?(Array) receipt.latest_receipt_info = [] latest_receipt_info_attributes.each do |latest_receipt_info_attribute| # latest_receipt_info format is identical with in_app receipt.latest_receipt_info << InAppReceipt.new(latest_receipt_info_attribute) end else receipt.latest_receipt_info = latest_receipt_info_attributes end end return receipt else raise Receipt::VerificationError, json end end |