Class: Amazon::Iap::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/amazon/iap/result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Result

Returns a new instance of Result.



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/amazon/iap/result.rb', line 4

def initialize(response)
  case response.code.to_i
  when 200
    parsed = JSON.parse(response.body)
    
    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
    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

Instance Attribute Details

#end_dateObject

Returns the value of attribute end_date.



2
3
4
# File 'lib/amazon/iap/result.rb', line 2

def end_date
  @end_date
end

#end_timeObject

Returns the value of attribute end_time.



2
3
4
# File 'lib/amazon/iap/result.rb', line 2

def end_time
  @end_time
end

#item_typeObject

Returns the value of attribute item_type.



2
3
4
# File 'lib/amazon/iap/result.rb', line 2

def item_type
  @item_type
end

#purchase_tokenObject

Returns the value of attribute purchase_token.



2
3
4
# File 'lib/amazon/iap/result.rb', line 2

def purchase_token
  @purchase_token
end

#skuObject

Returns the value of attribute sku.



2
3
4
# File 'lib/amazon/iap/result.rb', line 2

def sku
  @sku
end

#start_dateObject

Returns the value of attribute start_date.



2
3
4
# File 'lib/amazon/iap/result.rb', line 2

def start_date
  @start_date
end

#start_timeObject

Returns the value of attribute start_time.



2
3
4
# File 'lib/amazon/iap/result.rb', line 2

def start_time
  @start_time
end