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

com.avito.plugin.internal.UrlResolver.kt Maven / Gradle / Ivy

Go to download

Collection of infrastructure libraries and gradle plugins of Avito Android project

The newest version!
package com.avito.plugin.internal

import com.avito.plugin.SignExtension
import okhttp3.HttpUrl.Companion.toHttpUrl

internal class UrlResolver(
    private val extension: SignExtension,
) {

    fun resolveServiceUrl(onFailure: (Throwable) -> Nothing): String {
        val value = extension.url
            .orElse("")
            .get()

        return validateUrl(value, onFailure)
    }
}

// used in tests
internal fun validateUrl(url: String, onFailure: (Throwable) -> Nothing): String {
    return try {
        url.toHttpUrl()
            .newBuilder()
            .addEncodedPathSegment("sign")
            .build()
            .toString()
    } catch (e: Throwable) {
        onFailure(IllegalArgumentException("Invalid signer url value: '$url'", e))
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy