refactor iqdb endpoints

This commit is contained in:
r888888888
2018-06-23 10:32:39 -07:00
parent 27baa08e59
commit 3ba5c6fb51
11 changed files with 93 additions and 53 deletions

18
app/logical/iqdb_proxy.rb Normal file
View File

@@ -0,0 +1,18 @@
class IqdbProxy
def self.query(url)
raise NotImplementedError unless Danbooru.config.iqdbs_server.present?
url = URI.parse(Danbooru.config.iqdbs_server)
url.path = "/similar"
url.query = {url: url}.to_query
json = HTTParty.get(url.to_s, Danbooru.config.httparty_options).parsed_response
decorate_posts(json)
end
def self.decorate_posts(json)
json.map do |x|
x["post"] = Post.find(x["id"])
x
end
end
end