use of retrofit.RestAdapter 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.RestAdapter in project retrofit-examples by kdubb1337.
the class InterestingClient method main.
public static void main(String[] args) {
// Create our Converter
JacksonConverter converter = new JacksonConverter(new ObjectMapper());
// Build the Retrofit REST adaptor pointing to the URL specified, with the Converter.
// Note: The Converter must be set before the .build() command
RestAdapter restAdapter = new RestAdapter.Builder().setConverter(converter).setServer(API_URL).build();
// Create an instance of our InterestingApi interface.
InterestingApi api = restAdapter.create(InterestingApi.class);
// Call each of the methods and output the results
System.out.println("api.getDate()={" + api.getDate() + "}");
System.out.println("api.getWithPath()={" + api.getWithPath("my String 1234") + "}");
System.out.println("api.getWithQuery()={" + api.getWithQuery("my String 1234") + "}");
System.out.println("api.getWithBody()={" + api.getWithBody("my String 1234") + "}");
System.out.println("api.getWithDynamicHeader()={" + api.getWithDynamicHeader("max-age=26000") + "}");
System.out.println("api.getWithFixedHeaders()={" + api.getWithFixedHeaders() + "}");
}
use of retrofit.RestAdapter in project retrofit-examples by kdubb1337.
the class SimpleClient method main.
public static void main(String[] args) {
// Build the Retrofit REST adaptor pointing to the URL specified
RestAdapter restAdapter = new RestAdapter.Builder().setServer(API_URL).build();
// Create an instance of our SimpleApi interface.
SimpleApi simpleApi = restAdapter.create(SimpleApi.class);
// Call each of the methods and output the results
System.out.println("simpleApi.simpleGet()=<<" + simpleApi.simpleGet() + ">>");
System.out.println("simpleApi.simplePost()=<<" + simpleApi.simplePost() + ">>");
System.out.println("simpleApi.simpleDelete()=<<" + simpleApi.simpleDelete() + ">>");
System.out.println("simpleApi.simplePut()=<<" + simpleApi.simplePut() + ">>");
System.out.println("simpleApi.simpleHead()=<<" + simpleApi.simpleHead() + ">>");
System.out.println("simpleApi.simpleBoolean()=<<" + simpleApi.simpleBoolean() + ">>");
System.out.println("simpleApi.simpleInteger()=<<" + simpleApi.simpleInteger() + ">>");
System.out.println("simpleApi.simpleCollection()=<<" + simpleApi.simpleCollection() + ">>");
try {
ObjectMapper mapper = new ObjectMapper();
// We want to take a peek to see if all the fields are set correctly
CustomObject custom = simpleApi.simpleCustom();
System.out.println("simpleApi.simpleCustom()=<<" + custom + ">>");
System.out.println("simpleApi.simpleCustom() as JSON=<<" + mapper.writeValueAsString(custom) + ">>");
CustomChild child = simpleApi.simpleChild();
System.out.println("simpleApi.simpleChild()=<<" + child + ">>");
System.out.println("simpleApi.simpleChild() as JSON=<<" + mapper.writeValueAsString(child) + ">>");
} catch (IOException e) {
LOG.error("Failed to convert objects to JSON", e);
}
}
use of retrofit.RestAdapter in project Android-Week-View by alamkanak.
the class AsynchronousActivity method onMonthChange.
@Override
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {
// downloaded using retrofit, visit http://square.github.io/retrofit
if (!calledNetwork) {
RestAdapter retrofit = new RestAdapter.Builder().setEndpoint("https://api.myjson.com/bins").build();
MyJsonService service = retrofit.create(MyJsonService.class);
service.listEvents(this);
calledNetwork = true;
}
// Return only the events that matches newYear and newMonth.
List<WeekViewEvent> matchedEvents = new ArrayList<WeekViewEvent>();
for (WeekViewEvent event : events) {
if (eventMatches(event, newYear, newMonth)) {
matchedEvents.add(event);
}
}
return matchedEvents;
}
use of retrofit.RestAdapter in project enroscar by stanfy.
the class RetrofitClientTest method shouldWorkForContentScheme.
// content
@Test
public void shouldWorkForContentScheme() throws Exception {
String baseUri = "content://test.authority";
RestAdapter adapter = getRestAdapter(baseUri);
fetchAndTest(adapter);
Uri uri = Uri.parse(baseUri + "/thing?name=test");
verify(mockResolver).getType(uri);
verify(mockResolver).openAssetFileDescriptor(uri, "r");
}
Aggregations