ApiClient Retrofit Android

dependency

implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.2.1'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'

 ApiClient Class

package com.example.reBLISS.retrofit;


import com.example.reBLISS.Constant;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.util.concurrent.TimeUnit;

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

public class ApiClient {
private static Retrofit retrofit = null;


public static Retrofit getClient() {
Gson gson = new GsonBuilder()
.setLenient()
.create();

HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);

OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.addInterceptor(interceptor)
.build();
// if (retrofit == null) {
retrofit = new Retrofit.Builder()
.baseUrl(Constant.BASEURL)
.addConverterFactory(GsonConverterFactory.create(gson))
.client(client)
.build();
// }
return retrofit;
}
}


ApiInterface


package com.example.reBLISS.retrofit;

import com.example.reBLISS.modal.CheckInModal;
import com.example.reBLISS.modal.CompanyRequest;
import com.example.reBLISS.modal.CompanyResponse;
import com.example.reBLISS.modal.LoginResponse;
import com.example.reBLISS.modal.SelfieResponse;
import com.example.reBLISS.modal.SelfieResponseOut;
import com.example.reBLISS.modal.WeekOffResponcse;

import java.util.HashMap;

import okhttp3.MultipartBody;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.Multipart;
import retrofit2.http.POST;
import retrofit2.http.Part;

public interface ApiInterface {
/*
@GET("top-headlines")
Call<Modal>getpost(@Query("sources")String sources, @Query("apiKey")String apikey);

@GET("comments")
Call<List<NewsResponse> >getNews(@Query("postId")String postId );




*/
@FormUrlEncoded
@POST("login")
Call<LoginResponse> getLogin(@FieldMap HashMap<String, String> hashMap);
@Multipart
@POST("checkin")
Call<CheckInModal>checkInModal(@Part MultipartBody.Part img, @Part("location") RequestBody location,@Part("uid") long uid );
@FormUrlEncoded
@POST("checkinimagefetch")
Call<SelfieResponse> getSelfies(@FieldMap HashMap<String,String>hashMap);
@FormUrlEncoded
@POST("checkoutimagefetch")
Call<SelfieResponseOut> getSelfiesout(@FieldMap HashMap<String,String>hashMap);
@FormUrlEncoded
@POST("company")
Call<CompanyResponse> setCompany(@FieldMap HashMap<String ,String>hashMap);
@Multipart
@POST("checkout")
Call<CheckInModal>checkOutModal(@Part MultipartBody.Part img, @Part("checkoutlocation") RequestBody location,@Part("uid") long uid );
@FormUrlEncoded
@POST("weekoff")
Call<WeekOffResponcse>setWeekOff(@FieldMap HashMap<String,String>hashMap);





}


Comments

Popular posts from this blog

Spinner select validation

Open the Camera Pic The Image send to Server Base64