From 795d881626bd98fece7dbebb166b2ed7b4ae415c Mon Sep 17 00:00:00 2001 From: saurabhbhatia Date: Fri, 4 Oct 2013 10:15:57 +0800 Subject: [PATCH] Added video json api --- .../back_end/channel_videos_controller.rb | 25 +++++++++++++++++-- .../built_in_modules/video/config/routes.rb | 2 ++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/vendor/built_in_modules/video/app/controllers/panel/video/back_end/channel_videos_controller.rb b/vendor/built_in_modules/video/app/controllers/panel/video/back_end/channel_videos_controller.rb index e9ba49fe1..41a7e77ce 100644 --- a/vendor/built_in_modules/video/app/controllers/panel/video/back_end/channel_videos_controller.rb +++ b/vendor/built_in_modules/video/app/controllers/panel/video/back_end/channel_videos_controller.rb @@ -1,6 +1,6 @@ class Panel::Video::BackEnd::ChannelVideosController < OrbitBackendController before_filter :force_order_for_visitor,:only => [:index, :new, :edit, :delete] - before_filter :force_order_for_user,:except => [:index] + before_filter :force_order_for_user,:except => [:index, :get_channel_videos] def index @channel_videos = ChannelVideo.all @@ -17,7 +17,7 @@ class Panel::Video::BackEnd::ChannelVideosController < OrbitBackendController respond_to do |format| format.html - format.json { render json: @location } + format.json { render json: @channel_videos } end end @@ -55,4 +55,25 @@ class Panel::Video::BackEnd::ChannelVideosController < OrbitBackendController redirect_to panel_video_back_end_channel_videos_url end + + def get_channel_videos + @channel_video = ChannelVideo.all + @channel_video.each do |channel| + client = YouTubeIt::Client.new(:dev_key => "AI39si5KGPg8rhKLBfmeukit2tCSP_B9lT8igiNICbrbgUXQoAdYGvsyCGCmO1wGnr1OW4bDRv-ESolwk-rdBNIAgVTL9VYaEA") + @client_videos = client.videos_by(:user => channel.channel_name, :per_page => 5) + @data = Array.new + + + @client_videos.videos.each do |video| + url = video.player_url + title = video.title + description = video.description + author = video.author.name + # category_id = category.id.to_s + @data << { title: title, description: description, url: url, author: author} + end + + render :json => JSON.pretty_generate(@data) + end + end end \ No newline at end of file diff --git a/vendor/built_in_modules/video/config/routes.rb b/vendor/built_in_modules/video/config/routes.rb index c8a4c3aca..d3b74cc95 100644 --- a/vendor/built_in_modules/video/config/routes.rb +++ b/vendor/built_in_modules/video/config/routes.rb @@ -4,6 +4,8 @@ Rails.application.routes.draw do namespace :back_end do match "videos/get_videos" => "videos#get_videos" resources :videos + match "channel_videos/get_channel_videos" => "channel_videos#get_channel_videos" + resources :channel_videos end