mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-03 02:27:31 +01:00
Add optional logging to SubsonicAPI.
Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
24d68fcf3c
commit
20d95ce19d
@ -30,11 +30,12 @@ ext.androidSupport = [
|
||||
]
|
||||
|
||||
ext.other = [
|
||||
kotlinStdlib : "org.jetbrains.kotlin:kotlin-stdlib-common:$versions.kotlin",
|
||||
kotlinStdlib : "org.jetbrains.kotlin:kotlin-stdlib-common:$versions.kotlin",
|
||||
retrofit : "com.squareup.retrofit2:retrofit:$versions.retrofit",
|
||||
gsonConverter : "com.squareup.retrofit2:converter-gson:$versions.retrofit",
|
||||
jacksonConverter : "com.squareup.retrofit2:converter-jackson:$versions.retrofit",
|
||||
jacksonKotlin : "com.fasterxml.jackson.module:jackson-module-kotlin:$versions.jackson",
|
||||
okhttpLogging : "com.squareup.okhttp3:logging-interceptor:$versions.okhttp",
|
||||
]
|
||||
|
||||
ext.testing = [
|
||||
|
@ -12,6 +12,7 @@ dependencies {
|
||||
compile other.retrofit
|
||||
compile other.jacksonConverter
|
||||
compile other.jacksonKotlin
|
||||
compile other.okhttpLogging
|
||||
|
||||
testCompile testing.junit
|
||||
testCompile testing.kotlinJunit
|
||||
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature
|
||||
import com.fasterxml.jackson.databind.ObjectMapper
|
||||
import com.fasterxml.jackson.module.kotlin.KotlinModule
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.logging.HttpLoggingInterceptor
|
||||
import retrofit2.Retrofit
|
||||
import retrofit2.converter.jackson.JacksonConverterFactory
|
||||
import java.math.BigInteger
|
||||
@ -17,7 +18,8 @@ class SubsonicAPI(baseUrl: String,
|
||||
username: String,
|
||||
private val password: String,
|
||||
clientProtocolVersion: SubsonicAPIVersions,
|
||||
clientID: String) {
|
||||
clientID: String,
|
||||
debug: Boolean = false) {
|
||||
private val okHttpClient = OkHttpClient.Builder()
|
||||
.addInterceptor { chain ->
|
||||
// Adds default request params
|
||||
@ -30,6 +32,13 @@ class SubsonicAPI(baseUrl: String,
|
||||
.addQueryParameter("f", "json")
|
||||
.build()
|
||||
chain.proceed(originalRequest.newBuilder().url(newUrl).build())
|
||||
}
|
||||
.apply {
|
||||
if (debug) {
|
||||
val loggingInterceptor = HttpLoggingInterceptor()
|
||||
loggingInterceptor.level = HttpLoggingInterceptor.Level.BASIC
|
||||
this.addInterceptor(loggingInterceptor)
|
||||
}
|
||||
}.build()
|
||||
|
||||
private val jacksonMapper = ObjectMapper()
|
||||
@ -49,7 +58,7 @@ class SubsonicAPI(baseUrl: String,
|
||||
*
|
||||
* @return initialized API instance
|
||||
*/
|
||||
fun getApi() = subsonicAPI
|
||||
fun getApi(): SubsonicAPIDefinition = subsonicAPI
|
||||
|
||||
private fun passwordHex() = "enc:${password.toHexBytes()}"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user