class PlasticineController < ApplicationController before_action :authenticate def show if @granted # set_default_to if params[:from] and not params[:to] builder = "Plasticine::Builder::#{params[:nature].camelize}".constantize.new(params[:id], params) visual_model.build builder respond_to do |format| format.json { render json: builder.to_json } end else respond_to do |format| format.json { render json: { 'state' => 'access_refused' } } end end end private def authenticate auth = Plasticine::Authentication.new(request.url, params) @granted = (auth.valid_token? and not auth.expired?) end def visual_model name = params[:id].underscore.camelize + 'Visual' begin name.constantize.new(params) rescue raise "Plasticine: You must defined #{name}" end end def set_default_to if params[:nature] == 'line' params[:to] = case params[:step] when 'day' then (Time.now.utc - 1.day).end_of_day.iso8601 when 'week' then (Time.now.utc - 1.week).end_of_week.iso8601 when 'month' then (Time.now.utc - 1.month).end_of_month.iso8601 else Time.now.utc.iso8601 end else params[:to] = Time.now.utc.iso8601 end end end