Advertisement
nadeemjq

events_controller.rb

Jan 5th, 2017
301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.81 KB | None | 0 0
  1. # encoding: UTF-8
  2. class EventsController < ApplicationController
  3.  
  4.   before_action :set_client
  5.   before_action :set_resource_and_identifier
  6.  
  7.   def index
  8.    
  9.     # Somebody's looking for lectures,  ey? Well, let's look too!
  10.     events = @api.events_for @resource, @identifier, params
  11.  
  12.     # Give the poor guy his lectures
  13.     render json: events, root: false
  14.  
  15.   end
  16.  
  17.   private
  18.  
  19.     def set_client
  20.  
  21.       # Load the correct API for given client
  22.       @client = Client.find_by_id params[:client_id]
  23.  
  24.       require_dependency "#{Rails.root}/lib/api/#{@client.api_name}/#{@client.api_name}"
  25.  
  26.       @api = @client.api_name.capitalize.constantize
  27.      
  28.     end
  29.  
  30.     def set_resource_and_identifier
  31.       res, @identifier = request.path.split('/')[3, 4]
  32.       @resource = res.singularize
  33.     end
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement