diff --git a/Sources/SwiftDevRant/Models/DownvoteReason.swift b/Sources/SwiftDevRant/Models/DownvoteReason.swift new file mode 100644 index 0000000..b43aa5a --- /dev/null +++ b/Sources/SwiftDevRant/Models/DownvoteReason.swift @@ -0,0 +1,6 @@ +/// Represents the reason for downvoting. +public enum DownvoteReason: Int, Hashable { + case notForMe = 0 + case repost = 1 + case offensiveOrSpam = 2 +} diff --git a/Sources/SwiftDevRant/SwiftDevRant.swift b/Sources/SwiftDevRant/SwiftDevRant.swift index 80d8fba..4690fff 100644 --- a/Sources/SwiftDevRant/SwiftDevRant.swift +++ b/Sources/SwiftDevRant/SwiftDevRant.swift @@ -261,11 +261,15 @@ public extension SwiftDevRant { /// - token: The token from the `logIn` call response. /// - rantId: The id of the rant. /// - vote: The vote for this rant. - public func voteOnRant(token: AuthToken, rantId: Int, vote: VoteState) async throws -> Rant { //TODO: add downvote reason + public func voteOnRant(token: AuthToken, rantId: Int, vote: VoteState, downvoteReason: DownvoteReason = .notForMe) async throws -> Rant { var parameters: [String: String] = [:] parameters["vote"] = String(vote.rawValue) + if vote == .downvoted { + parameters["reason"] = String(downvoteReason.rawValue) + } + let config = makeConfig(.post, path: "devrant/rants/\(rantId)/vote", urlParameters: parameters, token: token) struct Response: Codable { @@ -284,11 +288,15 @@ public extension SwiftDevRant { /// - token: The token from the `logIn` call response. /// - commentId: The id of the comment. /// - vote: The vote for this comment. - public func voteOnComment(token: AuthToken, commentId: Int, vote: VoteState) async throws -> Comment { + public func voteOnComment(token: AuthToken, commentId: Int, vote: VoteState, downvoteReason: DownvoteReason = .notForMe) async throws -> Comment { var parameters: [String: String] = [:] parameters["vote"] = String(vote.rawValue) + if vote == .downvoted { + parameters["reason"] = String(downvoteReason.rawValue) + } + let config = makeConfig(.post, path: "comments/\(commentId)/vote", urlParameters: parameters, token: token) struct Response: Decodable {