sources: replace HttpartyCache with Danbooru::Http.
This commit is contained in:
@@ -110,10 +110,10 @@ module Sources::Strategies
|
||||
def api_response
|
||||
return {} unless project_id.present?
|
||||
|
||||
resp, code = HttpartyCache.get("https://www.artstation.com/projects/#{project_id}.json")
|
||||
return {} if code != 200
|
||||
resp = Danbooru::Http.cache(1.minute).get("https://www.artstation.com/projects/#{project_id}.json")
|
||||
return {} if resp.code != 200
|
||||
|
||||
JSON.parse(resp, symbolize_names: true)
|
||||
resp.parse.with_indifferent_access
|
||||
end
|
||||
memoize :api_response
|
||||
|
||||
|
||||
@@ -101,8 +101,8 @@ module Sources
|
||||
return {}
|
||||
end
|
||||
|
||||
body, code = HttpartyCache.get("/post.json", base_uri: "https://#{site_name}", params: params)
|
||||
post = JSON.parse(body, symbolize_names: true).first
|
||||
response = Danbooru::Http.cache(1.minute).get("https://#{site_name}/post.json", params: params)
|
||||
post = response.parse.first&.with_indifferent_access
|
||||
post || {}
|
||||
end
|
||||
memoize :api_response
|
||||
|
||||
@@ -166,17 +166,13 @@ module Sources::Strategies
|
||||
return {} unless self.class.enabled?
|
||||
return {} unless blog_name.present? && post_id.present?
|
||||
|
||||
body, code = HttpartyCache.get("/#{blog_name}/posts",
|
||||
response = Danbooru::Http.cache(1.minute).get(
|
||||
"https://api.tumblr.com/v2/blog/#{blog_name}/posts",
|
||||
params: { id: post_id, api_key: Danbooru.config.tumblr_consumer_key },
|
||||
base_uri: "https://api.tumblr.com/v2/blog/"
|
||||
)
|
||||
|
||||
if code == 200
|
||||
return JSON.parse(body, symbolize_names: true)
|
||||
else
|
||||
Rails.logger.debug("TumblrApiClient call failed (code=#{code}, body=#{body}, blog_name=#{blog_name}, post_id=#{post_id})")
|
||||
return {}
|
||||
end
|
||||
return {} if response.code != 200
|
||||
response.parse.with_indifferent_access
|
||||
end
|
||||
memoize :api_response
|
||||
|
||||
|
||||
Reference in New Issue
Block a user