Class: YahooVideo::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/yahoo-video.rb

Constant Summary collapse

DEFAULT_API_URL =

the default hostname queried to retrieve yahoo video content.

'http://search.yahooapis.com/VideoSearchService/V1/videoSearch'
DEFAULT_AGENT =

the default user agent submitted with http requests of yahoo video.

'yahoo-video for Ruby (http://www.rubyforge.org/projects/yahoo-video/)'

Instance Method Summary collapse

Constructor Details

#initialize(app_id, api_url = DEFAULT_API_URL, agent = DEFAULT_AGENT) ⇒ Client

constructs a Client with the supplied parameters as:

  • app_id: the Yahoo! Video application id to submit with API requests.

  • api_url: the root url via which to make requests of the Yahoo! Video API.

  • agent: the user agent to pass along with http requests made of the Yahoo! Video API.



211
212
213
214
215
# File 'lib/yahoo-video.rb', line 211

def initialize (app_id, api_url = DEFAULT_API_URL, agent = DEFAULT_AGENT)
  @app_id = app_id
  @api_url = api_url
  @agent = agent
end

Instance Method Details

#search(request) ⇒ Object

submits a search request of the Yahoo! Video service with the supplied SearchRequest parameters, returning a SearchResponse record detailing the results.



220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/yahoo-video.rb', line 220

def search (request)
  # submit the api request
  url = _video_search_url(request)
  response = _request(url)
  
  # build an xml document with which to analyze the results
  doc = REXML::Document.new response
  root = doc.root

  # parse out all of the search result records
  results = []
  root.elements.each('Result') do |re|
    # parse out the thumbnail record
    te = re.elements["Thumbnail"]
    thumbnail = Thumbnail.new(:url => te.elements["Url"].text,
                              :width => _text_or_nil(te, "Height", 'to_i'),
                              :height => _text_or_nil(te, "Height", 'to_i'))

    # tack on the new search result record
    results << SearchResult.new(:title => re.elements["Title"].text,
                                :summary => re.elements["Summary"].text,
                                :click_url => re.elements["ClickUrl"].text,
                                :url => re.elements["Url"].text,
                                :referer_url => re.elements["RefererUrl"].text,
                                :file_size => re.elements["FileSize"].text.to_i,
                                :file_format => re.elements["FileFormat"].text,
                                :height => re.elements["Height"].text.to_i,
                                :width => re.elements["Width"].text.to_i,
                                :duration => re.elements["Duration"].text.to_i,
                                :streaming => YahooVideo::_string_to_boolean(re.elements["Streaming"].text),
                                :channels => re.elements["Channels"].text.to_i,
                                :thumbnail => thumbnail)
  end

  # construct and return our final response record
  SearchResponse.new(:first_result_position => root.attributes['firstResultPosition'].to_i,
                     :results => results,
                     :total_results_available => root.attributes['totalResultsAvailable'].to_i,
                     :total_results_returned => root.attributes['totalResultsReturned'].to_i)
end