add support for nico seiga manga (fixes #4060)
This commit is contained in:
58
app/logical/nico_seiga_manga_api_client.rb
Normal file
58
app/logical/nico_seiga_manga_api_client.rb
Normal 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
|
||||
Reference in New Issue
Block a user