cache api clients

This commit is contained in:
Albert Yi
2018-09-10 17:28:18 -07:00
parent e0e85a3139
commit 266c7c0d5b
11 changed files with 99 additions and 64 deletions

View File

@@ -1,9 +1,14 @@
class TumblrApiClient < Struct.new(:api_key)
include HTTParty
base_uri "https://api.tumblr.com/v2/blog/"
def posts(blog_name, post_id)
response = self.class.get("/#{blog_name}/posts", Danbooru.config.httparty_options.merge(query: { id: post_id, api_key: api_key }))
response.parsed_response.with_indifferent_access[:response]
body, code = HttpartyCache.get("/#{blog_name}/posts",
params: { id: post_id, api_key: api_key },
base_uri: "https://api.tumblr.com/v2/blog/"
)
if code == 200
return JSON.parse(body)["response"].with_indifferent_access
end
raise "TumblrApiClient call failed (code=#{code}, body=#{body}, blog_name=#{blog_name}, post_id=#{post_id})"
end
end