use of retrofit2.Retrofit in project gce2retrofit by chiuki.
the class Discovery method main.
public static void main(String[] args) {
Retrofit restAdapter = new Retrofit.Builder().baseUrl(API_URL).addConverterFactory(GsonConverterFactory.create()).build();
Apis apis = restAdapter.create(Apis.class);
try {
Response<DirectoryList> response = apis.list(null, null).execute();
System.out.println(response.body().kind);
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
use of retrofit2.Retrofit in project Retrofit-Android-Basic by basil2style.
the class ServiceGenerator method createService.
public static <S> S createService(Class<S> serviceClass, final String authToken) {
if (authToken != null) {
httpClient.interceptors().add(new Interceptor() {
@Override
public okhttp3.Response intercept(Interceptor.Chain chain) throws IOException {
Request original = chain.request();
// Request customization: add request headers
Request.Builder requestBuilder = original.newBuilder().header("Authorization", authToken).method(original.method(), original.body());
Request request = requestBuilder.build();
return chain.proceed(request);
}
});
}
OkHttpClient client = httpClient.build();
Retrofit retrofit = builder.client(client).build();
return retrofit.create(serviceClass);
}
use of retrofit2.Retrofit in project BBS-Android by bdpqchen.
the class CollectionClient method loadCollection.
void loadCollection() {
Retrofit retrofit = new Retrofit.Builder().client(client).addConverterFactory(GsonConverterFactory.create()).baseUrl(RxDoHttpClient.BASE_URL + "home/").build();
CollectionApi collectionApi = retrofit.create(CollectionApi.class);
Call<CollectionBean> call = collectionApi.getCollection(uidToken);
call.enqueue(new Callback<CollectionBean>() {
@Override
public void onResponse(Call<CollectionBean> call, Response<CollectionBean> response) {
if (response != null) {
collectionPresenter.setCollectionDate(response.body());
}
}
@Override
public void onFailure(Call<CollectionBean> call, Throwable t) {
}
});
}
use of retrofit2.Retrofit in project BBS-Android by bdpqchen.
the class CollectionClient method collectByTid.
// TODO: 2017/5/23 传入Prenster来处理返回数据
void collectByTid(String tid) {
Retrofit retrofit = new Retrofit.Builder().client(client).addConverterFactory(GsonConverterFactory.create()).baseUrl("https://bbs.twtstudio.com/api/home/").build();
CollectionApi collectionApi = retrofit.create(CollectionApi.class);
Call<SimpleBean> call = collectionApi.collectByTid(uidToken, tid);
call.enqueue(new Callback<SimpleBean>() {
@Override
public void onResponse(Call<SimpleBean> call, Response<SimpleBean> response) {
collectionPresenter.dealCollectData(response.body());
}
@Override
public void onFailure(Call<SimpleBean> call, Throwable t) {
}
});
}
use of retrofit2.Retrofit in project YourAppIdea by Michenux.
the class MongolabPlaceServiceFactory method create.
public static MongolabPlaceService create(Context context) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Timestamp.class, new TimestampDeserializer());
gsonBuilder.registerTypeAdapter(Location.class, new LocationDeserializer());
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new LoggingInterceptor()).build();
String url = context.getString(R.string.aroundme_placeremoteprovider_url);
Retrofit retrofit = new Retrofit.Builder().baseUrl(url).client(client).addConverterFactory(GsonConverterFactory.create(gsonBuilder.create())).addCallAdapterFactory(RxJavaCallAdapterFactory.create()).build();
return retrofit.create(MongolabPlaceService.class);
}
Aggregations