Skip to content

Commit

Permalink
Add pagination to UserSearch
Browse files Browse the repository at this point in the history
  • Loading branch information
Layton Wedgeworth committed Aug 16, 2008
1 parent cbee721 commit d7c871c
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions 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
Expand Down

0 comments on commit d7c871c

Please sign in to comment.