Module: Yourub::MetaSearch

Includes:
REST::API
Included in:
Client
Defined in:
lib/yourub/meta_search.rb

Instance Method Summary collapse

Methods included from REST::Videos

list, single_video

Methods included from REST::Categories

for_country

Methods included from REST::Search

list

Instance Method Details

#get(video_id) ⇒ Object

return an hash containing the metadata for the given video

Examples:

client = Yourub::Client.new
client.get("G2b0OIkTraI")

Parameters:

  • video_id (Integer)


48
49
50
51
52
# File 'lib/yourub/meta_search.rb', line 48

def get(video_id)
  params = {:id => video_id, :part => 'snippet,statistics'}
  request = Yourub::REST::Videos.list(self,params)
  Yourub::Result.format(request).first
end

#get_views(video_id) ⇒ Object

return the number of times a video was watched

Examples:

client = Yourub::Client.new
client.get_views("G2b0OIkTraI")

Parameters:

  • video_id (Integer)


36
37
38
39
40
41
# File 'lib/yourub/meta_search.rb', line 36

def get_views(video_id)
  params = { :id => video_id, :part => 'statistics' }
  request = Yourub::REST::Videos.list(self,params)
  v = Yourub::Result.format(request).first
  v ? Yourub::CountFilter.get_views_count(v) : nil
end

#search(criteria) ⇒ Object

Search through the youtube API, executing multiple queries where necessary

Examples:

client = Yourub::Client.new
client.search(country: "DE", category: "sports", order: 'date')

Parameters:

  • criteria (Hash)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/yourub/meta_search.rb', line 12

def search(criteria)
  begin
    @api_options= {
      :part            => 'snippet',
      :type            => 'video',
      :order           => 'relevance',
      :safeSearch      => 'none',
     }
    @categories = []
    @count_filter = {}
    @criteria = Yourub::Validator.confirm(criteria)
    search_by_criteria do |result|
      yield result
    end
  rescue ArgumentError => e
    Yourub.logger.error "#{e}"
  end
end