Sha256: 3d105bd9127757b4c2204bc58eedee3c77a795451484d81823385a048b01fd1a

Contents?: true

Size: 1.81 KB

Versions: 3

Compression:

Stored size: 1.81 KB

Contents

module Strutta
  # Participants belong to a Strutta::Games object
  # Instance methods found in Strutta::APIObject
  class Participants < APIObject
    # Initializes the Strutta::Participants object
    #
    # @param id [Integer, nil] Entry id
    # @param game [Strutta::Games] Master Strutta::Games object
    # @return [Strutta::Participants] instantiated Strutta::Participants object
    def initialize(id = nil, game)
      @id = id
      @game = game
      @root_path = "participants/#{@id}"
      @no_id_error = Errors::PARTICIPANT_ID_REQUIRED
    end

    # GET participant by email address
    # games/:game_id/participants/search
    #
    # @return [Hash] Parsed body of the API response
    def search(params)
      fail Errors::InvalidSearchParameters, Errors::INVALID_SEARCH unless params.key? :email
      @game.verify_no_id(@id)
      @game.get(params, 'participants/search')
    end

    # PATCH update Participant token
    # games/:game_id/participants/:id/token
    #
    # @return [Hash] Parsed body of the API response
    def token_renew(params = {})
      participant_id_required
      @game.update(params, "participants/#{@id}/token")
    end

    # GET participant permissions
    # games/:game_id/participants/:id/permissions
    #
    # @return [Hash] Parsed body of the API response
    def permissions(params = {})
      participant_id_required
      @game.get(params, "participants/#{@id}/permissions")
    end

    # PATCH participant permissions
    # games/:game_id/participants/:id/permissions
    #
    # @return [Hash] Parsed body of the API response
    def permissions_update(params = {})
      participant_id_required
      @game.update(params, "participants/#{@id}/permissions")
    end

    private

    def participant_id_required
      @game.verify_id(@id, Errors::PARTICIPANT_ID_REQUIRED)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
strutta-api-1.0.3.1 lib/strutta-api/participants.rb
strutta-api-1.0.2 lib/strutta-api/participants.rb
strutta-api-1.0.1 lib/strutta-api/participants.rb