Class: YouTubeG::Request::VideoSearch

Inherits:
BaseSearch
  • Object
show all
Defined in:
lib/youtube_g/request/video_search.rb

Constant Summary collapse

ONLY_EMBEDDABLE =
5

Instance Attribute Summary collapse

Attributes inherited from BaseSearch

#url

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ VideoSearch

Returns a new instance of VideoSearch.



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/youtube_g/request/video_search.rb', line 58

def initialize(params={})
  # XXX I think we want to delete the line below
  return if params.nil?

  # initialize our various member data to avoid warnings and so we'll
  # automatically fall back to the youtube api defaults
  @max_results = nil
  @order_by = nil
  @offset = nil
  @query = nil
  @response_format = nil
  @video_format = nil

  # build up the url corresponding to this request
  @url = base_url
  
  # http://gdata.youtube.com/feeds/videos/T7YazwP8GtY
  return @url << "/" << params[:video_id] if params[:video_id]
  
  @url << "/-/" if (params[:categories] || params[:tags])
  @url << categories_to_params(params.delete(:categories)) if params[:categories]
  @url << tags_to_params(params.delete(:tags)) if params[:tags]

  params.each do |key, value| 
    name = key.to_s
    instance_variable_set("@#{name}", value) if respond_to?(name)
  end
  
  if( params[ :only_embeddable ] )
    @video_format = ONLY_EMBEDDABLE
  end

  @url << build_query_params(to_youtube_params)
end

Instance Attribute Details

#categoriesObject (readonly)

/-/Category1/Category2



55
56
57
# File 'lib/youtube_g/request/video_search.rb', line 55

def categories
  @categories
end

#max_resultsObject (readonly)

max_results



49
50
51
# File 'lib/youtube_g/request/video_search.rb', line 49

def max_results
  @max_results
end

#offsetObject (readonly)

start-index



51
52
53
# File 'lib/youtube_g/request/video_search.rb', line 51

def offset
  @offset
end

#order_byObject (readonly)

orderby, ([relevance], viewCount)



50
51
52
# File 'lib/youtube_g/request/video_search.rb', line 50

def order_by
  @order_by
end

#queryObject (readonly)

vq



52
53
54
# File 'lib/youtube_g/request/video_search.rb', line 52

def query
  @query
end

#response_formatObject (readonly)

alt, ([atom], rss, json)



53
54
55
# File 'lib/youtube_g/request/video_search.rb', line 53

def response_format
  @response_format
end

#tagsObject (readonly)

/-/tag1/tag2



54
55
56
# File 'lib/youtube_g/request/video_search.rb', line 54

def tags
  @tags
end

#video_formatObject (readonly)

format (1=mobile devices)



56
57
58
# File 'lib/youtube_g/request/video_search.rb', line 56

def video_format
  @video_format
end

Instance Method Details

#base_urlObject



93
94
95
# File 'lib/youtube_g/request/video_search.rb', line 93

def base_url
  super << "videos"
end

#to_youtube_paramsObject



97
98
99
100
101
102
103
104
105
106
# File 'lib/youtube_g/request/video_search.rb', line 97

def to_youtube_params
  {
    'max-results' => @max_results,
    'orderby' => @order_by,
    'start-index' => @offset,
    'vq' => @query,
    'alt' => @response_format,
    'format' => @video_format
  }
end