Sha256: 09fabd4b9839b8fe3766e91f96233bfef39b7fb3feb1c34adee3df659d641e88

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

# Strutta Container
module Strutta
  # @abstract
  # APIObject contains all the HTTP request methods
  class APIObject
    attr_accessor :game

    # GET index request
    # (Uses instance vars of child object to generate resource path)
    #
    # @return [Hash] Parsed body of the API response
    def all(params = {})
      @game.verify_no_id(@id)
      @game.all(params, "#{@game.id}/#{@root_path}")
    end

    # POST request
    # (Uses instance vars of child object to generate resource path)
    #
    # @return [Hash] Parsed body of the API response
    def create(params = {})
      @game.verify_no_id(@id)
      @game.create(params, "#{@game.id}/#{@root_path}")
    end

    # GET request
    # (Uses instance vars of child object to generate resource path)
    #
    # @return [Hash] Parsed body of the API response
    def get(params = {})
      @game.verify_id(@id, Errors::ROUND_ID_REQUIRED)
      @game.get(params, @root_path)
    end

    # PATCH request
    # (Uses instance vars of child object to generate resource path)
    #
    # @return [Hash] Parsed body of the API response
    def update(params = {})
      @game.verify_id(@id, Errors::ROUND_ID_REQUIRED)
      @game.update(params, @root_path)
    end

    # DELETE request
    # (Uses instance vars of child object to generate resource path)
    #
    # @return [Hash] Parsed body of the API response
    def delete
      @game.verify_id(@id, Errors::ROUND_ID_REQUIRED)
      @game.delete(@root_path)
    end

    # Manually disable a method in child classed
    def method_disabled(*_)
      fail Errors::DisabledEndpointError, Errors::METHOD_DISABLED
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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