Class: Venice::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/venice/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



27
28
29
# File 'lib/venice/client.rb', line 27

def initialize
  @verification_url = ENV['IAP_VERIFICATION_ENDPOINT']
end

Instance Attribute Details

#shared_secret=(value) ⇒ Object (writeonly)

Sets the attribute shared_secret

Parameters:

  • value

    the value to set the attribute shared_secret to.



11
12
13
# File 'lib/venice/client.rb', line 11

def shared_secret=(value)
  @shared_secret = value
end

#verification_urlObject

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

.developmentObject



14
15
16
17
18
# File 'lib/venice/client.rb', line 14

def development
  client = self.new
  client.verification_url = ITUNES_DEVELOPMENT_RECEIPT_VERIFICATION_ENDPOINT
  client
end

.productionObject



20
21
22
23
24
# File 'lib/venice/client.rb', line 20

def production
  client = self.new
  client.verification_url = ITUNES_PRODUCTION_RECEIPT_VERIFICATION_ENDPOINT
  client
end

Instance Method Details

#verify!(data, options = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/venice/client.rb', line 31

def verify!(data, options = {})
  @verification_url ||= ITUNES_DEVELOPMENT_RECEIPT_VERIFICATION_ENDPOINT
  @shared_secret = options[:shared_secret]

  json = json_response_from_verifying_data(data)
  status, receipt_attributes = json['status'].to_i, json['receipt']

  case status
  when 0, 21006
    attributes = (receipt_attributes || {}).merge({
      'latest_receipt' => json['latest_receipt'],
      'latest_receipt_info' => json['latest_receipt_info'],
    })
    Receipt.new(attributes)
  else
    raise Receipt::VerificationError.new(status, receipt_attributes)
  end
end