use of retrofit2.Retrofit in project 2017-01-HUDI-MAC-CHAR by NHNNEXT.
the class ServiceGenerator method createService.
public static <S> S createService(Class<S> serviceClass, Context context) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
if (BuildConfig.DEBUG) {
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
} else {
logging.setLevel(HttpLoggingInterceptor.Level.NONE);
}
PersistentCookieStore cookieStore = new PersistentCookieStore(context);
java.net.CookieManager cookieManager = new java.net.CookieManager(cookieStore, CookiePolicy.ACCEPT_ALL);
OkHttpClient.Builder httpClient = new OkHttpClient.Builder().cookieJar(new JavaNetCookieJar(cookieManager)).addInterceptor(logging).addNetworkInterceptor(new StethoInterceptor());
Gson gson = new GsonBuilder().setLenient().create();
Retrofit retorfit = new Retrofit.Builder().baseUrl(MafiaRemoteService.BASE_URL).addConverterFactory(GsonConverterFactory.create(gson)).client(httpClient.build()).build();
return retorfit.create(serviceClass);
}
use of retrofit2.Retrofit in project MusicDNA by harjot-oberai.
the class HomeActivity method updateStreamingList.
private void updateStreamingList(String query) {
if (!isLocalVisible) {
mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if ((settings.isStreamOnlyOnWifiEnabled() && mWifi.isConnected()) || (!settings.isStreamOnlyOnWifiEnabled())) {
new Thread(new CancelCall()).start();
if (!query.equals("")) {
streamRecyclerContainer.setVisibility(View.VISIBLE);
startLoadingIndicator();
Retrofit client = new Retrofit.Builder().baseUrl(Config.API_URL).addConverterFactory(GsonConverterFactory.create()).build();
StreamService ss = client.create(StreamService.class);
call = ss.getTracks(query, 75);
call.enqueue(new Callback<List<Track>>() {
@Override
public void onResponse(Call<List<Track>> call, Response<List<Track>> response) {
if (response.isSuccessful()) {
streamingTrackList = response.body();
sAdapter = new StreamTracksHorizontalAdapter(streamingTrackList, ctx);
LinearLayoutManager mLayoutManager = new LinearLayoutManager(ctx, LinearLayoutManager.HORIZONTAL, false);
soundcloudRecyclerView.setLayoutManager(mLayoutManager);
soundcloudRecyclerView.setItemAnimator(new DefaultItemAnimator());
soundcloudRecyclerView.setAdapter(sAdapter);
if (streamingTrackList.size() == 0) {
streamRecyclerContainer.setVisibility(GONE);
} else {
streamRecyclerContainer.setVisibility(View.VISIBLE);
}
stopLoadingIndicator();
(soundcloudRecyclerView.getAdapter()).notifyDataSetChanged();
StreamMusicFragment sFrag = (StreamMusicFragment) fragMan.findFragmentByTag("stream");
if (sFrag != null) {
sFrag.dataChanged();
}
} else {
stopLoadingIndicator();
}
Log.d("RETRO", response.body() + "");
}
@Override
public void onFailure(Call<List<Track>> call, Throwable t) {
Log.d("RETRO1", t.getMessage());
}
});
} else {
stopLoadingIndicator();
streamRecyclerContainer.setVisibility(GONE);
}
} else {
stopLoadingIndicator();
streamRecyclerContainer.setVisibility(GONE);
}
}
}
use of retrofit2.Retrofit in project ListenerMusicPlayer by hefuyicoder.
the class NetworkModule method provideLastFMRetrofit.
@Provides
@Named("lastfm")
@PerApplication
Retrofit provideLastFMRetrofit() {
String endpointUrl = Constants.BASE_API_URL_LASTFM;
Gson gson = new GsonBuilder().create();
GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(gson);
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().cache(new Cache(FileUtil.getHttpCacheDir(ListenerApp.getContext()), Constants.HTTP_CACHE_SIZE)).connectTimeout(Constants.HTTP_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS).readTimeout(Constants.HTTP_READ_TIMEOUT, TimeUnit.MILLISECONDS).build();
// OkHttpClient newClient = client.newBuilder().addInterceptor(loggingInterceptor).build();
Retrofit retrofit = new Retrofit.Builder().baseUrl(endpointUrl).client(client).addConverterFactory(gsonConverterFactory).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build();
return retrofit;
}
use of retrofit2.Retrofit in project ListenerMusicPlayer by hefuyicoder.
the class NetworkModule method provideKuGouRetrofit.
@Provides
@Named("kugou")
@PerApplication
Retrofit provideKuGouRetrofit() {
String endpointUrl = Constants.BASE_API_URL_KUGOU;
Gson gson = new GsonBuilder().create();
GsonConverterFactory gsonConverterFactory = GsonConverterFactory.create(gson);
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().cache(new Cache(FileUtil.getHttpCacheDir(ListenerApp.getContext()), Constants.HTTP_CACHE_SIZE)).connectTimeout(Constants.HTTP_CONNECT_TIMEOUT, TimeUnit.MILLISECONDS).readTimeout(Constants.HTTP_READ_TIMEOUT, TimeUnit.MILLISECONDS).build();
// OkHttpClient newClient = client.newBuilder().addInterceptor(loggingInterceptor).build();
Retrofit retrofit = new Retrofit.Builder().baseUrl(endpointUrl).client(client).addConverterFactory(gsonConverterFactory).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build();
return retrofit;
}
use of retrofit2.Retrofit in project retrofit by square.
the class CallTest method responseBodyBuffers.
@Test
public void responseBodyBuffers() throws IOException {
Retrofit retrofit = new Retrofit.Builder().baseUrl(server.url("/")).addConverterFactory(new ToStringConverterFactory()).build();
Service example = retrofit.create(Service.class);
server.enqueue(new MockResponse().setBody("1234").setSocketPolicy(DISCONNECT_DURING_RESPONSE_BODY));
Call<ResponseBody> buffered = example.getBody();
// When buffering we will detect all socket problems before returning the Response.
try {
buffered.execute();
fail();
} catch (IOException e) {
assertThat(e).hasMessage("unexpected end of stream");
}
}
Aggregations