/** * Get a feed object by its feed identifier * * @param feedid Id of the Cosm feed to retrieve * @return Feed object which corresponds to the id provided as the parameter * @throws CosmException If something goes wrong, or if the Feed was not found. */ public Feed getFeed(int feedid, boolean show_user) throws CosmException { try { HttpGet hr = null; if (show_user) { hr = new HttpGet( API_BASE_URL_V2 + API_RESOURCE_FEEDS + "/" + feedid + JSON_FILE_EXTENSION + "?show_user=true"); } else { hr = new HttpGet( API_BASE_URL_V2 + API_RESOURCE_FEEDS + "/" + feedid + JSON_FILE_EXTENSION + "?show_user=false"); } HttpResponse response = this.client.execute(hr); StatusLine statusLine = response.getStatusLine(); String body = this.client.getBody(response); if (statusLine.getStatusCode() == 200) { return CosmFactory.toFeed(body); } throw new CosmException(statusLine, body); } catch (IOException e) { throw new CosmException(IO_EXCEPTION_MESSAGE); } }
public Waypoint[] getWaypoints( Integer feedid, String start, String end, String duration, Integer interval, Boolean find_previous, Interval_type interval_type, String timezone) throws CosmException { try { String url = API_BASE_URL_V2 + API_RESOURCE_FEEDS + "/" + feedid + JSON_FILE_EXTENSION + "?"; boolean bAdd = false; if (start != null) { if (bAdd) url += '&'; url += "start=" + start; bAdd = true; } if (end != null) { if (bAdd) url += '&'; url += "end=" + end; bAdd = true; } if (duration != null) { if (bAdd) url += '&'; url += "duration=" + duration; bAdd = true; } if (interval != null) { if (bAdd) url += '&'; url += "interval=" + interval; bAdd = true; } if (find_previous != null) { if (bAdd) url += '&'; url += "find_previous=" + find_previous.toString(); bAdd = true; } if (interval_type != null) { if (bAdd) url += '&'; url += "interval_type=" + interval_type.toString(); bAdd = true; } if (timezone != null) { if (bAdd) url += '&'; url += "timezone=" + timezone; } HttpGet request = new HttpGet(url); HttpResponse response = this.client.execute(request); StatusLine statusLine = response.getStatusLine(); String body = this.client.getBody(response); if (statusLine.getStatusCode() == 200) { Feed feed = CosmFactory.toFeed(body); Location location = feed.getLocation(); Waypoint[] waypoints = location.getWaypoints(); return waypoints; } throw new CosmException(statusLine, body); } catch (CosmException e) { throw e; } catch (NullPointerException e) { throw new CosmException(NULL_POINTER_EXCEPTION_MESSAGE); } catch (IOException e) { throw new CosmException(IO_EXCEPTION_MESSAGE); } }