class Strutta::Games
The Strutta
Games
object is the master of all other API
objects (Rounds
, Flow
, Entries
, Participants
) The above objects are instantiated in association with a Games
object, as each belong to a Game in the Strutta
API
The above objects also have all their API
requests forwarded through this object to Strutta::API
Attributes
Public Class Methods
Initializes the Strutta::Games
object
@param id [Integer, nil] Game id @param master [Strutta::API] Master Strutta::API
object @return [Strutta::Games] instantiated Strutta::Games
object
# File lib/strutta-api/games.rb, line 13 def initialize(id = nil, master) @id = id @root_path = 'games' @master = master end
Public Instance Methods
Polymorphic GET Index request
@param resource_path [String, nil] the GET index path for the requesting object
See Strutta::APIObject#all
@return [Hash] Parsed body of the response
# File lib/strutta-api/games.rb, line 34 def all(params = {}, resource_path = nil) verify_no_id(@id) unless resource_path call('get', "#{@root_path}/#{resource_path}", params) end
Forwards an API
call to @master
@param method [String] the required HTTP method @param url [String] URL for the call @param params [Hash] Parameters for the call @return [Hash] Parsed body of the response
# File lib/strutta-api/games.rb, line 25 def call(method, url, params = {}) @master.call(method, url, params) end
Polymorphic POST request
@param resource_path [String, nil] the POST path for the requesting object
See Strutta::APIObject#create
@return [Hash] Parsed body of the response
# File lib/strutta-api/games.rb, line 54 def create(params = {}, resource_path = nil) verify_no_id(@id) unless resource_path call('post', "#{@root_path}/#{resource_path}", params) end
Polymorphic DELETE request
@param resource_path [String, nil] the DELETE path for the requesting object
See Strutta::APIObject#delete
@return [Hash] Parsed body of the response
# File lib/strutta-api/games.rb, line 74 def delete(resource_path = nil) verify_id(@id, Errors::GAME_ID_REQUIRED) call('delete', "#{@root_path}/#{@id}/#{resource_path}", {}) end
Instantiates a Strutta::Entries
object with reference to this Game
@param id [Integer, nil] the ID of the Entry @return [Strutta::Entries] The instantiated Strutta::Entries
object
# File lib/strutta-api/games.rb, line 110 def entries(id = nil) verify_id(@id, Errors::GAME_ID_REQUIRED) Entries.new id, self end
Instantiates a Strutta::Flow
object with reference to this Game
@param id [Integer, nil] Flows do not have Ids. This is here simply for consistency, and will result in error of used. @return [Strutta::Flow] The instantiated Strutta::Flow
object
# File lib/strutta-api/games.rb, line 101 def flow(id = nil) verify_id(@id, Errors::GAME_ID_REQUIRED) Flow.new id, self end
Polymorphic GET single object request
@param resource_path [String, nil] the GET path for the requesting object
See Strutta::APIObject#get
@return [Hash] Parsed body of the response
# File lib/strutta-api/games.rb, line 44 def get(params = {}, resource_path = '') verify_id(@id, Errors::GAME_ID_REQUIRED) call('get', "#{@root_path}/#{@id}/#{resource_path}", params) end
Instantiates a Strutta::Judging
object with reference to this Game
@param id [Integer, nil] Judging
does not have Ids. This is here simply for consistency, and will result in error of used. @return [Strutta::Entries] The instantiated Strutta::Judging
object
# File lib/strutta-api/games.rb, line 137 def judging(id = nil) verify_id(@id, Errors::GAME_ID_REQUIRED) Judging.new id, self end
Instantiates a Strutta::Moderation
object with reference to this Game
@param id [Integer, nil] Moderation
do not have Ids. This is here simply for consistency, and will result in error of used. @return [Strutta::Entries] The instantiated Strutta::Moderation
object
# File lib/strutta-api/games.rb, line 128 def moderation(id = nil) verify_id(@id, Errors::GAME_ID_REQUIRED) Moderation.new id, self end
Instantiates a Strutta::Participants
object with reference to this Game
@param id [Integer, nil] the ID of the Participant @return [Strutta::Participants] The instantiated Strutta::Participants
object
# File lib/strutta-api/games.rb, line 92 def participants(id = nil) verify_id(@id, Errors::GAME_ID_REQUIRED) Participants.new id, self end
Instantiates a Strutta::Points
object with reference to this Game
@param id [Integer, nil] Point IDs are not used by this API
. This is here simply for consistency, and will result in error of used. @return [Strutta::Entries] The instantiated Strutta::Points
object
# File lib/strutta-api/games.rb, line 119 def points(id = nil) verify_id(@id, Errors::GAME_ID_REQUIRED) Points.new id, self end
Instantiates a Strutta::Rounds
object with reference to this Game
@param id [Integer, nil] the ID of the Round @return [Strutta::Rounds] The instantiated Strutta::Rounds
object
# File lib/strutta-api/games.rb, line 83 def rounds(id = nil) verify_id(@id, Errors::GAME_ID_REQUIRED) Rounds.new id, self end
Polymorphic PATCH request
@param resource_path [String, nil] the PATCH path for the requesting object
See Strutta::APIObject#update
@return [Hash] Parsed body of the response
# File lib/strutta-api/games.rb, line 64 def update(params, resource_path = nil) verify_id(@id, Errors::GAME_ID_REQUIRED) call('patch', "#{@root_path}/#{@id}/#{resource_path}", params) end
Confirm that an id exists for a request
@param id [Integer] the ID of the objec @param message [String] Error message if no id exists @return [nil] nil if id exists, Error otherwise
# File lib/strutta-api/games.rb, line 147 def verify_id(id, message) fail Errors::ObjectIDRequired, message unless id end
Confirm that no id exists for a request
@param id [Integer] the ID of the objec @return [nil] nil if no id exists, Error otherwise
# File lib/strutta-api/games.rb, line 155 def verify_no_id(id) fail Errors::ObjectIDNotAllowed, Errors::OBJECT_NOT_ALLOWED if id end