Added authentication via Subsonic API

This commit is contained in:
CappielloAntonio 2021-07-24 14:47:44 +02:00
parent 8a2e2f7000
commit 27cc3b8570
3 changed files with 83 additions and 38 deletions

View file

@ -1,4 +1,53 @@
package com.cappielloantonio.play.subsonic.api.system;
import android.util.Log;
import com.cappielloantonio.play.subsonic.Subsonic;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
import java.util.List;
import java.util.Map;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class SystemClient {
private static final String TAG = "SystemClient";
private Subsonic subsonic;
private Retrofit retrofit;
private SystemService systemService;
public SystemClient(Subsonic subsonic) {
this.subsonic = subsonic;
this.retrofit = new Retrofit.Builder()
.baseUrl(subsonic.getUrl())
.addConverterFactory(GsonConverterFactory.create())
.client(getOkHttpClient())
.build();
this.systemService = retrofit.create(SystemService.class);
}
public Call<SubsonicResponse> ping(){
Log.d(TAG, "Requesting ping");
return systemService.ping(subsonic.getParams());
}
private OkHttpClient getOkHttpClient() {
return new OkHttpClient.Builder()
.addInterceptor(getHttpLoggingInterceptor())
.build();
}
private HttpLoggingInterceptor getHttpLoggingInterceptor() {
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
return loggingInterceptor;
}
}

View file

@ -2,12 +2,13 @@ package com.cappielloantonio.play.subsonic.api.system;
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
import java.util.List;
import java.util.Map;
import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.QueryMap;
public interface SystemService {
@GET("ping")
Call<List<SubsonicResponse>> ping();
Call<SubsonicResponse> ping(@QueryMap Map<String, String> params);
}