Skip to content

Instantly share code, notes, and snippets.

@jpotts18
Created August 23, 2013 17:48
Show Gist options
  • Save jpotts18/6322044 to your computer and use it in GitHub Desktop.
Save jpotts18/6322044 to your computer and use it in GitHub Desktop.
package com.mydietitian.android.activities;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import retrofit.Callback;
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;
import retrofit.http.GET;
public class RetrofitActivity extends Activity {
String TAG = "RetrofitActivity";
JsonEchoService service;
JsonMock js;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
RestAdapter restAdapter = new RestAdapter.Builder()
.setServer("http://echo.jsontest.com")
.build();
service = restAdapter.create(JsonEchoService.class);
testJson();
}
private void testJson() {
service.getJsonAsync(new Callback<JsonMock>() {
@Override
public void success(JsonMock jsonMock, Response response) {
Log.i(TAG, jsonMock.toString());
Log.i(TAG, response.toString());
}
@Override
public void failure(RetrofitError retrofitError) {
Log.i(TAG, "failed");
}
});
}
public interface JsonEchoService{
@GET("/key/value/one/two/three/four")
void getJsonAsync(Callback<JsonMock> callback);
}
public class JsonMock {
String key;
String one;
String three;
@Override
public String toString() {
return "JsonMock {" +
"key='" + key + '\'' +
", one='" + one + '\'' +
", three='" + three + '\'' +
'}';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment