Class: Viddler::Sitemap
- Inherits:
-
Object
- Object
- Viddler::Sitemap
- Defined in:
- lib/viddler/sitemap.rb
Constant Summary collapse
- API_PER_PAGE =
100
Class Method Summary collapse
-
.max_videos_per_file ⇒ Integer
The maximum number of videos to be incuded in each sitemap file.
-
.max_videos_per_file=(value) ⇒ Object
Set the maximum number of videos that should be included in one sitemap file.
Instance Method Summary collapse
-
#each_video(&block) ⇒ Object
Yields each video that will be included in the sitemap.
-
#files ⇒ Array
An array of SitemapFile objects each representing 1 sitemap file.
-
#generate!(folder) ⇒ Integer
Generate the sitemap files(s) for your videos.
-
#initialize(api_key, username, password) ⇒ Sitemap
constructor
Setup a new instance of Viddler Sitemap.
Constructor Details
#initialize(api_key, username, password) ⇒ Sitemap
Setup a new instance of Viddler Sitemap
9 10 11 12 |
# File 'lib/viddler/sitemap.rb', line 9 def initialize(api_key, username, password) @api_key, @username, @password = api_key, username, password setup_client end |
Class Method Details
.max_videos_per_file ⇒ Integer
The maximum number of videos to be incuded in each sitemap file.
60 61 62 |
# File 'lib/viddler/sitemap.rb', line 60 def self.max_videos_per_file @@max_videos_per_file ||= 50000 end |
.max_videos_per_file=(value) ⇒ Object
Set the maximum number of videos that should be included in one sitemap file. Defaults to 50000 which is Google's maximum. You may want to lower this on systems with limited resources
68 69 70 |
# File 'lib/viddler/sitemap.rb', line 68 def self.max_videos_per_file=(value) @@max_videos_per_file = value end |
Instance Method Details
#each_video(&block) ⇒ Object
Yields each video that will be included in the sitemap
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/viddler/sitemap.rb', line 47 def each_video(&block) page = 1 loop do videos = videos_for_page(page) videos.each { |v| yield v } break if videos.length < API_PER_PAGE page += 1 end end |
#files ⇒ Array
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/viddler/sitemap.rb', line 30 def files [].tap do |array| array << SitemapFile.new counter = 0 each_video do |video| counter += 1 # Add the video to the current file array.last.add_video(video) # Reached 50k in this file, start a new file array << SitemapFile.new if counter % Sitemap.max_videos_per_file == 0 end end end |
#generate!(folder) ⇒ Integer
Generate the sitemap files(s) for your videos
18 19 20 21 22 23 24 25 |
# File 'lib/viddler/sitemap.rb', line 18 def generate!(folder) counter = 0 files.each_with_index do |file, index| counter += file.videos.length file.write!(folder, index+1) end return counter end |