lib/mangadex/statistic.rb in mangadex-5.8.0 vs lib/mangadex/statistic.rb in mangadex-5.9.0

- old
+ new

@@ -1,31 +1,78 @@ # typed: false module Mangadex class Statistic < MangadexObject - has_attributes \ + class Rating < MangadexObject + has_attributes \ + :average, + :bayesian, + :distribution + + def self.attributes_to_inspect + [:average, :bayesian] + end + end + + class Comments < MangadexObject + has_attributes \ + :thread_id, + :replies_count + + def self.attributes_to_inspect + [:replies_count] + end + end + + attr_accessor \ :rating, - :average, - :bayesian, - :distribution, - :follows + :follows, + :comments - sig { params(uuid: String).returns(T::Api::GenericResponse) } - def self.get(uuid) + class << self + def from_data(data) + results = if data.is_a?(Array) + data.map do |item| + from_data(item) + end + else + data.keys.map do |manga_id| + statistics = data[manga_id] + new( + rating: Mangadex::Statistic::Rating.from_data(statistics['rating'], direct: true), + comments: Mangadex::Statistic::Comments.from_data(statistics['comments'], direct: true), + follows: statistics['follows'], + ) + end + end + + return results.first if results.length == 1 + Mangadex::Api::Response::Collection.new(results) + end + end + + sig { params(uuid: String, raw: T::Boolean).returns(T::Api::GenericResponse) } + def self.get(uuid, raw: false) Mangadex::Internal::Definition.must(uuid) Mangadex::Internal::Request.get( '/statistics/manga/%{uuid}' % {uuid: uuid}, + raw: raw, ) end - sig { params(args: T::Api::Arguments).returns(T::Api::GenericResponse) } - def self.list(**args) + sig { params(raw: T::Boolean, args: T::Api::Arguments).returns(T::Api::GenericResponse) } + def self.list(raw: false, **args) Mangadex::Internal::Request.get( '/statistics/manga', Mangadex::Internal::Definition.validate(args, { manga: { accepts: [String], converts: :to_a }, - }) + }), + raw: raw, ) + end + + def self.attributes_to_inspect + [:follows, :rating, :comments] end end end