Skip to content

Instantly share code, notes, and snippets.

Created October 23, 2020 06:26
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
package com.sergiocasero.backend.push
import com.sergiocasero.model.PushTopic
import kotlinx.coroutines.Deferred
import kotlinx.coroutines.runBlocking
import okhttp3.ResponseBody
import retrofit2.http.Body
import retrofit2.http.POST
import java.util.*
interface FcmApiService {
companion object {
const val ENDPOINT = ""
fun sendPush(@Body push: Push): Deferred<ResponseBody>
fun sendPush(topic: PushTopic, title: String, body: String) {
val push = Push(Message(topic = topic.label, notification = Notification(body = body, title = title)))
val googleCredential = GoogleCredential
val service = createService<FcmApiService>(FcmApiService.ENDPOINT, "Bearer " + googleCredential.accessToken)
runBlocking {
val response = service.sendPush(push).await()
data class Push(val message: Message)
data class Message(val topic: String, val notification: Notification)
data class Notification(val body: String, val title: String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment