Parent

Files

Nicovideo::Thumbnail

Public Class Methods

new(proxy_url = nil) click to toggle source
# File lib/nicovideo/thumbnail.rb, line 7
def initialize(proxy_url = nil)
  @proxy_url =  proxy_url
end

Public Instance Methods

get(video_id, wait_sec = 10, retry_max = 2) click to toggle source
# File lib/nicovideo/thumbnail.rb, line 11
def get(video_id, wait_sec = 10, retry_max = 2)
        root = get_response(video_id, wait_sec, retry_max)
        
        get_elements(root.elements["thumb"])
end
get_elements(parent) click to toggle source
# File lib/nicovideo/thumbnail.rb, line 36
      def get_elements(parent)
              thumbnail_info = ThumbInfo.new

              parent.each_element do |element|
                      if element.name == 'tags' then
thumbnail_info.tags[element.attributes['domain']] = []
element.each_element do |child|
  thumbnail_info.tags[element.attributes['domain']] << child.text
end
                              next
                end
                      thumbnail_info[element.name] = element.text
              end
      thumbnail_info
      end
get_response(video_id, wait_sec, retry_max) click to toggle source
# File lib/nicovideo/thumbnail.rb, line 17
          def get_response(video_id, wait_sec, retry_max)
                  retry_count = 0
begin
  body = timeout(wait_sec) do
    open("http://ext.nicovideo.jp/api/getthumbinfo/#{video_id}", :proxy => @proxy_url) do |f|
      f.read
    end
  end

  root = REXML::Document.new(body).root
  raise ::Errno::ENOENT::new(video_id) unless root.attributes.get_attribute('status').value == 'ok'
  root
rescue TimeoutError => e
  raise e if retry_count >= retry_max
  retry_count += 1
  retry
end
          end

[Validate]

Generated with the Darkfish Rdoc Generator 2.