RetrofitUtils工具类

package com.example.com.utils;

import com.example.com.api.ApiService;
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;

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

/**
 * Created by linmeihui on 2018/5/16.
 */

public class RetrofitUtils {

    private static RetrofitUtils instance;
    private final String url="";
    private final Retrofit retrofit;

    public static RetrofitUtils getInstance(){

        if (instance==null){
            synchronized (RetrofitUtils.class){
                if(null==instance){
                    instance=new RetrofitUtils();
                }
            }
        }
        return instance;
    }


    private RetrofitUtils(){

        OkHttpClient okHttpClient=new OkHttpClient();

        retrofit = new Retrofit.Builder()
                .client(okHttpClient)
                .baseUrl(url)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .build();

    }

    public ApiService getService(){
        return retrofit.create(ApiService.class);
    }


}
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页