Class: GameRocket::ActionGateway

Inherits:
Object
  • Object
show all
Defined in:
lib/gamerocket/action_gateway.rb

Instance Method Summary collapse

Constructor Details

#initialize(gateway) ⇒ ActionGateway

Returns a new instance of ActionGateway.



4
5
6
7
# File 'lib/gamerocket/action_gateway.rb', line 4

def initialize(gateway)
  @gateway = gateway
  @config = gateway.config
end

Instance Method Details

#find(id) ⇒ Object

Raises:



9
10
11
12
13
14
15
16
17
# File 'lib/gamerocket/action_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}/actions/#{id}")
  if !response["action"].nil?
    Action._new(@gateway, response["action"])
  else
    nil
  end
end

#run(id, attributes) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/gamerocket/action_gateway.rb', line 19

def run(id, attributes)
  response = @config.http.post("/games/#{@config.apiKey}/actions/#{id}/run", attributes)
  if response["status"] != "error"
    SuccessfulResult.new(response)
  else
    ErrorResult.new(attributes, response)
  end
rescue NotFoundError
  raise NotFoundError, "Action with id #{id} not found."
end