sources: replace HttpartyCache with Danbooru::Http.

This commit is contained in:
evazion
2019-12-15 15:40:30 -06:00
parent 0adec60259
commit 41378bc8e3
7 changed files with 35 additions and 56 deletions

View File

@@ -169,19 +169,19 @@ class PixivApiClient
}
url = "https://public-api.secure.pixiv.net/v#{API_VERSION}/works/#{illust_id.to_i}.json"
body, code = HttpartyCache.get(url, headers: headers, params: params)
json = JSON.parse(body)
response = Danbooru::Http.cache(1.minute).headers(headers).get(url, params: params)
json = response.parse
if code == 200
if response.code == 200
WorkResponse.new(json["response"][0])
elsif json["status"] == "failure" && json.dig("errors", "system", "message") =~ /対象のイラストは見つかりませんでした。/
raise BadIDError.new("Pixiv ##{illust_id} not found: work was deleted, made private, or ID is invalid.")
else
raise Error.new("Pixiv API call failed (status=#{code} body=#{body})")
raise Error.new("Pixiv API call failed (status=#{response.code} body=#{response.body.to_s})")
end
rescue JSON::ParserError
raise Error.new("Pixiv API call failed (status=#{code} body=#{body})")
raise Error.new("Pixiv API call failed (status=#{response.code} body=#{response.body.to_s})")
end
def fanbox(fanbox_id)