Class: Amazon::Iap::Result
- Inherits:
-
Object
- Object
- Amazon::Iap::Result
- Defined in:
- lib/amazon/iap/result.rb
Instance Attribute Summary collapse
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#item_type ⇒ Object
Returns the value of attribute item_type.
-
#purchase_token ⇒ Object
Returns the value of attribute purchase_token.
-
#sku ⇒ Object
Returns the value of attribute sku.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Instance Method Summary collapse
-
#initialize(response) ⇒ Result
constructor
A new instance of Result.
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_date ⇒ Object
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_time ⇒ Object
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_type ⇒ Object
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_token ⇒ Object
Returns the value of attribute purchase_token.
2 3 4 |
# File 'lib/amazon/iap/result.rb', line 2 def purchase_token @purchase_token end |
#sku ⇒ Object
Returns the value of attribute sku.
2 3 4 |
# File 'lib/amazon/iap/result.rb', line 2 def sku @sku end |
#start_date ⇒ Object
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_time ⇒ Object
Returns the value of attribute start_time.
2 3 4 |
# File 'lib/amazon/iap/result.rb', line 2 def start_time @start_time end |