Class: MyAnimeList::Anime

Inherits:
Object
  • Object
show all
Defined in:
lib/myanimelist/anime.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Anime

Returns a new instance of Anime.



4
5
6
7
# File 'lib/myanimelist/anime.rb', line 4

def initialize(options={})
  @myanimelist_username = options[:username]
  @myanimelist_password = options[:password]
end

Instance Method Details

#get_search(name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/myanimelist/anime.rb', line 13

def get_search(name)
  response = RestClient::Request.new(
    method: :get,
    url: "https://myanimelist.net/api/anime/search.xml?q=#{CGI::escape name}",
    user: @myanimelist_username,
    password: @myanimelist_password,
    content_type: :xml ).execute

  parse_xml response
end

#parse_xml(response) ⇒ Object



24
25
26
# File 'lib/myanimelist/anime.rb', line 24

def parse_xml(response)
  serialize Hash.from_xml response
end

#search(name) ⇒ Object



9
10
11
# File 'lib/myanimelist/anime.rb', line 9

def search(name)
  get_search(name)
end

#serialize(data) ⇒ Object



28
29
30
31
# File 'lib/myanimelist/anime.rb', line 28

def serialize(data)
  result = MyAnimeList::Serializer.new data, 'anime'
  result.fetch
end