/**
   * @param clazz
   * @param endPoint
   * @param <T>
   * @return
   */
  public static <T> T createRetrofitService(final Class<T> clazz, final String endPoint) {

    final Retrofit.Builder builder =
        new Retrofit.Builder()
            .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .baseUrl(endPoint);

    OkHttpClient client =
        new OkHttpClient.Builder()
            .addInterceptor(
                new Interceptor() {
                  @Override
                  public Response intercept(Chain chain) throws IOException {
                    Request request = chain.request();
                    Request newRequest =
                        request
                            .newBuilder()
                            .addHeader("Authorization", "Client-ID " + ImgurService.CLIENT_ID)
                            .build();
                    return chain.proceed(newRequest);
                  }
                })
            .build();

    builder.client(client);

    T service = builder.build().create(clazz);
    return service;
  }
Ejemplo n.º 2
0
 public <S> S createService(Class<S> serviceClass) {
   return adapterBuilder.client(okBuilder.build()).build().create(serviceClass);
 }