require_relative '../../lib/qaplay_projects' require_relative '../../lib/localhost_projects' class ProjectsController < ApplicationController skip_before_action :verify_authenticity_token, if: :json_request? skip_before_action :verify_authenticity_token, only: [:project_login] before_action :validate_session def initialize @projects = ENV['RAILS_ENV'] == 'test' ? LocalhostProjects.new : QAPlayProjects.new end def list render :json => projects_list end def fetch project = project_from_id(params['id']) # TODO: fail if not found model = project.dup # add anything interesting here... render :json => model end protected def projects_list @projects.projects(@current_session[:user], @current_session[:p4ticket]) end def project_from_id(id) index = projects_list.index { |obj| obj['id'] == id } return projects_list[index] unless index.nil? end end