Last active
August 10, 2017 09:54
-
-
Save ParthBarot-BoTreeConsulting/4ed1a71864ff17160bd0db032251036e to your computer and use it in GitHub Desktop.
Youtube API integration using YT gem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Old code, which has a loop and sends API call for each video ID | |
# | |
video_ids.map do |video_id| | |
Yt::Video.new(id: video_id).select(:snippet, :content_details, :statistics, :status) | |
end | |
# | |
#New code, which fetches all the videos (max upto 12 IDs only) at once | |
# | |
@videos = Yt::Collections::Videos.new.where(id: video_ids, #video_ids has at max 12 ids only! | |
part: 'id,snippet,content_details,statistics,status' | |
) | |
@videos.first #This is needed to initiate the YT API call and load the data. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment