use of retrofit2.Retrofit in project cw-omnibus by commonsguy.
the class QuestionsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View result = super.onCreateView(inflater, container, savedInstanceState);
setRetainInstance(true);
Retrofit retrofit = new Retrofit.Builder().baseUrl("https://api.stackexchange.com").addConverterFactory(GsonConverterFactory.create()).build();
StackOverflowInterface so = retrofit.create(StackOverflowInterface.class);
so.questions("android").enqueue(this);
return (result);
}
use of retrofit2.Retrofit in project RxJavaSamples by rengwuxian.
the class Network method getGankApi.
public static GankApi getGankApi() {
if (gankApi == null) {
Retrofit retrofit = new Retrofit.Builder().client(okHttpClient).baseUrl("http://gank.io/api/").addConverterFactory(gsonConverterFactory).addCallAdapterFactory(rxJavaCallAdapterFactory).build();
gankApi = retrofit.create(GankApi.class);
}
return gankApi;
}
use of retrofit2.Retrofit in project RxJavaSamples by rengwuxian.
the class Network method getZhuangbiApi.
public static ZhuangbiApi getZhuangbiApi() {
if (zhuangbiApi == null) {
Retrofit retrofit = new Retrofit.Builder().client(okHttpClient).baseUrl("http://www.zhuangbi.info/").addConverterFactory(gsonConverterFactory).addCallAdapterFactory(rxJavaCallAdapterFactory).build();
zhuangbiApi = retrofit.create(ZhuangbiApi.class);
}
return zhuangbiApi;
}
use of retrofit2.Retrofit in project muzei by romannurik.
the class FiveHundredPxExampleArtSource method onTryUpdate.
@Override
protected void onTryUpdate(@UpdateReason int reason) throws RetryException {
String currentToken = (getCurrentArtwork() != null) ? getCurrentArtwork().getToken() : null;
OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(new Interceptor() {
@Override
public Response intercept(final Chain chain) throws IOException {
Request request = chain.request();
HttpUrl url = request.url().newBuilder().addQueryParameter("consumer_key", Config.CONSUMER_KEY).build();
request = request.newBuilder().url(url).build();
return chain.proceed(request);
}
}).build();
Retrofit retrofit = new Retrofit.Builder().baseUrl("https://api.500px.com/").client(okHttpClient).addConverterFactory(GsonConverterFactory.create()).build();
FiveHundredPxService service = retrofit.create(FiveHundredPxService.class);
PhotosResponse response;
try {
response = service.getPopularPhotos().execute().body();
} catch (IOException e) {
Log.w(TAG, "Error reading 500px response", e);
throw new RetryException();
}
if (response == null || response.photos == null) {
throw new RetryException();
}
if (response.photos.size() == 0) {
Log.w(TAG, "No photos returned from API.");
scheduleUpdate(System.currentTimeMillis() + ROTATE_TIME_MILLIS);
return;
}
Random random = new Random();
Photo photo;
String token;
while (true) {
photo = response.photos.get(random.nextInt(response.photos.size()));
token = Integer.toString(photo.id);
if (response.photos.size() <= 1 || !TextUtils.equals(token, currentToken)) {
break;
}
}
publishArtwork(new Artwork.Builder().title(photo.name).byline(photo.user.fullname).imageUri(Uri.parse(photo.image_url)).token(token).viewIntent(new Intent(Intent.ACTION_VIEW, Uri.parse("http://500px.com/photo/" + photo.id))).build());
scheduleUpdate(System.currentTimeMillis() + ROTATE_TIME_MILLIS);
}
use of retrofit2.Retrofit in project retrofit by square.
the class ProtoConverterFactoryTest method setUp.
@Before
public void setUp() {
Retrofit retrofit = new Retrofit.Builder().baseUrl(server.url("/")).addConverterFactory(ProtoConverterFactory.create()).build();
service = retrofit.create(Service.class);
ExtensionRegistry registry = ExtensionRegistry.newInstance();
PhoneProtos.registerAllExtensions(registry);
Retrofit retrofitWithRegistry = new Retrofit.Builder().baseUrl(server.url("/")).addConverterFactory(ProtoConverterFactory.createWithRegistry(registry)).build();
serviceWithRegistry = retrofitWithRegistry.create(ServiceWithRegistry.class);
}
Aggregations