voteForPoll
Submit the votes of the user for a poll.
This API allows any member to vote for his or her favorite(s) answer(s). A vote can only apply to a poll that is in published state. It is not possible to vote on a draft or an ended poll. If the poll allows it (see Poll.modifyVote), it is possible to change the votes by calling this method again. If the poll doesn't allow to modify votes, this method will return a failure in case of multiple usage for a single poll.
Return
A RainbowResult indicating success or failure. In case of failure, the RainbowResult will contain error details.
Parameters
pollId
The unique identifier of the poll.
votes
The list of PollVote representing the vote(s) of the user.
Samples
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import com.ale.infra.manager.poll.Poll
import com.ale.infra.manager.poll.PollAnswer
import com.ale.infra.manager.poll.PollQuestion
import com.ale.infra.manager.poll.PollVote
import com.ale.infra.rest.listeners.onFailure
import com.ale.infra.rest.listeners.onSuccess
import com.ale.rainbowsdk.RainbowSdk
import kotlinx.coroutines.launch
fun main() {
//sampleStart
val votes = mutableListOf<PollVote>()
// Assuming we have a the poll previously created, we have 1 question with 2 answers
// Here we vote on first question with second answer
votes.add(PollVote(question = 0, answers = mutableListOf(1)))
// With another question, It would be added like this
// Here we vote on second question with the 2 first answers (assuming it is a multiple Choices question)
votes.add(PollVote(question = 1, answers = mutableListOf(0,1)))
viewLifecycleOwner.lifecycleScope.launch {
RainbowSdk().polls().voteForPoll(pollId, votes).onSuccess {
// Handle success
}.onFailure {
// Handle failure
}
}
//sampleEnd
}