This commit is contained in:
r888888888
2017-11-10 14:06:56 -08:00
parent 893563cf9a
commit 710a5f1abe
2 changed files with 32 additions and 1 deletions

View File

@@ -0,0 +1,31 @@
class PostViewCountService
def self.enabled?
Danbooru.config.reportbooru_server.present?
end
def initialize
if !MissedSearchService.enabled?
raise NotImplementedError.new("the Reportbooru service isn't configured. Missed searches are not available.")
end
end
def fetch_count(post_id)
url = URI.parse("#{Danbooru.config.reportbooru_server}/post_views/#{post_id}?date=#{date}")
response = HTTParty.get(url, Danbooru.config.httparty_options.reverse_merge(timeout: 6))
if response.success?
return JSON.parse(response.body)
else
return nil
end
end
def fetch_rank(date = Date.today)
url = URI.parse("#{Danbooru.config.reportbooru_server}/post_views/rank?date=#{date}")
response = HTTParty.get(url, Danbooru.config.httparty_options.reverse_merge(timeout: 6))
if response.success?
return JSON.parse(response.body)
else
return nil
end
end
end