Skip to content

Instantly share code, notes, and snippets.

@dustin-graham
Created May 13, 2013 21:04
Show Gist options
  • Save dustin-graham/5571520 to your computer and use it in GitHub Desktop.
Save dustin-graham/5571520 to your computer and use it in GitHub Desktop.
Simple activity to pull data from whoismyrepresentative.org. This code throws a runtime error: java.lang.ExceptionInInitializerError caused by java.util.regex.PatternSyntaxException: Syntax error U_REGEX_RULE_SYNTAX near index 21: 05-13 14:55:03.464: E/AndroidRuntime(1568): \{([a-z][a-z0-9_-]*)} of RestMethodInfo line 46
package com.rain.example.retrofit.sanitycheck;
import java.util.List;
import retrofit.RestAdapter;
import retrofit.http.GET;
import retrofit.http.Query;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import com.rain.example.retrofit.sanitycheck.MainActivity.RepresentativeResponse.Representative;
public class MainActivity extends Activity {
private static final String REP_API_URL = "http://whoismyrepresentative.com";
class RepresentativeResponse {
List<Representative> results;
class Representative {
String name;
String party;
String state;
String district;
String phone;
String office;
String linke;
}
}
interface RepresentativeClient {
@GET("/getall_mems.php")
RepresentativeResponse getRepresentativesByZip(
@Query("zip") String zip, @Query("output") String output);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RestAdapter repRestAdapter = new RestAdapter.Builder().setServer(
REP_API_URL).build();
RepresentativeClient repClient = repRestAdapter.create(RepresentativeClient.class);
RepresentativeResponse repResponse = repClient.getRepresentativesByZip("84043", "json");
for (Representative rep : repResponse.results) {
System.out.println(rep.name);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment