content: package com.lance.freebook.Data.Retrofit;
  
  import com.lance.freebook.Constant.Constant;
  
  import okhttp3.OkHttpClient;
  import retrofit2.Retrofit;
  import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
  import retrofit2.converter.gson.GsonConverterFactory;
  
  /**
   *封装一个retrofit集成0kHttp3的抽象基类
   */
  public abstract class RetrofitUtils {
  
      private static Retrofit mRetrofit;
      private static OkHttpClient mOkHttpClient;
      /**
       * 获取Retrofit对象
       *
       * @return
       */
      protected static Retrofit getRetrofit() {
  
          if (null == mRetrofit) {
  
              if (null == mOkHttpClient) {
                  mOkHttpClient = OkHttp3Utils.getOkHttpClient();
              }
  
              //Retrofit2后使用build设计模式
              mRetrofit = new Retrofit.Builder()
                      //设置服务器路径
                      .baseUrl(Constant.API_SERVER + "/")
                      //添加转化库，默认是Gson
                      .addConverterFactory(GsonConverterFactory.create())
                      //添加回调库，采用RxJava
                      .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                      //设置使用okhttp网络请求
                      .client(mOkHttpClient)
                      .build();
          }
  
          return mRetrofit;
      }
  
  }
  