use of retrofit.RetrofitError in project retrofit-examples by kdubb1337.
the class AsynchronousClient method main.
public static void main(String[] args) {
// Build the Retrofit REST adaptor pointing to the URL specified
// with a ThrottlingInterceptor allowing only 1 request per second
RestAdapter restAdapter = new RestAdapter.Builder().setRequestInterceptor(new ThrottlingInterceptor(1000L)).setServer(API_URL).build();
// Create an instance of our InterestingApi interface.
InterestingApi synchronousApi = restAdapter.create(InterestingApi.class);
// Create an instance of our AsynchronousApi interface.
AsynchronousApi asyncApi = restAdapter.create(AsynchronousApi.class);
for (int i = 0; i < 10; i++) LOG.info("synchronousApi " + synchronousApi.getWithPath(Integer.toString(i)));
for (int i = 0; i < 10; i++) asyncApi.getWithPath(Integer.toString(i), new Callback<String>() {
@Override
public void success(String t, Response response) {
LOG.info("asynchronousApi (" + t + ")");
}
@Override
public void failure(RetrofitError error) {
LOG.info("Epic fail!");
}
});
}
use of retrofit.RetrofitError in project mortar by square.
the class Chat method getMessages.
public Observable<Message> getMessages() {
return Observable.create(new Observable.OnSubscribe<Message>() {
@Override
public void call(final Subscriber<? super Message> subscriber) {
final Random random = new Random();
while (true) {
if (random.nextInt(PROBABILITY) == 0) {
try {
User from = users.get(random.nextInt(users.size()));
Message next = new Message(from, chats.service.getQuote().quote);
messages.add(next);
if (!subscriber.isUnsubscribed()) {
subscriber.onNext(next);
}
} catch (RetrofitError e) {
if (!subscriber.isUnsubscribed()) {
subscriber.onError(e);
break;
}
}
}
try {
// Hijacking the thread like this is sleazey, but you get the idea.
Thread.sleep(SLEEP_MILLIS);
} catch (InterruptedException e) {
if (!subscriber.isUnsubscribed()) {
subscriber.onError(e);
}
break;
}
}
}
}).startWith(//
messages).subscribeOn(//
Schedulers.io()).observeOn(AndroidSchedulers.mainThread());
}
use of retrofit.RetrofitError in project cw-omnibus by commonsguy.
the class SOTests method fetchQuestions.
@Test(timeout = 30000)
public void fetchQuestions() throws InterruptedException {
RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint("https://api.stackexchange.com").build();
StackOverflowInterface so = restAdapter.create(StackOverflowInterface.class);
so.questions("android", new Callback<SOQuestions>() {
@Override
public void success(SOQuestions soQuestions, Response response) {
questions = soQuestions;
responseLatch.countDown();
}
@Override
public void failure(RetrofitError error) {
responseLatch.countDown();
}
});
responseLatch.await();
Assert.assertNotNull(questions);
Assert.assertEquals(30, questions.items.size());
for (Item item : questions.items) {
Assert.assertNotNull(item.title);
Assert.assertNotNull(item.link);
}
}
Aggregations