From b6c831714ab592b8eac79d8970de581574f51fbc Mon Sep 17 00:00:00 2001 From: Ruling-Mac Date: Wed, 21 Oct 2015 14:39:30 +0800 Subject: [PATCH] add youtube api --- .../admin/video_channels_controller.rb | 8 +++++++ app/controllers/video_channels_controller.rb | 22 +++++++++++++++++++ .../admin/video_channels/_index.html.erb | 2 +- app/views/admin/video_channels/show.html.erb | 10 +++++++++ app/views/video_channels/index.html.erb | 4 +++- 5 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 app/views/admin/video_channels/show.html.erb diff --git a/app/controllers/admin/video_channels_controller.rb b/app/controllers/admin/video_channels_controller.rb index a317013..7d6be27 100644 --- a/app/controllers/admin/video_channels_controller.rb +++ b/app/controllers/admin/video_channels_controller.rb @@ -30,6 +30,14 @@ class Admin::VideoChannelsController < OrbitAdminController end end + def show + @video_channel = VideoChannel.find(params[:id]) + channel_id = @video_channel.channel_link.split("/")[-1] + uri = URI('https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=' + channel_id + '&key=AIzaSyCTFdyLgb7GJfrr1JOI3gvVslZFw7td2zQ') + @r = Net::HTTP.get(uri) # => String + @r = JSON.parse(@r) + end + def update video_channel = VideoChannel.find(params[:id]) diff --git a/app/controllers/video_channels_controller.rb b/app/controllers/video_channels_controller.rb index 002ab84..7c1c71b 100644 --- a/app/controllers/video_channels_controller.rb +++ b/app/controllers/video_channels_controller.rb @@ -1,3 +1,25 @@ class VideoChannelsController < ApplicationController + def index + + end + def show + @video_channel = VideoChannel.find(params[:id]) + channel_id = @video_channel.channel_link.split("/")[-1] + uri = URI('https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=' + channel_id + '&key=AIzaSyCTFdyLgb7GJfrr1JOI3gvVslZFw7td2zQ') + result = Net::HTTP.get(uri) # => String + result = JSON.parse(result) + + nextPageToken = result['nextPageToken'] + videos = {} + + while !nextPageToken.nil? + result['items'].each do item + video = item['snippet'] + + + end + end + + end end \ No newline at end of file diff --git a/app/views/admin/video_channels/_index.html.erb b/app/views/admin/video_channels/_index.html.erb index 08c9225..dfdf46f 100644 --- a/app/views/admin/video_channels/_index.html.erb +++ b/app/views/admin/video_channels/_index.html.erb @@ -14,7 +14,7 @@ <% @video_channels.each do |video_channel| %> - <%= video_channel.title %> + <%= video_channel.title %>