Skip to content

Instantly share code, notes, and snippets.

@ParthBarot-BoTreeConsulting
Last active August 10, 2017 09:54

Revisions

  1. ParthBarot-BoTreeConsulting revised this gist Aug 10, 2017. 1 changed file with 6 additions and 2 deletions.
    8 changes: 6 additions & 2 deletions video_youtube_integration.rb
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,7 @@
    #
    # 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
    @@ -10,6 +11,9 @@
    #
    #New code, which fetches all the videos (max upto 12 IDs only) at once
    #
    Yt::Collections::Videos.new.where(id: video_ids, #video_ids has at max 12 ids only!

    @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.
  2. ParthBarot-BoTreeConsulting created this gist Aug 10, 2017.
    15 changes: 15 additions & 0 deletions video_youtube_integration.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@

    #
    # 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
    #
    Yt::Collections::Videos.new.where(id: video_ids, #video_ids has at max 12 ids only!
    part: 'id,snippet,content_details,statistics,status'
    )