createPoll

abstract suspend fun createPoll(poll: Poll): RainbowResult<String>

Create a Poll in a Room.

This API allows an organizer to create the draft of a poll in a Room. A poll is composed of up to 20 questions, each one of them having between 2 and 20 possible answers, and a various set of settings. Once created, the poll will only be accessible by other organizers. It can be modified or deleted. It is only once the poll is published that all users can see it and have the possibility to vote

Return

A RainbowResult containing the poll id on success. In case of failure, the RainbowResult will contain error details.

Parameters

poll

The Poll to create

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 newPoll = Poll().apply {
    // Add here the id of the room you want to create you poll in
    roomId = "<room-id>"
    // Title is optional
    title = "My wonderful poll"
    // You need between 1 and 20 questions
    questions.add(PollQuestion().apply {
        text = "My first question?"
        // Each question needs between 2 and 20 possible answers
        answers.addAll(listOf(
            PollAnswer("First Answer"),
            PollAnswer("Second Answer")
        ))
    })
}

viewLifecycleOwner.lifecycleScope.launch {
    RainbowSdk().polls().createPoll(newPoll).onSuccess {
        // Handle success
    }.onFailure {
        // Handle failure
    }
} 
   //sampleEnd
}