All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.deque.networking.usageservice.UsageServiceClient.kt Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
package com.deque.networking.usageservice

import com.deque.networking.interfaces.DashboardService
import com.deque.networking.models.ResultCallAdapterFactory
import com.squareup.moshi.Moshi
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
import retrofit2.Retrofit
import retrofit2.converter.moshi.MoshiConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory

internal class UsageServiceClient(
    private val baseUrl: String
) {
    private val usageServiceInterface: UsageServiceInterface =
        Retrofit.Builder()
            .baseUrl(baseUrl)
            .addConverterFactory(
                ScalarsConverterFactory.create()
            )
            .addConverterFactory(
                MoshiConverterFactory.create(
                    Moshi.Builder()
                        .addLast(KotlinJsonAdapterFactory())
                        .build()
                )
            )
            .addCallAdapterFactory(ResultCallAdapterFactory())
            .build()
            .create(UsageServiceInterface::class.java)

    suspend fun sendEvent(event: UsageServiceEvent): Result {
        return usageServiceInterface.sendEvent(
            UsageServiceEventV2Data(
                event = event.eventName,
                dateTime = System.currentTimeMillis(),
                distinctId = UsageService.distinctId,
                userId = DashboardService.email,
                organization = UsageService.orgId,
            )
        )
    }

    suspend fun healthCheck(): Result {
        return usageServiceInterface.healthCheck()
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy