Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

adding safe_search params to videos_by method

  • Loading branch information...
commit 458a43ade32d3b3d0eb7d3257b1e16e38c520256 1 parent 5b29cda
@chebyte chebyte authored
View
6 README.rdoc
@@ -84,6 +84,12 @@ Advanced Queries (with boolean operators OR (either), AND (include), NOT (exclud
$ client.videos_by(:categories => { :either => [:news, :sports], :exclude => [:comedy] }, :tags => { :include => ['football'], :exclude => ['soccer'] })
+Queries for safeSearch
+ The safe_search parameter indicates whether the search results should include restricted content as well as standard content.
+ The following values are valid for this parameter: none, moderate(default), strict
+
+ $ client.videos_by(:query => "penguin", :safe-search => "strict")
+
Fields Parameter(experimental features):
Return videos more than 1000 views
$ client.videos_by(:fields => {:view_count => "1000"})
View
2  lib/youtube_it/client.rb
@@ -38,7 +38,7 @@ def initialize *params
#
# If fetching videos by tags, categories, query:
# params<Hash>:: Accepts the keys :tags, :categories, :query, :order_by,
- # :author, :racy, :response_format, :video_format, :page (default is 1),
+ # :author, :safe_search, :response_format, :video_format, :page (default is 1),
# and :per_page(default is 25)
#
# options<Hash>:: Not used. (Optional)
View
5 lib/youtube_it/model/video.rb
@@ -68,7 +68,7 @@ def self.by_code(format_code)
attr_reader :position
# *Boolean*:: Specifies that a video is flagged as adult or not.
- attr_reader :racy
+ attr_reader :safe_search
# *String*: Specifies a URI that uniquely and permanently identifies the video.
attr_reader :video_id
@@ -205,8 +205,9 @@ def embed_html5(params = {})
:frameborder => params[:frameborder] || "0",
:url_params => params[:url_params] || {}
}
+ url_opts = opts[:url_params].empty? ? "" : "?#{Rack::Utils::build_query(opts[:url_params])}"
<<EDOC
-<iframe class="#{opts[:class]}" id="#{opts[:id]}" type="text/html" width="#{opts[:width]}" height="#{opts[:height]}" src="http://www.youtube.com/embed/#{unique_id}?#{Rack::Utils::build_query(opts[:url_params])}" frameborder="#{opts[:frameborder]}"></iframe>
+<iframe class="#{opts[:class]}" id="#{opts[:id]}" type="text/html" width="#{opts[:width]}" height="#{opts[:height]}" src="http://www.youtube.com/embed/#{unique_id}#{url_opts}" frameborder="#{opts[:frameborder]}"></iframe>
EDOC
end
View
6 lib/youtube_it/parser.rb
@@ -444,8 +444,8 @@ def parse_entry(entry)
view_count, favorite_count = 0,0
end
- noembed = entry.elements["yt:noembed"] ? true : false
- racy = entry.elements["media:rating"] ? true : false
+ noembed = entry.elements["yt:noembed"] ? true : false
+ safe_search = entry.elements["media:rating"] ? true : false
if where = entry.elements["georss:where"]
position = where.elements["gml:Point"].elements["gml:pos"].text
@@ -485,7 +485,7 @@ def parse_entry(entry)
:favorite_count => favorite_count,
:widescreen => widescreen,
:noembed => noembed,
- :racy => racy,
+ :safe_search => safe_search,
:position => position,
:latitude => latitude,
:longitude => longitude,
View
6 lib/youtube_it/request/video_search.rb
@@ -14,7 +14,7 @@ class VideoSearch < BaseSearch #:nodoc:
attr_reader :tags # /-/tag1/tag2
attr_reader :categories # /-/Category1/Category2
attr_reader :video_format # format (1=mobile devices)
- attr_reader :racy # racy ([exclude], include)
+ attr_reader :safe_search # safeSearch (none, [moderate], strict)
attr_reader :author
attr_reader :lang # lt
attr_reader :restriction
@@ -26,7 +26,7 @@ def initialize(params={})
@max_results, @order_by,
@offset, @query,
@response_format, @video_format,
- @racy, @author, @lang = nil
+ @safe_search, @author, @lang = nil
@url = base_url
@dev_key = params[:dev_key] if params[:dev_key]
@@ -62,7 +62,7 @@ def to_youtube_params
'q' => @query,
'alt' => @response_format,
'format' => @video_format,
- 'racy' => @racy,
+ 'safeSearch' => @safe_search,
'author' => @author,
'restriction' => @restriction,
'lr' => @lang
View
9 test/test_client.rb
@@ -392,7 +392,14 @@ def test_configure_faraday_adapter
YouTubeIt.adapter = :net_http
assert YouTubeIt.adapter == :net_http
end
-
+
+ def test_safe_search_params
+ @videos = @client.videos_by(:query => "porno", :safe_search => 'none').videos
+ assert_equal @videos.count, 25
+ @videos = @client.videos_by(:query => "porno", :safe_search => 'strict').videos
+ assert_equal @videos.count, 0
+ end
+
private
def assert_valid_video (video)
View
11 test/test_video_feed_parser.rb
@@ -41,10 +41,10 @@ def test_should_parse_noembed_correctly
end
end
- def test_should_parse_racy_correctly
+ def test_should_parse_safe_search_correctly
with_video_response do |parser|
video = parser.parse
- assert_equal false, video.racy
+ assert_equal false, video.safe_search
end
end
@@ -183,13 +183,6 @@ def test_should_parse_dislikes_correctly
# TOD: GEODATA
- def test_should_parse_where_geodata_correctly
- with_video_response do |parser|
- video = parser.parse
- assert_equal nil, video.where
- end
- end
-
def test_should_parse_position_geodata_correctly
with_video_response do |parser|
video = parser.parse
Please sign in to comment.
Something went wrong with that request. Please try again.