lib/mangadex/internal/context.rb in mangadex-5.4.9 vs lib/mangadex/internal/context.rb in mangadex-5.4.11

- old
+ new

@@ -16,22 +16,22 @@ @version ||= Mangadex::Api::VersionChecker.check_mangadex_version end sig { returns(T.nilable(Mangadex::Api::User)) } def user - @ignore_user ? nil : @user&.with_valid_session + @ignore_user ? nil : @user rescue Mangadex::Errors::UnauthorizedError warn("A user is present but not authenticated!") nil end sig { returns(T::Array[Mangadex::Tag]) } def tags @tags ||= Mangadex::Tag.list.data end - sig { params(user: T.nilable(T.any(Hash, Mangadex::Api::User, Mangadex::User)), block: T.proc.returns(T.untyped)).returns(T.untyped) } + sig { params(user: T.nilable(T.untyped), block: T.proc.returns(T.untyped)).returns(T.untyped) } def with_user(user, &block) temp_set_value("user", user) do yield end end @@ -62,15 +62,16 @@ @user = Mangadex::Api::User.new( mangadex_user_id: user[:mangadex_user_id], session: user[:session], refresh: user[:refresh], ) - elsif user_object?(user) + elsif Mangadex::Internal::Context.user_object?(user) @user = Mangadex::Api::User.new( mangadex_user_id: user.mangadex_user_id.to_s, session: user.session, refresh: user.refresh, + session_valid_until: user.session_valid_until, data: user, ) elsif user.nil? @user = nil else @@ -111,20 +112,20 @@ else !!@force_raw_requests end end - private - - def user_object?(user) + def self.user_object?(user) return false if user.nil? - missing_methods = [:session, :refresh, :mangadex_user_id] - user.methods + missing_methods = [:session, :refresh, :mangadex_user_id, :save] - user.methods return true if missing_methods.empty? warn("Potential user object #{user} is missing #{missing_methods}") false end + + private def temp_set_value(name, value, &block) setter_method_name = "#{name}=" current_value = send(name)