Class: YouTube::YouTubeAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/share_learning/youtube_api.rb

Overview

using YouTube API to get playlists

Constant Summary collapse

YouTube_URL =
'https://www.googleapis.com/youtube/v3/search?part=snippet' + \
'&type=playlist&order=relevance&maxResults=' + max_results.to_s

Class Method Summary collapse

Class Method Details

.configObject



15
16
17
18
# File 'lib/share_learning/youtube_api.rb', line 15

def self.config
  return @config if @config
  @config = { api_key: ENV['YOUTUBE_API_KEY'] } # export YOUTUBE_API_KEY=....
end

.config=(credentials) ⇒ Object



11
12
13
# File 'lib/share_learning/youtube_api.rb', line 11

def self.config=(credentials)
  @config ? @config.update(credentials) : @config = credentials
end

.get_playlist(keyword) ⇒ Object

Retrieve the search results



21
22
23
24
25
26
# File 'lib/share_learning/youtube_api.rb', line 21

def self.get_playlist(keyword)
  search_response =
    HTTP.get(YouTube_URL + '&q=' + keyword.split().join('+') + \
      '&key=' + config[:api_key])
  JSON.parse(search_response)
end