class NicoQuery::ObjectMapper::GetThumbInfo

Public Class Methods

new(xml) click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 8
def initialize(xml)
  @xml = xml
  @parser = Nori.new
  @parsed_xml = @parser.parse xml

  @hash = @parsed_xml['nicovideo_thumb_response']['thumb']
  if !exist?
    @hash = @parser.parse null_xml
  end
end

Public Instance Methods

comment_num() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 98
def comment_num
  return nil if @hash == nil
  @hash['comment_num'].to_i
end
community?() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 27
def community?
  if @parsed_xml['nicovideo_thumb_response']["error"].presence
    @parsed_xml['nicovideo_thumb_response']["error"].presence["code"].presence == "COMMUNITY"
  else
    false
  end
end
deleted?() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 19
def deleted?
  if @parsed_xml['nicovideo_thumb_response']["error"].presence
    @parsed_xml['nicovideo_thumb_response']["error"].presence["code"].presence == "DELETED"
  else
    false
  end
end
description() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 53
def description
  return nil if @hash.nil? || @hash['description'].nil?
  @_description ||= Description.new @hash['description']
end
embeddable() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 128
def embeddable
  return nil if @hash == nil
  @hash['embeddable'] == 1
end
exist?() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 35
def exist?
  if @parsed_xml['nicovideo_thumb_response']["error"].presence
    @parsed_xml['nicovideo_thumb_response']["error"].presence["code"].presence != "NOT_FOUND"
  else
    true
  end
end
first_retrieve() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 63
def first_retrieve
  return nil if @hash == nil
  @hash['first_retrieve'].to_time
end
last_res_body() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 108
def last_res_body
  return nil if @hash == nil
  @hash['last_res_body']
end
length() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 72
def length
  return nil if @hash == nil
  string = @hash['length'].split(':')
  string[0].to_i * 60 + string[1].to_i
end
movie_type() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 78
def movie_type
  return nil if @hash == nil
  @hash['movie_type']
end
mylist_counter() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 103
def mylist_counter
  return nil if @hash == nil
  @hash['mylist_counter'].to_i
end
no_live_play() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 133
def no_live_play
  return nil if @hash == nil
  @hash['no_live_play'] == 1
end
publish_date() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 68
def publish_date # alias
  first_retrieve
end
size_high() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 83
def size_high
  return nil if @hash == nil
  @hash['size_high'].to_i
end
size_low() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 88
def size_low
  return nil if @hash == nil
  @hash['size_low'].to_i
end
tags() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 138
def tags
  return nil if @hash.nil? || @hash['tags'].nil?
  xml = @xml.scan(/\<tags domain=\"jp\">\n.+\<\/tags\>/m)[0]
  parsed = Nokogiri::XML xml
  parsed.xpath("//tag").map do |tag_object|
    generate_tag_hash_by tag_object
  end
end
thumb_type() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 123
def thumb_type
  return nil if @hash == nil
  @hash['thumb_type']
end
thumbnail_url() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 58
def thumbnail_url
  return nil if @hash == nil
  @hash['thumbnail_url']
end
title() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 48
def title
  return nil if @hash == nil
  @hash['title']
end
url() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 113
def url
  return nil if @hash == nil
  @hash['watch_url']
end
user_id() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 147
def user_id
  return nil if @hash == nil
  @hash['user_id'].to_i
end
video_id() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 43
def video_id
  return nil if @hash == nil
  @hash['video_id']
end
view_counter() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 93
def view_counter
  return nil if @hash.nil? || @hash['view_counter'].nil?
  @hash['view_counter'].to_i
end
watch_url() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 118
def watch_url
  return nil if @hash == nil
  @hash['watch_url']
end

Private Instance Methods

generate_tag_hash_by(nokogiri_xml) click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 153
def generate_tag_hash_by(nokogiri_xml)
  text = nokogiri_xml.text

  lock = if nokogiri_xml.attributes['lock'].present?
    nokogiri_xml.attributes['lock'].text.to_i == 1
  else
    false
  end

  { text: text, lock: lock }
end
null_xml() click to toggle source
# File lib/nicoquery/object_mapper/getthumbinfo.rb, line 165
      def null_xml
        <<-EOS
          <video_id></video_id>
          <title></title>
          <description></description>
          <thumbnail_url></thumbnail_url>
          <first_retrieve></first_retrieve>
          <length></length>
          <movie_type></movie_type>
          <size_high></size_high>
          <size_low></size_low>
          <view_counter></view_counter>
          <comment_num></comment_num>
          <mylist_counter></mylist_counter>
          <last_res_body></last_res_body>
          <watch_url></watch_url>
          <thumb_type></thumb_type>
          <embeddable></embeddable>
          <no_live_play></no_live_play>
          <tags domain="jp">
            <tag></tag>
            <tag></tag>
            <tag></tag>
            <tag></tag>
            <tag></tag>
            <tag></tag>
            <tag></tag>
            <tag></tag>
            <tag></tag>
            <tag></tag>
          </tags>
          <user_id></user_id>
        EOS
      end