module Workarea module Storefront class YoutubeVideosController < Storefront::ApplicationController include DisplayContent before_action :cache_page def content_lookup 'Cart' end def index all_playlists if @all_playlists && @all_playlists["kind"] == "youtube#playlistListResponse" @all_playlists["items"].each do |playlist| playlist["video"]= get_video_data(playlist["id"], {maxResults: 3}) end @youtube = @all_playlists else @youtube = false end # @youtube = false end def show overrides = { maxResults: Workarea.config.youtube_video_per_page } overrides[:pageToken] = params[:page_id] @videos = get_video_data(params[:id], overrides) # @videos = false end def get_playlists(ids) list_data = get_list_data({:id => ids}) list_data["items"].each do |playlist| playlist["video"]= get_video_data(playlist["id"], {maxResults: 3}) end list_data end def all_playlists overrides = {pageToken: params[:page_id] } @all_playlists ||= get_list_data(overrides) end def get_video_data(id, overrides) response = JSON.parse(YoutubePlaylists.get_video_data(id, overrides).read) end def get_list_data(overrides) response = JSON.parse(YoutubePlaylists.get_list_data(overrides).read) end end end end