diff --git a/Data/Sources/Data/PostRepository+Voting.swift b/Data/Sources/Data/PostRepository+Voting.swift index e6dab419..c9c965dc 100644 --- a/Data/Sources/Data/PostRepository+Voting.swift +++ b/Data/Sources/Data/PostRepository+Voting.swift @@ -37,7 +37,23 @@ extension PostRepository { if containsLoginForm { throw HackersKitError.unauthenticated } } - // Unvote functionality removed + public func unvote(post: Post) async throws { + guard let voteLinks = post.voteLinks else { throw HackersKitError.unauthenticated } + guard let unvoteURL = voteLinks.unvote else { + throw HackersKitError.scraperError + } + + let fullURLString = unvoteURL.absoluteString.hasPrefix("http") + ? unvoteURL.absoluteString + : urlBase + "/" + unvoteURL.absoluteString + guard let realURL = URL(string: fullURLString) else { throw HackersKitError.scraperError } + + let response = try await networkManager.get(url: realURL) + let containsLoginForm = + response.contains("