Skip to content
This repository has been archived by the owner on Sep 22, 2023. It is now read-only.

Add review endpoint #1

Merged
merged 10 commits into from
Jul 14, 2022
Merged

Add review endpoint #1

merged 10 commits into from
Jul 14, 2022

Conversation

bytedream
Copy link
Member

@bytedream bytedream commented Jul 9, 2022

This PR adds the functionality to review a series and get review metadata from it like ratings.

In the following, UserReview / userReview and OwnerReview / ownerReview are getting used. These are structs with the same fields but different methods. A review which was written by the logged-in account cannot be rated as helpful, and is therefore represented as a *OwnerReview which has only function to manipulate the review. A review written by another person on the other hand, has only functions to interact with it (rating as helpful, ...) and is represented as *UserReview.

Rating

Get the rating of a series.

rating, err := series.Rating()

Returns *crunchyroll.Rating.

Reviews

Get reviews of a series.

// Sort the returning reviews by the newest first and filter them by reviews which has only one star
options := crunchyroll.ReviewOptions {
    Sort: ReviewSortNewest,
    Filter: OneStar,
}

// Returns 5 reviews
userReviews, err := series.Reviews(options, 1, 5)

Returns crunchyroll.BulkResult[*crunchyroll.UserReview].

CreateReview

Create a review. Title must be 10 characters long or longer and content 100 charaters long or longer.

title := "TestTestTest"
content := "TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest"

// Create a review with the given title and content and mark it as spoiler.
ownerReview, err := series.CreateReview(title, content, true)

Returns *crunchyroll.OwnerReview.

GetOwnerReview

Get the review from the logged-in account. Returns an error if none was written yet.

ownerReview, err := series.GetOwnerReview()

HasOwnerReview

Returns if the logged-in account has written a review for the series.

hasOwnerReview := series.HasOwnerReview()

Rate

Rate a series.

err := series.Rate(FiveStars)

Edit

Edit your review.

title := "TestTestTest1"
content := "TestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTestTest1"

// Edit the review with the given title and content and not mark it as spoiler.
err := ownerReview.Edit(title, content, false)

Delete

Delete your review.

err := ownerReview.Delete()

RateHelpful

Rate a review as helpul. A review can only be rated once as helpful (or not helpful) and this cannot be undone, so be careful. Check UserReview.Rated() if the review is already rated.

err := userReview.RateHelpful()

RateNotHelpful

Rate a review as not helpul. A review can only be rated once as not helpful (or helpful) and this cannot be undone, so be careful. Check UserReview.Rated() if the review is already rated.

err := userReview.RateNotHelpful()

Rated

Check if a review is already rated.

rated := userReview.Rated()

Report

Report a review. Check for Review.Ratings.Reported if the review is reported. If this is the case, the function will fail.

err := review.Report()

RemoveReport

Remove a report from a review. Check for Review.Ratings.Reported if the review is reported. If this is not the case, the function will fail.

err := review.RemoveReport()

@bytedream bytedream marked this pull request as ready for review July 14, 2022 10:24
@bytedream bytedream merged commit c1fa0a3 into next/v3 Jul 14, 2022
@bytedream bytedream deleted the v3/feature/rating branch July 15, 2022 10:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant