viddler-sitemaps 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +45 -0
- data/LICENSE.txt +20 -0
- data/README.md +7 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/bin/viddler_sitemap_generator +59 -0
- data/lib/viddler-sitemaps.rb +5 -0
- data/lib/viddler/sitemap.rb +87 -0
- data/lib/viddler/sitemap_file.rb +60 -0
- data/spec/data/simple_sitemap.xml +31 -0
- data/spec/sitemap_file_spec.rb +63 -0
- data/spec/sitemap_spec.rb +83 -0
- data/spec/spec_helper.rb +29 -0
- metadata +123 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.5)
|
5
|
+
i18n (~> 0.6)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
builder (3.0.0)
|
8
|
+
diff-lcs (1.1.3)
|
9
|
+
git (1.2.5)
|
10
|
+
i18n (0.6.0)
|
11
|
+
jeweler (1.8.3)
|
12
|
+
bundler (~> 1.0)
|
13
|
+
git (>= 1.2.5)
|
14
|
+
rake
|
15
|
+
rdoc
|
16
|
+
json (1.7.3)
|
17
|
+
mime-types (1.18)
|
18
|
+
multi_json (1.3.6)
|
19
|
+
rake (0.9.2.2)
|
20
|
+
rdoc (3.12)
|
21
|
+
json (~> 1.4)
|
22
|
+
rest-client (1.6.7)
|
23
|
+
mime-types (>= 1.16)
|
24
|
+
rspec (2.8.0)
|
25
|
+
rspec-core (~> 2.8.0)
|
26
|
+
rspec-expectations (~> 2.8.0)
|
27
|
+
rspec-mocks (~> 2.8.0)
|
28
|
+
rspec-core (2.8.0)
|
29
|
+
rspec-expectations (2.8.0)
|
30
|
+
diff-lcs (~> 1.1.2)
|
31
|
+
rspec-mocks (2.8.0)
|
32
|
+
viddler-ruby (0.1.2)
|
33
|
+
activesupport (> 2.3.0)
|
34
|
+
json
|
35
|
+
rest-client
|
36
|
+
|
37
|
+
PLATFORMS
|
38
|
+
ruby
|
39
|
+
|
40
|
+
DEPENDENCIES
|
41
|
+
builder
|
42
|
+
bundler (~> 1.1.0)
|
43
|
+
jeweler (~> 1.8.3)
|
44
|
+
rspec (~> 2.8.0)
|
45
|
+
viddler-ruby
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 viddler
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
DIY Video Sitemaps using The Viddler API (Ruby)
|
2
|
+
===============================================
|
3
|
+
|
4
|
+
A simple way to create your own video sitemap files for your site.
|
5
|
+
A PHP version of this (without a cli) exists at https://github.com/viddler/Video-Sitemaps
|
6
|
+
|
7
|
+
More details will be added soon
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "viddler-sitemaps"
|
18
|
+
gem.homepage = "https://github.com/viddler/video-sitemaps-ruby"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{DIY Video Sitemaps using The Viddler API}
|
21
|
+
gem.description = %Q{DIY Video Sitemaps using The Viddler API}
|
22
|
+
gem.email = "mail@matthewfawcett.co.uk"
|
23
|
+
gem.authors = ["viddler", "mattfawcett"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "viddler-sitemaps #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,59 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
# resolve bin path, ignoring symlinks
|
5
|
+
require 'pathname'
|
6
|
+
bin_file = Pathname.new(__FILE__).realpath
|
7
|
+
|
8
|
+
# add self to libpath
|
9
|
+
$:.unshift File.expand_path('../../lib', bin_file)
|
10
|
+
|
11
|
+
require 'optparse'
|
12
|
+
require 'viddler-sitemaps'
|
13
|
+
|
14
|
+
options = {}
|
15
|
+
|
16
|
+
opt_parser = OptionParser.new do |opt|
|
17
|
+
opt.banner = 'Usage: viddler_sitemap_generator -k apikey -u username -p password /path/to/public/folder'
|
18
|
+
opt.separator ''
|
19
|
+
|
20
|
+
opt.on('-k','--api-key API_KEY', 'Your Viddler API key') do |api_key|
|
21
|
+
options[:api_key] = api_key
|
22
|
+
end
|
23
|
+
|
24
|
+
opt.on('-u','--username USERNAME', 'Your Viddler usrname') do |username|
|
25
|
+
options[:username] = username
|
26
|
+
end
|
27
|
+
|
28
|
+
opt.on('-p','--password PASSWORD', 'Your Viddler password') do |password|
|
29
|
+
options[:password] = password
|
30
|
+
end
|
31
|
+
|
32
|
+
opt.on('-h','--help','help') do
|
33
|
+
puts opt_parser
|
34
|
+
exit
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
opt_parser.parse!
|
39
|
+
|
40
|
+
[:api_key, :username, :password].each do |option|
|
41
|
+
if options[option].nil?
|
42
|
+
puts "You must specify your #{option}"
|
43
|
+
puts opt_parser
|
44
|
+
exit
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
folder = ARGV.last
|
49
|
+
if folder
|
50
|
+
if File.directory?(folder)
|
51
|
+
sitemap = Viddler::Sitemap.new(options[:api_key], options[:username], options[:password])
|
52
|
+
indexed_videos = sitemap.generate!(folder)
|
53
|
+
puts "Indexed #{indexed_videos} videos to #{folder}"
|
54
|
+
else
|
55
|
+
puts "Folder #{folder} does not appear to exist"
|
56
|
+
end
|
57
|
+
else
|
58
|
+
puts 'You must specift the folder where you wish to save the sitemap files'
|
59
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
module Viddler
|
2
|
+
class Sitemap
|
3
|
+
API_PER_PAGE = 100
|
4
|
+
|
5
|
+
# Setup a new instance of Viddler Sitemap
|
6
|
+
# @param [String] api_key Viddler API key
|
7
|
+
# @param [String] username Viddler username
|
8
|
+
# @param [String] password Viddler password
|
9
|
+
def initialize(api_key, username, password)
|
10
|
+
@api_key, @username, @password = api_key, username, password
|
11
|
+
setup_client
|
12
|
+
end
|
13
|
+
|
14
|
+
# Generate the sitemap files(s) for your videos
|
15
|
+
#
|
16
|
+
# @param [String] folder The path to the folder where the sitemap files will be written to
|
17
|
+
# @return [Integer] the number of videos that were included in the index
|
18
|
+
def generate!(folder)
|
19
|
+
counter = 0
|
20
|
+
files.each_with_index do |file, index|
|
21
|
+
counter += file.videos.length
|
22
|
+
file.write!(folder, index+1)
|
23
|
+
end
|
24
|
+
return counter
|
25
|
+
end
|
26
|
+
|
27
|
+
# @return [Array] An array of SitemapFile objects each representing 1 sitemap file.
|
28
|
+
# There will normally be only 1 of these but could be more if there are lots of videos.
|
29
|
+
# There are a maxiumum of 5000 (default) videos per file.
|
30
|
+
def files
|
31
|
+
[].tap do |array|
|
32
|
+
array << SitemapFile.new
|
33
|
+
counter = 0
|
34
|
+
each_video do |video|
|
35
|
+
counter += 1
|
36
|
+
|
37
|
+
# Add the video to the current file
|
38
|
+
array.last.add_video(video)
|
39
|
+
|
40
|
+
# Reached 50k in this file, start a new file
|
41
|
+
array << SitemapFile.new if counter % Sitemap.max_videos_per_file == 0
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Yields each video that will be included in the sitemap
|
47
|
+
def each_video(&block)
|
48
|
+
page = 1
|
49
|
+
loop do
|
50
|
+
videos = videos_for_page(page)
|
51
|
+
videos.each { |v| yield v }
|
52
|
+
|
53
|
+
break if videos.length < API_PER_PAGE
|
54
|
+
page += 1
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# The maximum number of videos to be incuded in each sitemap file.
|
59
|
+
# @return [Integer] the maximum number. Defaults to 50000
|
60
|
+
def self.max_videos_per_file
|
61
|
+
@@max_videos_per_file ||= 50000
|
62
|
+
end
|
63
|
+
|
64
|
+
# Set the maximum number of videos that should be included in one sitemap file.
|
65
|
+
# Defaults to 50000 which is Google's maximum. You may want to lower this on systems
|
66
|
+
# with limited resources
|
67
|
+
# @param [Integer] value The maximum number
|
68
|
+
def self.max_videos_per_file=(value)
|
69
|
+
@@max_videos_per_file = value
|
70
|
+
end
|
71
|
+
|
72
|
+
private
|
73
|
+
# An authenticated instance of the API client
|
74
|
+
# @return [Viddler::Client]
|
75
|
+
def setup_client
|
76
|
+
@client = Viddler::Client.new(@api_key)
|
77
|
+
@client.authenticate!(@username, @password)
|
78
|
+
end
|
79
|
+
|
80
|
+
# Calls the API to return an array of videos for a certain page. The API will return a maximum
|
81
|
+
# of 100 pages per request
|
82
|
+
def videos_for_page(page_number)
|
83
|
+
@client.get('viddler.videos.getByUser', :user => @username, :per_page => API_PER_PAGE,
|
84
|
+
:page => page_number, :visibility => 'public,embed')['list_result']['video_list']
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module Viddler
|
2
|
+
class SitemapFile
|
3
|
+
# An array of video hash object that will be included in the SitemapFile
|
4
|
+
attr_reader :videos
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@videos = []
|
8
|
+
end
|
9
|
+
|
10
|
+
# Add a video to this sitemap file
|
11
|
+
# @param [Hash] video the video details hash from the API response
|
12
|
+
def add_video(video)
|
13
|
+
@videos << video
|
14
|
+
return true
|
15
|
+
end
|
16
|
+
|
17
|
+
# The XML string for this SitemapFile
|
18
|
+
# @return [String] the XML
|
19
|
+
def to_xml
|
20
|
+
@builder = Builder::XmlMarkup.new(:indent => 2)
|
21
|
+
@builder.instruct!(:xml, :version => '1.0', :encoding => 'UTF-8')
|
22
|
+
|
23
|
+
@builder.urlset('xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9',
|
24
|
+
'xmlns:video' => 'http://www.google.com/schemas/sitemap-video/1.1') do | xml|
|
25
|
+
@videos.each do |video|
|
26
|
+
downloadable = video['permissions'] && video['permissions']['download'] != 'private'
|
27
|
+
embedable = video['permissions'] && video['permissions']['embed'] != 'private'
|
28
|
+
|
29
|
+
xml.url do |xml|
|
30
|
+
xml.loc(video['permalink'])
|
31
|
+
xml.tag!('video:video') do
|
32
|
+
xml.tag!('video:thumbnail_loc', "http://www.viddler.com/thumbnail/#{video['id']}")
|
33
|
+
xml.tag!('video:title', video['title'])
|
34
|
+
xml.tag!('video:description', video['description'])
|
35
|
+
if downloadable
|
36
|
+
xml.tag!('video:content_loc', video['files'].first['url'])
|
37
|
+
end
|
38
|
+
xml.tag!('video:player_loc', "http://www.viddler.com/embed/#{video['id']}", :allow_embed => embedable ? 'yes' : 'no')
|
39
|
+
xml.tag!('video:duration', video['length'])
|
40
|
+
xml.tag!('video:view_count', video['view_count'])
|
41
|
+
xml.tag!('video:publication_date', Time.at(video['upload_time'].to_i).strftime('%Y-%m-%d'))
|
42
|
+
xml.tag!('video:family_friendly', 'yes')
|
43
|
+
xml.tag!('video:live', 'no')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
return @builder.target!
|
49
|
+
end
|
50
|
+
|
51
|
+
# Write the xml content for this SitemapFile to disk
|
52
|
+
# @param [String] folder The path to the folder where the sitemaps should be written
|
53
|
+
# @param [Integer] file_number The number of this file. Because there is a maximum number of videos per file, there may be multiple files.
|
54
|
+
def write!(folder, file_number)
|
55
|
+
path = "#{folder}/sitemap-#{file_number}.xml"
|
56
|
+
File.open(path, 'w') { |f| f.write(self.to_xml) }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
|
3
|
+
<url>
|
4
|
+
<loc>http://www.viddler.com/v/182d7551</loc>
|
5
|
+
<video:video>
|
6
|
+
<video:thumbnail_loc>http://www.viddler.com/thumbnail/182d7551</video:thumbnail_loc>
|
7
|
+
<video:title>vid8</video:title>
|
8
|
+
<video:description>Some <b>Strong</b> Description \n \n a new line</video:description>
|
9
|
+
<video:player_loc allow_embed="no">http://www.viddler.com/embed/182d7551</video:player_loc>
|
10
|
+
<video:duration>96</video:duration>
|
11
|
+
<video:view_count>0</video:view_count>
|
12
|
+
<video:publication_date>2012-05-25</video:publication_date>
|
13
|
+
<video:family_friendly>yes</video:family_friendly>
|
14
|
+
<video:live>no</video:live>
|
15
|
+
</video:video>
|
16
|
+
</url>
|
17
|
+
<url>
|
18
|
+
<loc>http://www.viddler.com/v/7e6eba64</loc>
|
19
|
+
<video:video>
|
20
|
+
<video:thumbnail_loc>http://www.viddler.com/thumbnail/7e6eba64</video:thumbnail_loc>
|
21
|
+
<video:title>vid9</video:title>
|
22
|
+
<video:description>A description goes here</video:description>
|
23
|
+
<video:player_loc allow_embed="no">http://www.viddler.com/embed/7e6eba64</video:player_loc>
|
24
|
+
<video:duration>96</video:duration>
|
25
|
+
<video:view_count>0</video:view_count>
|
26
|
+
<video:publication_date>2012-05-25</video:publication_date>
|
27
|
+
<video:family_friendly>yes</video:family_friendly>
|
28
|
+
<video:live>no</video:live>
|
29
|
+
</video:video>
|
30
|
+
</url>
|
31
|
+
</urlset>
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Viddler::SitemapFile do
|
4
|
+
describe '#to_xml' do
|
5
|
+
it 'should render the xml for the videos in the sitemap file' do
|
6
|
+
video_1 = {
|
7
|
+
'id' => '182d7551',
|
8
|
+
'status' => 'ready',
|
9
|
+
'author' => 'mattfawcett',
|
10
|
+
'title' => 'vid8',
|
11
|
+
'length' => '96',
|
12
|
+
'description' => 'Some <b>Strong</b> Description \n \n a new line',
|
13
|
+
'age_limit' => '',
|
14
|
+
'url' => 'http://www.viddler.com/v/182d7551',
|
15
|
+
'thumbnail_url' => 'http://cdn-thumbs.viddler.com/thumbnail_2_182d7551_v1.jpg',
|
16
|
+
'permalink' => 'http://www.viddler.com/v/182d7551',
|
17
|
+
'html5_video_source' => 'http://www.viddler.com/file/182d7551/html5',
|
18
|
+
'view_count' => '0',
|
19
|
+
'impression_count' => '0',
|
20
|
+
'upload_time' => '1337945626',
|
21
|
+
'made_public_time' => '1337946278',
|
22
|
+
'favorite' => '0',
|
23
|
+
'comment_count' => '0',
|
24
|
+
'display_aspect_ratio' => '4:3'
|
25
|
+
}
|
26
|
+
video_2 = {
|
27
|
+
'id' => '7e6eba64',
|
28
|
+
'status' => 'ready',
|
29
|
+
'author' => 'mattfawcett',
|
30
|
+
'title' => 'vid9',
|
31
|
+
'length' => '96',
|
32
|
+
'description' => 'A description goes here',
|
33
|
+
'age_limit' => '',
|
34
|
+
'url' => 'http://www.viddler.com/v/7e6eba64',
|
35
|
+
'thumbnail_url' => 'http://cdn-thumbs.viddler.com/thumbnail_2_7e6eba64_v1.jpg',
|
36
|
+
'permalink' => 'http://www.viddler.com/v/7e6eba64',
|
37
|
+
'html5_video_source' => 'http://www.viddler.com/file/7e6eba64/html5',
|
38
|
+
'view_count' => '0',
|
39
|
+
'impression_count' => '0',
|
40
|
+
'upload_time' => '1337945626',
|
41
|
+
'made_public_time' => '1337946278',
|
42
|
+
'favorite' => '0',
|
43
|
+
'comment_count' => '0',
|
44
|
+
'display_aspect_ratio' => '4:3'
|
45
|
+
}
|
46
|
+
sitemap_file = Viddler::SitemapFile.new
|
47
|
+
sitemap_file.add_video(video_1)
|
48
|
+
sitemap_file.add_video(video_2)
|
49
|
+
|
50
|
+
expected = File.read('spec/data/simple_sitemap.xml')
|
51
|
+
sitemap_file.to_xml.should == expected
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '#write!' do
|
56
|
+
it 'should write the contents to the correct place' do
|
57
|
+
sitemap_file = Viddler::SitemapFile.new
|
58
|
+
sitemap_file.should_receive(:to_xml).and_return('dummy xml')
|
59
|
+
sitemap_file.write!(File.dirname(__FILE__) + '/tmp', 2)
|
60
|
+
File.read('spec/tmp/sitemap-2.xml').should == 'dummy xml'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Viddler::Sitemap do
|
4
|
+
before(:each) do
|
5
|
+
Viddler::Client.any_instance.stub(:authenticate!).with('myusername', 'mypassword')
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '#setup_client' do
|
9
|
+
it 'should setup a Vidder::Client object using the API key' do
|
10
|
+
Viddler::Client.any_instance.should_receive(:authenticate!).with('myusername', 'mypassword')
|
11
|
+
@sitemap = Viddler::Sitemap.new('myapikey', 'myusername', 'mypassword')
|
12
|
+
|
13
|
+
client = @sitemap.instance_variable_get('@client')
|
14
|
+
client.should be_a(Viddler::Client)
|
15
|
+
client.api_key.should == 'myapikey'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#each_video' do
|
20
|
+
it 'should include an array of all videos, calling the API for each page until all retrieved' do
|
21
|
+
@sitemap = Viddler::Sitemap.new('myapikey', 'myusername', 'mypassword')
|
22
|
+
client = @sitemap.instance_variable_get('@client')
|
23
|
+
|
24
|
+
client.should_receive(:get).with('viddler.videos.getByUser', hash_including(:user => 'myusername', :page => 1))
|
25
|
+
.and_return({'list_result' => {'video_list' => dummy_videos(100, 'page1')}})
|
26
|
+
client.should_receive(:get).with('viddler.videos.getByUser', hash_including(:user => 'myusername', :page => 2))
|
27
|
+
.and_return({'list_result' => {'video_list' => dummy_videos(100, 'page2')}})
|
28
|
+
client.should_receive(:get).with('viddler.videos.getByUser', hash_including(:user => 'myusername', :page => 3))
|
29
|
+
.and_return({'list_result' => {'video_list' => dummy_videos(50, 'page3')}})
|
30
|
+
|
31
|
+
client.should_not_receive(:get).with('viddler.videos.getByUser', hash_including(:user => 'myusername', :page => 4))
|
32
|
+
|
33
|
+
videos = []
|
34
|
+
@sitemap.each_video { |v| videos << v }
|
35
|
+
videos.length.should == 250
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#files' do
|
40
|
+
before(:each) do
|
41
|
+
setup_big_sitemap
|
42
|
+
Viddler::Sitemap.max_videos_per_file = 50
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should return an array of SiteMapFile objects' do
|
46
|
+
@sitemap.files.length.should == 3
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should assign a maximum of 50 videos per file' do
|
50
|
+
@sitemap.files[0].videos.length.should == 50
|
51
|
+
@sitemap.files[1].videos.length.should == 50
|
52
|
+
@sitemap.files[2].videos.length.should == 10
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#generate!' do
|
57
|
+
before(:each) do
|
58
|
+
setup_big_sitemap
|
59
|
+
Viddler::Sitemap.max_videos_per_file = 50
|
60
|
+
@path = File.dirname(__FILE__) + '/tmp'
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should return the total number of videos indexed' do
|
64
|
+
@sitemap.generate!(@path).should == 110
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should write the sitemaps to the specified directory' do
|
68
|
+
@sitemap.generate!(@path)
|
69
|
+
File.exists?('spec/tmp/sitemap-1.xml').should == true
|
70
|
+
File.exists?('spec/tmp/sitemap-2.xml').should == true
|
71
|
+
File.exists?('spec/tmp/sitemap-3.xml').should == true
|
72
|
+
File.exists?('spec/tmp/sitemap-4.xml').should == false
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def setup_big_sitemap
|
77
|
+
@sitemap = Viddler::Sitemap.new('myapikey', 'myusername', 'mypassword')
|
78
|
+
|
79
|
+
# Fake it so that it looks like the user has 110,000 vides
|
80
|
+
@sitemap.stub!(:videos_for_page).with(1).and_return(dummy_videos 110)
|
81
|
+
@sitemap.stub!(:videos_for_page).with(2).and_return([])
|
82
|
+
end
|
83
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'viddler-sitemaps'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
config.before(:each) { delete_tmp_folder; ensure_tmp_folder_exists }
|
12
|
+
config.after(:each) { delete_tmp_folder }
|
13
|
+
|
14
|
+
def ensure_tmp_folder_exists
|
15
|
+
FileUtils.mkdir('spec/tmp')
|
16
|
+
end
|
17
|
+
|
18
|
+
def delete_tmp_folder
|
19
|
+
FileUtils.rm_rf('spec/tmp')
|
20
|
+
end
|
21
|
+
|
22
|
+
def dummy_videos(number, prefix='vid')
|
23
|
+
return [].tap do |videos|
|
24
|
+
number.times do |n|
|
25
|
+
videos << {'id' => "#{prefix}#{number}"}
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: viddler-sitemaps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- viddler
|
9
|
+
- mattfawcett
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2012-06-14 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: viddler-ruby
|
17
|
+
requirement: &70096716444280 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *70096716444280
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: builder
|
28
|
+
requirement: &70096716442980 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *70096716442980
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
requirement: &70096716442400 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ~>
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.8.0
|
45
|
+
type: :development
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: *70096716442400
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
50
|
+
requirement: &70096716441820 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.1.0
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70096716441820
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: jeweler
|
61
|
+
requirement: &70096716441020 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ~>
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 1.8.3
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *70096716441020
|
70
|
+
description: DIY Video Sitemaps using The Viddler API
|
71
|
+
email: mail@matthewfawcett.co.uk
|
72
|
+
executables:
|
73
|
+
- viddler_sitemap_generator
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files:
|
76
|
+
- LICENSE.txt
|
77
|
+
- README.md
|
78
|
+
files:
|
79
|
+
- .document
|
80
|
+
- .rspec
|
81
|
+
- Gemfile
|
82
|
+
- Gemfile.lock
|
83
|
+
- LICENSE.txt
|
84
|
+
- README.md
|
85
|
+
- Rakefile
|
86
|
+
- VERSION
|
87
|
+
- bin/viddler_sitemap_generator
|
88
|
+
- lib/viddler-sitemaps.rb
|
89
|
+
- lib/viddler/sitemap.rb
|
90
|
+
- lib/viddler/sitemap_file.rb
|
91
|
+
- spec/data/simple_sitemap.xml
|
92
|
+
- spec/sitemap_file_spec.rb
|
93
|
+
- spec/sitemap_spec.rb
|
94
|
+
- spec/spec_helper.rb
|
95
|
+
homepage: https://github.com/viddler/video-sitemaps-ruby
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - ! '>='
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
hash: -1273621280096321863
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 1.8.11
|
120
|
+
signing_key:
|
121
|
+
specification_version: 3
|
122
|
+
summary: DIY Video Sitemaps using The Viddler API
|
123
|
+
test_files: []
|