Class: GameRocket::PurchaseGateway
- Inherits:
-
Object
- Object
- GameRocket::PurchaseGateway
- Defined in:
- lib/gamerocket/purchase_gateway.rb
Instance Method Summary collapse
- #buy(id, attributes) ⇒ Object
- #find(id) ⇒ Object
-
#initialize(gateway) ⇒ PurchaseGateway
constructor
A new instance of PurchaseGateway.
Constructor Details
#initialize(gateway) ⇒ PurchaseGateway
Returns a new instance of PurchaseGateway.
4 5 6 7 |
# File 'lib/gamerocket/purchase_gateway.rb', line 4 def initialize(gateway) @gateway = gateway @config = gateway.config end |
Instance Method Details
#buy(id, attributes) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/gamerocket/purchase_gateway.rb', line 19 def buy(id, attributes) response = @config.http.post("/games/#{@config.apiKey}/purchases/#{id}/buy", attributes) if response["status"] != "error" SuccessfulResult.new(response) else ErrorResult.new(@gateway, response) end rescue NotFoundError raise NotFoundError, "Purchase with id #{id} not found." end |
#find(id) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/gamerocket/purchase_gateway.rb', line 9 def find(id) raise InvalidArgument, "Expected id to be set" if id.nil? || id.to_s == "" response = @config.http.get("/games/#{@config.apiKey}/purchases/#{id}") if !response["purchase"].nil? Purchase._new(@gateway, response["purchase"]) else nil end end |