1
0
mirror of https://github.com/bspeice/itcs4180 synced 2024-11-13 19:08:20 -05:00

Add REST implementation skeleton

The Location class is still in flux, so waiting on that.
This commit is contained in:
DjBushido 2014-03-31 15:07:10 -04:00
parent a4412c749b
commit 8a527aace4
4 changed files with 58 additions and 1 deletions

View File

@ -3,6 +3,7 @@
<string name="app_name">UNCC Scavenger</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="hello_world">Hello world!</string>
<string name="endpoint">http://djbushido.no-ip.org/</string>
</resources>

View File

@ -0,0 +1,5 @@
package edu.uncc.scavenger.rest;
public class Location {
}

View File

@ -0,0 +1,34 @@
package edu.uncc.scavenger.rest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import edu.uncc.scavenger.R;
import android.content.Context;
import retrofit.RestAdapter;
public class LocationClient {
public static LocationService getAdapter(Context ctx) {
String endpoint = ctx.getString(R.string.endpoint);
RestAdapter ra = new RestAdapter.Builder().setEndpoint(endpoint).build();
return ra.create(LocationService.class);
}
public static String validateLocation(Context ctx, int id, String key) {
LocationService client = getAdapter(ctx);
Map<String, String> keys = new HashMap<String, String>();
keys.put("key", key);
keys.put("id", String.valueOf(id));
return client.getResult(keys);
}
public static List<Location> getLocations(Context ctx) {
LocationService client = getAdapter(ctx);
return client.listLocations();
}
}

View File

@ -0,0 +1,17 @@
package edu.uncc.scavenger.rest;
import java.util.List;
import java.util.Map;
import retrofit.http.GET;
import retrofit.http.QueryMap;
public interface LocationService {
@GET("/locations")
List<Location> listLocations();
@GET("/validate")
String getResult(@QueryMap Map<String, String> keys);
}