Search in sources :

Example 1 with SimpleApi

use of com.kdubb.retrofitexamples.api.SimpleApi 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);
    }
}
Also used : CustomObject(com.kdubb.retrofitexamples.domain.CustomObject) SimpleApi(com.kdubb.retrofitexamples.api.SimpleApi) IOException(java.io.IOException) RestAdapter(retrofit.RestAdapter) CustomChild(com.kdubb.retrofitexamples.domain.CustomChild) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Aggregations

SimpleApi (com.kdubb.retrofitexamples.api.SimpleApi)1 CustomChild (com.kdubb.retrofitexamples.domain.CustomChild)1 CustomObject (com.kdubb.retrofitexamples.domain.CustomObject)1 IOException (java.io.IOException)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 RestAdapter (retrofit.RestAdapter)1