module Youtube
  extend ActiveSupport::Concern

  class << self

   def get_views(video_id)
      uri = "https://www.googleapis.com/youtube/v3/videos"
      stats_query = {
        key: Source.find_by(name:"YouTube").key,
        part: 'statistics',
        id: video_id
      }
      response = HTTParty.get uri, query: stats_query
      return response["items"][0]["statistics"]["viewCount"].to_i
    end

  end
end #Youtube
