Commits

Luis Montiel  committed 2c1a649

Some changes to get feedback api working

  • Participants
  • Parent commits 5dcee12

Comments (0)

Files changed (1)

File src/main/java/urbanairship/UrbanAirshipClient.java

-
 package urbanairship;
 
 import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Type;
 import java.net.URLEncoder;
 import java.util.*;
 
 import org.apache.http.impl.client.BasicCredentialsProvider;
 import org.apache.http.impl.client.DefaultHttpClient;
 import org.apache.http.message.BasicHeader;
+import org.apache.http.message.BasicNameValuePair;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpParams;
 import org.apache.http.util.EntityUtils;
 
 import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
 
-public class UrbanAirshipClient
-{
+public class UrbanAirshipClient {
 	private static final String CHARSET = "UTF-8";
 	private String hostname = "go.urbanairship.com";
 	// private boolean production = false;
 	private String username;
 	private String password;
 	private HttpClient httpClient;
-	
-	public UrbanAirshipClient(String username, String password)
-	{
+
+	public UrbanAirshipClient(String username, String password) {
 		this.username = username;
 		this.password = password;
 		this.httpClient = null;
 	}
-	
-	public UrbanAirshipClient(String username, String password, String hostname)
-	{
-		this(username,password,null,hostname);
+
+	public UrbanAirshipClient(String username, String password, String hostname) {
+		this(username, password, null, hostname);
 	}
-	
-	public UrbanAirshipClient(String username, String password, HttpClient hc)
-	{
+
+	public UrbanAirshipClient(String username, String password, HttpClient hc) {
 		this.username = username;
 		this.password = password;
 		this.httpClient = hc;
 	}
-	
-	public UrbanAirshipClient(String username, String password, HttpClient hc, String hostname)
-	{
+
+	public UrbanAirshipClient(String username, String password, HttpClient hc,
+			String hostname) {
 		this.username = username;
 		this.password = password;
 		this.httpClient = hc;
 		this.hostname = hostname;
 	}
-	
-	public List<String> getTags()
-	{
+
+	public List<String> getTags() {
 		TagsResponse resp = get(TagsResponse.class, "/api/tags");
 
-		if (resp == null)
-		{
+		if (resp == null) {
 			return new ArrayList<String>();
-		}
-		else
-		{
+		} else {
 			return resp.tags;
 		}
 	}
-	
-	public HttpResponse addTagToDevice(String deviceToken, String tag)
-	{
-		if (tag.length() > 255)
-		{
-			throw new IllegalArgumentException("maximum tag length is 255. Tag: " + tag);
+
+	public HttpResponse addTagToDevice(String deviceToken, String tag) {
+		if (tag.length() > 255) {
+			throw new IllegalArgumentException(
+					"maximum tag length is 255. Tag: " + tag);
 		}
-		
-		return put("/api/device_tokens/" + encode(deviceToken) + "/tags/" + encode(tag));
-	}
-	
-	public void removeTagFromDevice(String deviceToken, String tag)
-	{
-		delete("/api/device_tokens/" + encode(deviceToken) + "/tags/" + encode(tag));
+
+		return put("/api/device_tokens/" + encode(deviceToken) + "/tags/"
+				+ encode(tag));
 	}
 
-	public List<String> getTagsForDevice(String deviceToken)
-	{
-		TagsResponse resp = get(TagsResponse.class, "/api/device_tokens/" + encode(deviceToken) + "/tags");
-		
-		if (resp == null)
-		{
+	public void removeTagFromDevice(String deviceToken, String tag) {
+		delete("/api/device_tokens/" + encode(deviceToken) + "/tags/"
+				+ encode(tag));
+	}
+
+	public List<String> getTagsForDevice(String deviceToken) {
+		TagsResponse resp = get(TagsResponse.class, "/api/device_tokens/"
+				+ encode(deviceToken) + "/tags");
+
+		if (resp == null) {
 			return new ArrayList<String>();
-		}
-		else
-		{
+		} else {
 			return resp.tags;
 		}
 	}
-	
-	public HttpResponse register(Device dev)
-	{
-		
+
+	public HttpResponse register(Device dev) {
+
 		String identifier = dev.getIdentifier();
 		String path = dev.getPath();
-		
-		if ( (identifier == null) || (identifier.trim().length() == 0) )
-		{
+
+		if ((identifier == null) || (identifier.trim().length() == 0)) {
 			throw new IllegalStateException("missing device identifier");
 		}
-		
-		return put("/api/" 
-				+ path 
-				+ "/" 
-				+ encode(identifier), 
-				dev);
+
+		return put("/api/" + path + "/" + encode(identifier), dev);
 	}
-	
-	public UserCredentials create(User u)
-	{
+
+	public UserCredentials create(User u) {
 		return post("/api/user/", u, UserCredentials.class);
 	}
-	
-	public void updateUserByUserId(User u, String userid)
-	{
-		if (userid == null)
-		{
+
+	public void updateUserByUserId(User u, String userid) {
+		if (userid == null) {
 			throw new IllegalArgumentException("userid parameter is null");
 		}
-		
+
 		put("/api/user/" + userid + "/", u);
 	}
-	
-	public HttpResponse updateUserByAlias(User u, String alias)
-	{
-		if (alias == null)
-		{
+
+	public HttpResponse updateUserByAlias(User u, String alias) {
+		if (alias == null) {
 			throw new IllegalArgumentException("alias parameter is null");
 		}
 		return put("/api/user/alias/" + alias + "/", u);
 	}
-	
-	public UserCredentials reset(UserCredentials creds)
-	{
-		return post("/api/user/" + creds.getUserId() + "/creds/reset/", creds, UserCredentials.class);
+
+	public UserCredentials reset(UserCredentials creds) {
+		return post("/api/user/" + creds.getUserId() + "/creds/reset/", creds,
+				UserCredentials.class);
 	}
-	
-	public void deleteUser(String userId)
-	{
+
+	public void deleteUser(String userId) {
 		delete("/api/user/" + userId + "/");
 	}
-	
-	public void deleteMessage(Message m)
-	{
+
+	public void deleteMessage(Message m) {
 		delete(m.getMessageUrl());
 	}
-	
-	public void deleteMessages(final Message...msgs)
-	{
+
+	public void deleteMessages(final Message... msgs) {
 		String[] urls = new String[msgs.length];
-		
-		for (int i = 0; i < msgs.length; i++)
-		{
+
+		for (int i = 0; i < msgs.length; i++) {
 			urls[i] = msgs[i].getMessageUrl();
 		}
-		
+
 		Map<String, String[]> map = new HashMap<String, String[]>();
 		map.put("delete", urls);
-		
+
 		post("/api/user/" + this.username + "/messages/delete/", map);
 	}
-	
-	public void send(Airmail airmail)
-	{
+
+	public void send(Airmail airmail) {
 		post("/api/airmail/send/", airmail);
 	}
-	
-	public void send(List<Airmail> airmailList)
-	{
+
+	public void send(List<Airmail> airmailList) {
 		post("/api/airmail/send/batch/", airmailList);
 	}
-	
-	public Messages getMessagesByUserId(String userId, boolean fullList)
-	{
+
+	public Messages getMessagesByUserId(String userId, boolean fullList) {
 		String uri = "/api/user/" + userId + "/messages/";
-		
-		if (fullList)
-		{
+
+		if (fullList) {
 			uri += "?full_list=true";
 		}
-		
+
 		return get(Messages.class, uri);
 	}
-	
-	public Messages getMessages()
-	{
+
+	public Messages getMessages() {
 		return getMessages(true);
 	}
-	
-	public Messages getMessages(boolean fullList)
-	{
+
+	public Messages getMessages(boolean fullList) {
 		return getMessagesByUserId(this.username, fullList);
 	}
-	
-	public String getMessageBody(String messageBodyUrl)
-	{
+
+	public String getMessageBody(String messageBodyUrl) {
 		return getString(messageBodyUrl);
 	}
-	
-	public Message getMessage(String messageUrl)
-	{
+
+	public Message getMessage(String messageUrl) {
 		return get(Message.class, messageUrl);
 	}
-	
-	public void markAsRead(String userId, final Message... msgs)
-	{
-		if (msgs.length == 0)
-		{
+
+	public void markAsRead(String userId, final Message... msgs) {
+		if (msgs.length == 0) {
 			throw new IllegalArgumentException("msgs.length is zero");
-		}
-		else if (msgs.length == 1)
-		{
+		} else if (msgs.length == 1) {
 			post(msgs[0].getMessageReadUrl(), null);
-		}
-		else
-		{
+		} else {
 			String[] urls = new String[msgs.length];
-			for (int i = 0; i < msgs.length; i++)
-			{
+			for (int i = 0; i < msgs.length; i++) {
 				urls[i] = msgs[i].getMessageReadUrl();
 			}
 			Map<String, String[]> map = new HashMap<String, String[]>();
 			map.put("mark_as_read", urls);
-			
+
 			post("/api/user/" + this.username + "/messages/unread/", map);
 		}
 	}
-	
-	public void sendToAllUsers(Airmail airmail)
-	{
+
+	public void sendToAllUsers(Airmail airmail) {
 		post("/api/airmail/send/broadcast/", airmail);
 	}
-	
-	protected HttpResponse put(String path)
-	{
+
+	protected HttpResponse put(String path) {
 		return put(path, null);
 	}
-	
-	protected HttpResponse put(String path, Object requestBodyObject)
-	{
+
+	protected HttpResponse put(String path, Object requestBodyObject) {
 		HttpPut put = createHttpPut(path);
-		
-		if (requestBodyObject != null)
-		{
+
+		if (requestBodyObject != null) {
 			put.setEntity(toJsonEntity(requestBodyObject));
 		}
-		
+
 		return execute(put);
 	}
-	
-	
-	protected void post(String path, Object requestBodyObject)
-	{
+
+	protected void post(String path, Object requestBodyObject) {
 		post(path, requestBodyObject, null);
 	}
-	
-	protected HttpPut createHttpPut(String path)
-	{
+
+	protected HttpPut createHttpPut(String path) {
 		HttpPut put = new HttpPut(getUrlForPath(path));
 		return put;
 	}
 
-	public Device getDeviceToken(String deviceToken)
-	{
-		return get(Device.class, "/api/device_tokens/" + encode(deviceToken)); 
+	public Device getDeviceToken(String deviceToken) {
+		return get(Device.class, "/api/device_tokens/" + encode(deviceToken));
 	}
-	
-	public DeviceTokensResponse getDeviceTokens()
-	{
-		return get(DeviceTokensResponse.class, "/api/device_tokens/"); 
+
+	public DeviceTokensResponse getDeviceTokens() {
+		return get(DeviceTokensResponse.class, "/api/device_tokens/");
 	}
-	
-	public APIDResponse getAPIDS()
-	{
+
+	public APIDResponse getAPIDS() {
 		return get(APIDResponse.class, "/api/apids/");
 	}
-	
-	public Feed[] getFeeds(){
+
+	public Feed[] getFeeds() {
 		return get(Feed[].class, "/api/feeds/");
 	}
-	
-	public Feed getFeed(String feed_id){
+
+	public Feed getFeed(String feed_id) {
 		return get(Feed.class, String.format("/api/feeds/%s/", encode(feed_id)));
 	}
-	
-	public void createFeed(Feed feed)
-	{
+
+	public void createFeed(Feed feed) {
 		post("/api/feeds/", feed);
 	}
-	
-	public HttpResponse updateFeed(Feed feed, String url)
-	{
+
+	public HttpResponse updateFeed(Feed feed, String url) {
 		return put(url, feed);
 	}
-	
-	public void deleteFeed(String url)
-	{
+
+	public void deleteFeed(String url) {
 		delete(url);
 	}
-	
-	
-	protected HttpGet createHttpGet(String path)
-	{
+
+	protected HttpGet createHttpGet(String path) {
 		HttpGet get = new HttpGet(this.getUrlForPath(path));
 		return get;
 	}
 	 * @return may return null
 	 * 
 	 */
-	public PushResponse sendPushNotifications(Push... p)
-	{
+	public PushResponse sendPushNotifications(Push... p) {
 		Class<PushResponse> responseClazz = PushResponse.class;
-		
+
 		PushResponse result = null;
-		
-		if (p.length == 0)
-		{
+
+		if (p.length == 0) {
 			throw new IllegalArgumentException("parameter p");
-		}
-		else if (p.length == 1)
-		{
+		} else if (p.length == 1) {
 			// single push notification
 			result = post("/api/push/", p[0], responseClazz);
-		}
-		else
-		{
+		} else {
 			// batch of push notifications
 			result = post("/api/push/batch/", p, responseClazz);
 		}
-		
+
 		return result;
 	}
-	
-	public void cancelScheduledNotifications(String... scheduledNotificationUrls)
-	{
+
+	public void cancelScheduledNotifications(
+			String... scheduledNotificationUrls) {
 		Map<String, String[]> cancelMap = new HashMap<String, String[]>();
 		cancelMap.put("cancel", scheduledNotificationUrls);
-		
+
 		post("https://" + getHostname() + "/api/push/scheduled/", cancelMap);
-		
+
 	}
-	
-	public void broadcast(Broadcast b)
-	{
+
+	public void broadcast(Broadcast b) {
 		post("/api/push/broadcast/", b);
 	}
-	
-	protected <T> T post(final String path, final Object obj, final Class<T> responseType)
-	{
-		
+
+	protected <T> T post(final String path, final Object obj,
+			final Class<T> responseType) {
+
 		HttpPost post = createHttpPost(path);
-		
-		if (obj != null)
-		{
+
+		if (obj != null) {
 			post.setEntity(toJsonEntity(obj));
 		}
-		
+
 		HttpResponse response = execute(post);
 
-		if (responseType == null)
-		{	
+		if (responseType == null) {
 			close(response);
 			return null;
-		}
-		else
-		{
+		} else {
 			T r = fromJson(response, responseType);
 			return r;
 		}
 	}
 
-	protected HttpEntity toJsonEntity(final Object obj)
-	{
-		
+	protected HttpEntity toJsonEntity(final Object obj) {
+
 		String json = toJson(obj);
-		
-		try
-		{
+
+		try {
 			return new JsonEntity(json);
-		}
-		catch (Exception ex)
-		{
+		} catch (Exception ex) {
 			Class<? extends Object> clazz = null;
-			if (obj != null)
-			{
+			if (obj != null) {
 				clazz = obj.getClass();
 			}
 			throw new RuntimeException("failure, obj class=" + clazz, ex);
 		}
-		
+
 	}
 
-	protected void checkResponse(HttpRequest request, HttpResponse response)
-	{
+	protected void checkResponse(HttpRequest request, HttpResponse response) {
 		boolean hasError = false;
-		
-		try
-		{
+
+		try {
 			StatusLine status = response.getStatusLine();
-			
+
 			int statusCode = status.getStatusCode();
-			
-		
-			if (statusCode == 404)
-			{
+
+			if (statusCode == 404) {
 				hasError = true;
 				throw new NotFoundException(status.getReasonPhrase());
-			}
-			else if ( (statusCode < 200) || (statusCode > 299) )
-			{
+			} else if ((statusCode < 200) || (statusCode > 299)) {
 				hasError = true;
-				
+
 				StringBuilder msg = new StringBuilder();
-				
+
 				msg.append("statusCode=" + statusCode);
-				
+
 				msg.append("\n");
-				
+
 				msg.append("method=" + request.getRequestLine().getMethod());
-				
+
 				msg.append("\n");
-				
+
 				msg.append(request.getRequestLine().getUri());
-				
-				
+
 				HttpEntity responseEntity = response.getEntity();
-				
-				try
-				{
+
+				try {
 					String responseBody = EntityUtils.toString(responseEntity);
 					msg.append("\n");
 					msg.append("responseBody=" + responseBody);
-				}
-				catch (Exception ignored)
-				{
+				} catch (Exception ignored) {
 					// ignored
 				}
 
 				throw new RuntimeException("unexpected response\n" + msg);
 			}
-		}
-		finally
-		{
-			if (hasError)
-			{
+		} finally {
+			if (hasError) {
 				close(response);
 			}
 		}
 	}
 
-	protected void close(final HttpResponse resp)
-	{
-		if (resp != null)
-		{
-			try
-			{
+	protected void close(final HttpResponse resp) {
+		if (resp != null) {
+			try {
 				close(resp.getEntity());
-			}
-			catch (Exception ignored)
-			{
-				// ignored
-			}
-		}
-	}
-	
-	protected void close(final HttpEntity responseEntity)
-	{
-		if (responseEntity != null)
-		{
-			try
-			{
-				//responseEntity.consumeContent();
-				EntityUtils.consume(responseEntity);
-			}
-			catch (Exception ignored)
-			{
+			} catch (Exception ignored) {
 				// ignored
 			}
 		}
 	}
 
-	protected <T> T fromJson(HttpResponse rsp, Class<T> clazz)
-	{
-		if (clazz == null)
-		{
+	protected void close(final HttpEntity responseEntity) {
+		if (responseEntity != null) {
+			try {
+				// responseEntity.consumeContent();
+				EntityUtils.consume(responseEntity);
+			} catch (Exception ignored) {
+				// ignored
+			}
+		}
+	}
+
+	protected <T> T fromJson(HttpResponse rsp, Class<T> clazz) {
+		if (clazz == null) {
 			return null;
 		}
-		
-		if (rsp.getEntity() == null)
-		{
+
+		if (rsp.getEntity() == null) {
 			return null;
 		}
-		
-		try
-		{
+
+		try {
 			String responseBody = EntityUtils.toString(rsp.getEntity());
 			return fromJson(responseBody, clazz);
-		}
-		catch (RuntimeException rtex)
-		{
+		} catch (RuntimeException rtex) {
 			throw rtex;
-		}
-		catch (Exception e)
-		{
+		} catch (Exception e) {
 			throw new RuntimeException(e);
-		}
-		finally
-		{
+		} finally {
 			close(rsp);
 		}
 	}
 	
-	public List<Stat> getPushStats(Calendar start, Calendar end)
-	{
-		// TODO 
+	protected <T> T fromJson(HttpResponse rsp, Type clazz) {
+		if (clazz == null) {
+			return null;
+		}
+
+		if (rsp.getEntity() == null) {
+			return null;
+		}
+
+		try {
+			String responseBody = EntityUtils.toString(rsp.getEntity());
+			return fromJson(responseBody, clazz);
+		} catch (RuntimeException rtex) {
+			throw rtex;
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		} finally {
+			close(rsp);
+		}
+	}
+
+	public List<Stat> getPushStats(Calendar start, Calendar end) {
+		// TODO
 		return null;
 	}
-	
-	protected HttpResponse execute(HttpRequestBase method)
-	{
+
+	protected HttpResponse execute(HttpRequestBase method) {
 		HttpResponse rsp = null;
-		try
-		{
+		try {
 			method.setHeader(new BasicHeader("Accept", "application/json"));
 			rsp = getHttpClient().execute(method);
 			checkResponse(method, rsp);
 			return rsp;
-		}
-		catch (RuntimeException rtex)
-		{
+		} catch (RuntimeException rtex) {
 			throw rtex;
-		}
-		catch (Exception ex)
-		{
+		} catch (Exception ex) {
 			throw new RuntimeException(ex);
 		}
 	}
 
-	protected HttpClient getHttpClient()
-	{
-		if (this.httpClient == null)
-		{
+	protected HttpClient getHttpClient() {
+		if (this.httpClient == null) {
 			this.httpClient = createHttpClient();
 		}
 		return this.httpClient;
 	}
-	
-	protected HttpClient createHttpClient()
-	{
+
+	protected HttpClient createHttpClient() {
 		DefaultHttpClient client = new DefaultHttpClient();
-		
-		client.getParams().setParameter(AllClientPNames.USER_AGENT, "urbanairship-java library");
+
+		client.getParams().setParameter(AllClientPNames.USER_AGENT,
+				"urbanairship-java library");
 
 		CredentialsProvider credProvider = new BasicCredentialsProvider();
-		
-		credProvider.setCredentials(
-		    new AuthScope(getHostname(), AuthScope.ANY_PORT), 
-		    new UsernamePasswordCredentials(getUsername(), getPassword()));
-		
+
+		credProvider.setCredentials(new AuthScope(getHostname(),
+				AuthScope.ANY_PORT), new UsernamePasswordCredentials(
+				getUsername(), getPassword()));
+
 		client.setCredentialsProvider(credProvider);
-		
+
 		return client;
 	}
 
-	protected String getUsername()
-	{
+	protected String getUsername() {
 		return this.username;
 	}
 
-	protected String getPassword()
-	{
+	protected String getPassword() {
 		return this.password;
 	}
 
-	private HttpPost createHttpPost(final String path)
-	{
+	private HttpPost createHttpPost(final String path) {
 		String url = getUrlForPath(path);
-		
+
 		HttpPost post = new HttpPost(url);
-		
+
 		return post;
 	}
 
-	protected String getUrlForPath(final String path)
-	{
-		if (path.startsWith("http://") || (path.startsWith("https://")))
-		{
+	protected String getUrlForPath(final String path) {
+		if (path.startsWith("http://") || (path.startsWith("https://"))) {
 			return path;
-		}
-		else
-		{
-			return "https://" 
-				+ getHostname()
-				+ path;
+		} else {
+			return "https://" + getHostname() + path;
 		}
 	}
 
-	protected String getHostname()
-	{
+	protected String getHostname() {
 		return hostname;
 	}
-	
-	public void setHostname(String val)
-	{
+
+	public void setHostname(String val) {
 		hostname = val;
 	}
-	
+
 	/*
-	protected boolean isProduction()
-	{
-		return this.production;
-	} */
+	 * protected boolean isProduction() { return this.production; }
+	 */
 
-	public FeedbackList getFeedback(final long since)
-	{
-		if (since < 0)
-		{
+	public List<Feedback> getFeedback(final long since) {
+		if (since < 0) {
 			throw new IllegalArgumentException("since parameter: " + since);
 		}
-		
+
 		Calendar c = Calendar.getInstance();
 		c.setTimeInMillis(since);
 		return getFeedback(c);
 	}
-	
-	public FeedbackList getFeedback(final Calendar since)
-	{
-		FeedbackList feedbackList = get(
-						FeedbackList.class,
-						"/api/device_tokens/feedback/",
-						"since", 
-						ISO8601.toString(since));
+
+	public List<Feedback> getFeedback(final Calendar since) {
+		Type collectionType = new TypeToken<java.util.List<Feedback>>(){}.getType();
 		
+		List<Feedback> feedbackList = get(collectionType,
+				"/api/device_tokens/feedback/", "since",
+				ISO8601.toString(since));
+
 		return feedbackList;
 	}
 
-	protected String getString(final String path, final String... parameters)
-	{
+	
+	protected String getString(final String path, final String... parameters) {
 		HttpGet get = createHttpGet(path);
-		
+
 		HttpResponse rsp = this.execute(get);
-		
+
 		return toString(rsp);
 	}
-	
-	protected String toString(HttpResponse rsp)
-	{
-		try
-		{
+
+	protected String toString(HttpResponse rsp) {
+		try {
 			return EntityUtils.toString(rsp.getEntity());
-		}
-		catch (java.io.IOException ex)
-		{
+		} catch (java.io.IOException ex) {
 			throw new RuntimeException(ex);
-		}
-		finally
-		{
+		} finally {
 			close(rsp);
 		}
 	}
-	
-	protected <T> T get(final Class<T> clazz, final String path, final String... parameters)
-	{
-		HttpGet get = createHttpGet(path);
+
+	protected HttpParams getHttpParams(String... parameters) { // Does not work
+																// for GET
+		HttpParams params = new BasicHttpParams();
+		for (int i = 0; i <= parameters.length - 1; i = i + 2) {
+			params.setParameter(parameters[i], parameters[i + 1]);
+		}
+		return params;
+	}
+
+	private String getPathWithParams(String path, String... parameters) {
+		List<NameValuePair> params = new LinkedList<NameValuePair>();
 		
-		HttpResponse rsp = this.execute(get);
-		
+		if (!(parameters.length >= 2 && parameters.length % 2 == 0))
+			return path;
+
+		for (int i = 0; i <= parameters.length - 1; i = i + 2) {
+			params.add(new BasicNameValuePair(parameters[i], parameters[i + 1]));
+		}
+		StringBuilder sb = new StringBuilder();
+		for (NameValuePair pair : params){
+			sb.append(pair.getName());
+			sb.append("=");
+			sb.append(pair.getValue());
+			sb.append("&");
+		}
+		sb.replace(sb.length()-1, sb.length(), "");
+		//return path + URLEncodedUtils.format(params, "utf-8"); // Not working for UA
+		return path + "?" + sb.toString();
+	}
+
+	protected <T> T get(final Class<T> clazz, final String path,
+			final String... parameters) {
+		HttpResponse rsp = this.execute(createHttpGet(getPathWithParams(path, parameters)));
 		return fromJson(rsp, clazz);
 	}
 	
-	protected <T> String toJson(final T object)
-	{
-		if (object == null)
-		{
+	protected <T> T get(final Type clazz, final String path,
+			final String... parameters) {		
+		HttpResponse rsp = this.execute(createHttpGet(getPathWithParams(path, parameters)));
+		return fromJson(rsp, clazz);
+	}
+
+	protected <T> String toJson(final T object) {
+		if (object == null) {
 			throw new IllegalArgumentException("object parameter is null");
 		}
-		
+
 		Gson gson = GsonFactory.create();
 		return gson.toJson(object);
 	}
+
+	protected <T> T fromJson(final String json, final Class<T> clazz) {
+		Gson gson = GsonFactory.create();
+		return gson.fromJson(json, clazz);
+	}
 	
-	protected <T> T fromJson(final String json, final Class<T> clazz)
-	{
+	protected <T> T fromJson(final String json, final Type clazz) {
 		Gson gson = GsonFactory.create();
 		return gson.fromJson(json, clazz);
 	}
 
-	protected void delete(final String path)
-	{
+	protected void delete(final String path) {
 		HttpDelete delete = createHttpDelete(path);
 		close(execute(delete));
 	}
 
-	private HttpDelete createHttpDelete(final String path)
-	{
+	private HttpDelete createHttpDelete(final String path) {
 		HttpDelete delete = new HttpDelete(getUrlForPath(path));
 		return delete;
 	}
 
-	protected String encode(String s)
-	{
-		try
-		{
+	protected String encode(String s) {
+		try {
 			return URLEncoder.encode(s, "UTF-8");
-		}
-		catch (UnsupportedEncodingException e)
-		{
+		} catch (UnsupportedEncodingException e) {
 			throw new RuntimeException(e);
 		}
 	}
 
-	static private class JsonEntity extends StringEntity
-	{
-		
-		public JsonEntity(String jsonString) throws UnsupportedEncodingException
-		{
+	static private class JsonEntity extends StringEntity {
+
+		public JsonEntity(String jsonString)
+				throws UnsupportedEncodingException {
 			super(jsonString, CHARSET);
 		}
-		
-		
+
 		@Override
-		public Header getContentType()
-		{
+		public Header getContentType() {
 			Header h = new BasicHeader("Content-Type", "application/json");
 			return h;
 		}
-		
+
 	}
 
-	public void setUserAgent(String agentString)
-	{
-		if (agentString == null)
-		{
-			this.getHttpClient().getParams().removeParameter(AllClientPNames.USER_AGENT);
-		}
-		else
-		{
-			this.getHttpClient().getParams().setParameter(AllClientPNames.USER_AGENT, agentString);
+	public void setUserAgent(String agentString) {
+		if (agentString == null) {
+			this.getHttpClient().getParams()
+					.removeParameter(AllClientPNames.USER_AGENT);
+		} else {
+			this.getHttpClient().getParams()
+					.setParameter(AllClientPNames.USER_AGENT, agentString);
 		}
 	}
-	
-	public void shutdown()
-	{
-		if (this.getHttpClient() != null)
-		{
-			try
-			{
+
+	public void shutdown() {
+		if (this.getHttpClient() != null) {
+			try {
 				this.getHttpClient().getConnectionManager().shutdown();
-			}
-			catch (Exception ignored)
-			{
+			} catch (Exception ignored) {
 				// ignored
 			}
 		}