Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions funpaybotengine/methods/get_reviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
__all__ = ('GetReviews',)


from typing import TYPE_CHECKING, Any

from pydantic import BaseModel
from funpayparsers.types import Language
from funpayparsers.parsers import ReviewsParser
Expand All @@ -14,6 +16,10 @@
from funpaybotengine.client.session.http_methods import HTTPMethod


if TYPE_CHECKING:
from funpaybotengine.client.session.base import RawResponse


STATE_FILTERS = {
OrderStatus.COMPLETED: 'closed',
OrderStatus.PAID: 'paid',
Expand Down Expand Up @@ -51,3 +57,16 @@ def __init__(
from_review_id=from_review_id,
filter=filter,
)

async def transform_result(
self,
parsing_result: Any,
response: RawResponse[Any],
) -> ReviewsBatch:
batch = await super().transform_result(parsing_result, response)
# FunPay omits the hidden ``filter`` and ``user_id`` inputs in some responses,
# so the scraped values are unreliable. Stamp the ones actually requested to
# keep the filter (and the profile id needed for pagination) across batches.
batch.filter = self.filter
batch.user_id = self.user_id
return batch
18 changes: 18 additions & 0 deletions funpaybotengine/types/reviews.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,21 @@ class ReviewsBatch(FunPayObject, BaseModel):
If present, this value should be included in the next request to fetch
the following batch of reviews. If ``None``, there are no more reviews to load.
"""

async def next_batch(self) -> ReviewsBatch:
if not self.next_review_id:
raise ValueError('Last batch.')

if self.user_id is None:
raise ValueError('Unknown user id.')

# Imported lazily to avoid a circular import between types and methods.
from funpaybotengine.methods.get_reviews import GetReviews

return (
await GetReviews(
user_id=self.user_id,
from_review_id=self.next_review_id,
filter=self.filter or '',
).execute(self.get_bound_bot())
).response_obj