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)


44
45
46
47
48
# File 'lib/yourub/meta_search.rb', line 44

def get(video_id)
  params = {:id => video_id, :part => 'snippet,statistics'}
  request = Yourub::REST::Videos.list(self,params)
  Yourub::Result.format(request).first
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
30
31
32
33
34
35
36
37
# File 'lib/yourub/meta_search.rb', line 12

def search(criteria)
  begin
    Yourub::CountFilter.filter = nil

    @api_options= {
      :part            => 'snippet',
      :type            => 'video',
      :order           => 'relevance',
      :safeSearch      => 'none',
      :q               => nil
    }

    @categories = []
    @count_filter = {}

    @api_options[:q] = criteria[:query] if criteria[:query]

    @criteria = Yourub::Validator.confirm(criteria)
    search_by_criteria do |result|
      yield result
    end
  rescue ArgumentError => e
    Yourub.logger.error "#{e}"
    raise
  end
end