CultureQuestORG/SDP2023

View on GitHub
app/src/main/java/ch/epfl/culturequest/backend/notifications_api/ApiClient.java

Summary

Maintainability
A
0 mins
Test Coverage
A
92%
package ch.epfl.culturequest.backend.notifications_api;

import static ch.epfl.culturequest.backend.notifications_api.ApiInterface.BASE_URL;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Class that provides the Retrofit Rest client to send a POST request to the Firebase Cloud
 * Messaging API that will then send the notification to the user.
 */
public class ApiClient {
    public static ApiInterface getApiService() {
        return new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .client(provideClient())
                .addConverterFactory(GsonConverterFactory.create())
                .build()
                .create(ApiInterface.class);
    }

    private static OkHttpClient provideClient() {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        return new OkHttpClient.Builder().addInterceptor(interceptor).addInterceptor(chain -> {
            Request request = chain.request();
            return chain.proceed(request);
        }).build();
    }
}