Sha256: 21dbc1c790c665fc5fe3fc56eb6024f012a32f2734b6bdbb17e4c709fe2579ae

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

require 'active_support/core_ext'
require 'nicoapi/base'


module NicoAPI
  class TagSearch
    include NicoAPI::Base

    def set(tag: tag, sort: sort, order: order)
      @dynamic_segment = tag
      @params_array = params_array(sort, order)
    end

    private
    def host
      'www.nicovideo.jp'
    end

    def static_segment
      'tag'
    end

    def params_array(sort, order)
      array = []

      array.push sort_param(sort)
      array.push order_param(order)
      array.push "rss=2.0"

      array
    end

    def format
      "rss=2.0"
    end

    def sort_param(sort)
      sort_string = case sort
      when 'commented_at' then nil
      when 'view_count'   then 'v'
      when 'comment_num'  then 'r'
      when 'mylist_count' then 'm'
      when 'published_at' then 'f'
      when 'length'       then 'l'
      end

      sort_string.present? ? "sort=#{sort_string}" : ''
    end

    def order_param(order)
      order_string = case order
      when 'asc'  then 'order=a'
      else nil
      end

      order_string.present? ? 'order=a' : ''
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nicoapi-0.0.1 lib/nicoapi/tag_search.rb