class AnimeNewsNetwork::Encyclopedia

Public Class Methods

new(args = {}) click to toggle source
# File lib/animenewsnetwork/encyclopedia.rb, line 7
def initialize(args = {})
  @url = args.has_key?(:url) ? args[:url] : 'http://cdn.animenewsnetwork.com/encyclopedia'
end

Public Instance Methods

get_details(args = {}) click to toggle source
# File lib/animenewsnetwork/encyclopedia.rb, line 29
def get_details(args = {})
  validator = DataValidator::Validator.new(
    args, {
      id:   { presence: true, numericality: { only_integer: true } },
      type: { presence: true, inclusion: { in: %w(anime manga) } },
    }
  )
  raise ArgumentError, validator.errors unless validator.valid?

  path = '/api.xml';
  query = { args[:type] => args[:id] }
  Nokogiri::XML(get(path, query))
end
get_reports(args = {}) click to toggle source
# File lib/animenewsnetwork/encyclopedia.rb, line 11
def get_reports(args = {})
  validator = DataValidator::Validator.new(
    args, {
      id:     { presence: true, numericality: { only_integer: true } },
      type:   { allow_nil: true, inclusion: { in: %w(anime manga) } },
      name:   { allow_nil: true },
      search: { allow_nil: true },
      nskip:  { allow_nil: true, numericality: { only_integer: true } },
      nlist:  { allow_nil: true, format: { with: /^(\d+|all)$/ } },
    }
  )
  raise ArgumentError, validator.errors unless validator.valid?

  path = '/reports.xml';
  query = args
  Nokogiri::XML(get(path, query))
end

Private Instance Methods

get(path = '', query = {}) click to toggle source
# File lib/animenewsnetwork/encyclopedia.rb, line 45
def get(path = '', query = {})
  uri = Addressable::URI.parse(@url)
  uri.path += path
  uri.query_values = query
  return open(uri)
end