docs: add remaining docs for classes in app/logical.

This commit is contained in:
evazion
2021-06-23 20:32:59 -05:00
parent c6855261fe
commit 00ca7526bb
47 changed files with 705 additions and 25 deletions

View File

@@ -1,3 +1,7 @@
# An API client for the Reportbooru service. Reportbooru tracks post view
# counts, post search counts, and missed search counts.
#
# @see https://github.com/r888888888/reportbooru
class ReportbooruService
attr_reader :http, :reportbooru_server
@@ -6,10 +10,14 @@ class ReportbooruService
@http = http.timeout(1)
end
# @return [Boolean] true if Reportbooru is configured
def enabled?
reportbooru_server.present?
end
# Get the list of today's top missed searches.
# @param expires_in [Integer] the length of time to cache the results
# @return [Hash<String, Integer>] a map from searches to search counts
def missed_search_rankings(expires_in: 1.minute)
return [] unless enabled?
@@ -20,10 +28,18 @@ class ReportbooruService
body.lines.map(&:split).map { [_1, _2.to_i] }
end
# Get the list of the day's top searches.
# @param date [Date] the date to check (YYYY-MM-DD)
# @param expires_in [Integer] the length of time to cache the results
# @return [Array<Array<(String, Float)>>] a map from searches to search counts
def post_search_rankings(date, expires_in: 1.minute)
request("#{reportbooru_server}/post_searches/rank?date=#{date}", expires_in)
end
# Get the list of the day's most viewed posts.
# @param date [Date] the date to check (YYYY-MM-DD)
# @param expires_in [Integer] the length of time to cache the results
# @return [Array<Array<(String, Float)>>] a map from post ids to view counts
def post_view_rankings(date, expires_in: 1.minute)
request("#{reportbooru_server}/post_views/rank?date=#{date}", expires_in)
end
@@ -40,6 +56,10 @@ class ReportbooruService
ranking.take(limit).map { |x| Post.find(x[0]) }
end
# Send a request to Reportbooru
# @param url [String] the full Reportbooru URL
# @param expires_in [Integer] the length of time to cache the results
# @return [Object] the parsed JSON response
def request(url, expires_in)
return [] unless enabled?