Module: VkMusic::Utility::PlaylistSectionLoader

Defined in:
lib/vk_music/utility/playlist_section_loader.rb

Overview

Load sections into playlist

Class Method Summary collapse

Class Method Details

.call(agent, client_id, owner_id, playlist_id, access_hash, offset, up_to) ⇒ Array<Audio>

Parameters:

  • agent (Mechanize)
  • client_id (Integer)
  • owner_id (Integer)
  • playlist_id (Integer)
  • access_hash (String, nil)
  • offset (Integer)
  • up_to (Integer)

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/vk_music/utility/playlist_section_loader.rb', line 15

def self.call(agent, client_id, owner_id, playlist_id, access_hash, offset, up_to)
  audios = []

  while audios.size < up_to
    section = Request::PlaylistSection.new(owner_id, playlist_id, access_hash, offset + audios.size, client_id)
    section.call(agent)
    audios.concat(section.audios)
    break if section.audios.empty? || !section.more?
  end

  audios.first(up_to)
end