Permalink
Browse files

Add pagination to UserSearch

  • Loading branch information...
1 parent cbee721 commit d7c871c0f720d1bc8604f8a4545ea5353d142ed1 Layton Wedgeworth committed Aug 16, 2008
Showing with 22 additions and 2 deletions.
  1. +22 −2 lib/youtube_g/request/user_search.rb
@@ -1,17 +1,37 @@
class YouTubeG
module Request #:nodoc:
class UserSearch < BaseSearch #:nodoc:
+ attr_reader :max_results # max_results
+ attr_reader :order_by # orderby, ([relevance], viewCount, published, rating)
+ attr_reader :offset # start-index
+
def initialize(params, options={})
@url = base_url
- return @url << "#{options[:user]}/favorites" if params == :favorites
- @url << "#{params[:user]}/uploads" if params[:user]
+
+ if params == :favorites
+ @url << "#{options[:user]}/favorites"
+ elsif params[:user]
+ @url << "#{params[:user]}/uploads"
+ end
+
+ set_instance_variables(params)
+
+ @url << build_query_params(to_youtube_params)
end
private
def base_url #:nodoc:
super << "users/"
end
+
+ def to_youtube_params #:nodoc:
+ {
+ 'max-results' => @max_results,
+ 'orderby' => @order_by,
+ 'start-index' => @offset
+ }
+ end
end
end

0 comments on commit d7c871c

Please sign in to comment.