Class: AnimeNewsNetwork::Encyclopedia

Inherits:
Object
  • Object
show all
Defined in:
lib/animenewsnetwork/encyclopedia.rb

Defined Under Namespace

Classes: Reports

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Encyclopedia

Returns a new instance of Encyclopedia.



7
8
9
# File 'lib/animenewsnetwork/encyclopedia.rb', line 7

def initialize(args = {})
  @url = args.has_key?(:url) ? args[:url] : 'http://cdn.animenewsnetwork.com/encyclopedia'
end

Instance Method Details

#get_details(args = {}) ⇒ Object

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
41
# 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 = {}) ⇒ Object

Raises:

  • (ArgumentError)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 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