class Amazon::Iap::Result

Constants

V2_V1_MAPPING

Attributes

beta_product[RW]
end_date[RW]
end_time[RW]
item_type[RW]
parent_product_id[RW]
purchase_token[RW]
quantity[RW]
sku[RW]
start_date[RW]
start_time[RW]
term[RW]
term_sku[RW]
test_transaction[RW]

Public Class Methods

new(response) click to toggle source
# File lib/amazon/iap/result.rb, line 10
def initialize(response)
  case response.code.to_i
  when 200
    parsed = JSON.parse(response.body)
    V2_V1_MAPPING.each { |v2,v1| parsed[v1.to_s] = parsed.delete(v2.to_s) if parsed.has_key?(v2.to_s) }
    if parsed.has_key? 'startDate'
      parsed['startTime'] = parsed['startDate'].nil? ? nil : Time.at(parsed['startDate'] / 1000)
    end
    if parsed.has_key? 'endDate'
      parsed['endTime'] = parsed['endDate'].nil? ? nil : Time.at(parsed['endDate'] / 1000)
    end

    parsed.each do |key, value|
      underscore = key.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').gsub(/([a-z\d])([A-Z])/, '\1_\2').tr('-', '_').downcase
      send "#{underscore}=", value if respond_to?("#{underscore}=")
    end
  when 400 then raise Amazon::Iap::Exceptions::InvalidTransaction
  when 496 then raise Amazon::Iap::Exceptions::InvalidSharedSecret
  when 497 then raise Amazon::Iap::Exceptions::InvalidUserId
  when 498 then raise Amazon::Iap::Exceptions::InvalidPurchaseToken
  when 499 then raise Amazon::Iap::Exceptions::ExpiredCredentials
  when 500 then raise Amazon::Iap::Exceptions::InternalError
  else raise Amazon::Iap::Exceptions::General
  end
end