mirror of
				https://github.com/bspeice/itcs4180
				synced 2025-11-03 18:00:37 -05:00 
			
		
		
		
	Add REST implementation skeleton
The Location class is still in flux, so waiting on that.
This commit is contained in:
		
							
								
								
									
										5
									
								
								UNCCScavenger/src/edu/uncc/scavenger/rest/Location.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								UNCCScavenger/src/edu/uncc/scavenger/rest/Location.java
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,5 @@
 | 
			
		||||
package edu.uncc.scavenger.rest;
 | 
			
		||||
 | 
			
		||||
public class Location {
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -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();
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@ -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);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user