voteOnPost :: MonadIO m => Options -> Voting -> Post -> m (EitherR ())
voteOnPost opts voting Post{..} = do
  let PostID pid = postID
      R subr = subreddit
  case optCredentials opts of
    Nothing -> do
      logFmt Warn
        "Cannot vote on post #{} (\"{}\" in /r/{}) due to lack of credentials"
        (pid, title, subr)
      return $ Left $ APIError CredentialsError
    _ -> do
      logFmt Info "Voting on post #{} (\"{}\" in /r/{}) [{}] -> [{}]"
        (pid, title, subr, score, newScore)
      result <- runReddit opts $ doVote postID
      case result of
        Left err ->
          logFmt Warn "Failed to vote on post #{}: {}" (pid, tshow err)
        Right _ -> logFmt Debug "Successfully voted on post #{} in /r/{}"
                                (pid, subr)
      return result
  where
  newScore = case voting of Upvote -> score + 1
                            Downvote -> score - 1
  doVote = case voting of Upvote -> R.upvotePost
                          Downvote -> R.downvotePost
voteOnPost :: MonadIO m => Options -> Voting -> Post -> m (EitherR ())
voteOnPost opts voting Post{..} = do
  let PostID pid = postID
      R subr = subreddit
  case optCredentials opts of
    Nothing -> do
      logFmt Warn
        "Cannot vote on post #{} (\"{}\" in /r/{}) due to lack of credentials"
        (pid, title, subr)
      return $ Left $ APIError CredentialsError
    _ -> do
      logFmt Info "Voting on post #{} (\"{}\" in /r/{}) [{}] -> [{}]"
        (pid, title, subr, score, newScore)
      result <- runReddit opts $ doVote postID
      case result of
        Left err ->
          logFmt Warn "Failed to vote on post #{}: {}" (pid, tshow err)
        Right _ -> logFmt Debug "Successfully voted on post #{} in /r/{}"
                                (pid, subr)
      return result
  where
  newScore = case voting of Upvote -> score + 1
                            Downvote -> score - 1
  doVote = case voting of Upvote -> R.upvotePost
                          Downvote -> R.downvotePost
voteOnPost opts voting Post{..} = do
  let PostID pid = postID
      R subr = subreddit
  case optCredentials opts of
    Nothing -> do
      logFmt Warn
        "Cannot vote on post #{} (\"{}\" in /r/{}) due to lack of credentials"
        (pid, title, subr)
      return $ Left $ APIError CredentialsError
    _ -> do
      logFmt Info "Voting on post #{} (\"{}\" in /r/{}) [{}] -> [{}]"
        (pid, title, subr, score, newScore)
      result <- runReddit opts $ doVote postID
      case result of
        Left err ->
          logFmt Warn "Failed to vote on post #{}: {}" (pid, tshow err)
        Right _ -> logFmt Debug "Successfully voted on post #{} in /r/{}"
                                (pid, subr)
      return result
  where
  newScore = case voting of Upvote -> score + 1
                            Downvote -> score - 1
  doVote = case voting of Upvote -> R.upvotePost
                          Downvote -> R.downvotePost