Module: ANN_Wrapper
Overview
wrapper class for ANN API
Constant Summary collapse
- ANN_URL =
ANN API anime url
"http://cdn.animenewsnetwork.com/encyclopedia"
- ANN_API_URL =
"#{ANN_URL}/api.xml"
- ANN_REPORTS_URL =
"#{ANN_URL}/reports.xml"
Instance Method Summary collapse
-
#fetch_anime(id, api_url = ANN_API_URL) ⇒ Object
fetch anime and convert to ANN_Anime.
-
#fetch_titles(type = "anime", nskip = 0, nlist = 50, name = "", api_url = ANN_REPORTS_URL) ⇒ Object
fetch list of titles via reports.
Instance Method Details
#fetch_anime(id, api_url = ANN_API_URL) ⇒ Object
fetch anime and convert to ANN_Anime
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/ann_wrapper.rb', line 19 def fetch_anime(id, api_url=ANN_API_URL) # append id to API url and send request url = "#{api_url}?anime=#{id.to_s}" ann = fetch(url) return ann if ann.is_a?(ANN_Error) anime = ann.at_xpath('//ann/anime') # initialize new ann_anime or error with ann object anime.nil? ? ANN_Error.new(get_xml_error(ann)) : ANN_Anime.new(anime) end |
#fetch_titles(type = "anime", nskip = 0, nlist = 50, name = "", api_url = ANN_REPORTS_URL) ⇒ Object
fetch list of titles via reports
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ann_wrapper.rb', line 34 def fetch_titles(type="anime", nskip=0, nlist=50, name="", api_url=ANN_REPORTS_URL) url = "#{api_url}?id=155&type=#{type}&nskip=#{nskip}&nlist=#{nlist}" report = fetch(url) return report if report.is_a?(ANN_Error) reports = report.xpath('//report/item') return ANN_Error.new(get_xml_error(report)) if reports.nil? reports.map { |item| ANN_Report.new(item) } end |