pboksz/steam-card-tracker

View on GitHub
app/controllers/api/games_controller.rb

Summary

Maintainability
A
0 mins
Test Coverage
class Api::GamesController < ApplicationController
  def index
    render json: games_repository.all.as_json
  end

  def show
    render json: game.as_full_json, status: :ok
  rescue => e
    render json: e.message, status: :unprocessable_entity
  end

  def parse
    updated_game = listings_parser(game).parse
    render json: updated_game.as_json, status: :ok
  rescue => e
    render json: e.message, status: :unprocessable_entity
  end

  private

  def games_repository
    @games_repository ||= DefaultRepository.new(Game)
  end

  def game
    @game ||= games_repository.find(id: params[:id])
  end

  def listings_parser(game)
    ListingsParser.new(game)
  end
end