add support for nico seiga manga (fixes #4060)

This commit is contained in:
Albert Yi
2019-02-25 14:44:45 -08:00
parent 78322b38f4
commit 90ce42a537
7 changed files with 201 additions and 34 deletions

View File

@@ -0,0 +1,58 @@
class NicoSeigaMangaApiClient
extend Memoist
BASE_URL = "http://seiga.nicovideo.jp/api"
attr_reader :theme_id
def initialize(theme_id)
@theme_id = theme_id
end
def user_id
theme_info_xml["response"]["theme"]["user_id"].to_i
end
def title
theme_info_xml["response"]["theme"]["title"]
end
def desc
theme_info_xml["response"]["theme"]["description"]
end
def moniker
artist_xml["response"]["user"]["nickname"]
end
def image_ids
theme_data_xml["response"]["image_list"]["image"].map {|x| x["id"]}
end
def tags
theme_info_xml["response"]["theme"]["tag_list"]["tag"].map {|x| x["name"]}
end
def theme_data_xml
uri = "#{BASE_URL}/theme/data?theme_id=#{theme_id}"
body = NicoSeigaApiClient.agent.get(uri).body
Hash.from_xml(body)
end
memoize :theme_data_xml
def theme_info_xml
uri = "#{BASE_URL}/theme/info?id=#{theme_id}"
body = NicoSeigaApiClient.agent.get(uri).body
Hash.from_xml(body)
end
memoize :theme_info_xml
def artist_xml
uri = "#{BASE_URL}/user/info?id=#{user_id}"
body, code = HttpartyCache.get(uri)
if code == 200
Hash.from_xml(body)
else
raise "nico seiga api call failed (code=#{code}, body=#{body})"
end
end
memoize :artist_xml
end