Class: Itunes::Receipt::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/itunes/receipt/service.rb

Constant Summary collapse

TEST_HOST =
'sandbox.itunes.apple.com'
PRODUCTION_HOST =
'buy.itunes.apple.com'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host: PRODUCTION_HOST, password: nil) ⇒ Service

Returns a new instance of Service.



11
12
13
14
15
# File 'lib/itunes/receipt/service.rb', line 11

def initialize host: PRODUCTION_HOST, password: nil
   @host = host
   @password = password
   @connection = Excon.new("https://#{host}")
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



9
10
11
# File 'lib/itunes/receipt/service.rb', line 9

def connection
  @connection
end

#hostObject (readonly)

Returns the value of attribute host.



9
10
11
# File 'lib/itunes/receipt/service.rb', line 9

def host
  @host
end

#passwordObject (readonly)

Returns the value of attribute password.



9
10
11
# File 'lib/itunes/receipt/service.rb', line 9

def password
  @password
end

Instance Method Details

#validate(receipt_data: nil) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/itunes/receipt/service.rb', line 17

def validate receipt_data: nil
   request = {
      'receipt-data' => receipt_data,
      'password' => password
   }

   response = connection.post(path: '/verifyReceipt', body: request.to_json)

   Itunes::Receipt::Response.new(response: response, request: request)
end