33
app/src/main/java/org/mian/gitnex/clients/IssuesService.java
Normal file
33
app/src/main/java/org/mian/gitnex/clients/IssuesService.java
Normal file
@@ -0,0 +1,33 @@
|
||||
package org.mian.gitnex.clients;
|
||||
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class IssuesService {
|
||||
|
||||
public static <S> S createService(Class<S> serviceClass, String instanceURL) {
|
||||
|
||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
|
||||
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
|
||||
|
||||
httpClient.addInterceptor(logging);
|
||||
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl(instanceURL)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
//.client(httpClient.build())
|
||||
.build();
|
||||
|
||||
return retrofit.create(serviceClass);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package org.mian.gitnex.clients;
|
||||
|
||||
import org.mian.gitnex.interfaces.ApiInterface;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
import retrofit2.converter.scalars.ScalarsConverterFactory;
|
||||
|
||||
/**
|
||||
* Author M M Arif
|
||||
*/
|
||||
|
||||
public class RetrofitClient {
|
||||
|
||||
private Retrofit retrofit;
|
||||
|
||||
private RetrofitClient(String instanceUrl) {
|
||||
|
||||
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
|
||||
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
|
||||
OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
|
||||
|
||||
httpClient.addInterceptor(logging);
|
||||
|
||||
retrofit = new Retrofit.Builder()
|
||||
.baseUrl(instanceUrl)
|
||||
.addConverterFactory(ScalarsConverterFactory.create())
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
//.client(httpClient.build())
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public static synchronized RetrofitClient getInstance(String instanceUrl) {
|
||||
return new RetrofitClient(instanceUrl);
|
||||
}
|
||||
|
||||
public ApiInterface getApiInterface() {
|
||||
return retrofit.create(ApiInterface.class);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user