1 package net.jaekl.frank.octranspo;
3 import java.io.BufferedReader;
4 import java.io.InputStream;
5 import java.io.InputStreamReader;
6 import java.io.IOException;
7 import java.util.ArrayList;
9 import net.jaekl.frank.FrankException;
10 import net.jaekl.qd.QDException;
11 import net.jaekl.qd.http.RequestBroker;
13 import org.apache.http.NameValuePair;
14 import org.apache.http.message.BasicNameValuePair;
18 static final String API_KEY = "apiKey";
19 static final String APP_ID = "appID";
20 static final String GATEWAY_URL = "https://api.octranspo1.com/v1.2/";
21 static final String ROUTE_NO = "routeNo";
22 static final String STOP_NO = "stopNo";
23 static final String GET_ROUTE_SUMMARY_FOR_STOP = "GetRouteSummaryForStop";
24 static final String GET_NEXT_TRIPS_FOR_STOP = "GetNextTripsForStop";
25 static final String GET_NEXT_TRIPS_FOR_STOP_ALL_ROUTES = "GetNextTripsForStopAllRoutes";
27 RequestBroker m_broker;
28 ArrayList<NameValuePair> m_baseParams;
31 // appID The appID for our application
32 // is InputStream from which to read the apiKey
33 public Server(String appID, InputStream is) throws IOException {
34 assert (null != appID);
37 BufferedReader br = new BufferedReader(new InputStreamReader(is));
38 String apiKey = br.readLine();
40 m_baseParams = new ArrayList<NameValuePair>();
41 m_baseParams.add(new BasicNameValuePair(APP_ID, appID));
42 m_baseParams.add(new BasicNameValuePair(API_KEY, apiKey));
44 m_broker = new RequestBroker(GATEWAY_URL, m_baseParams);
47 public StopInfo getRouteSummaryForStop(int stopNo)
51 ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
52 params.add(new BasicNameValuePair(STOP_NO, Integer.valueOf(stopNo).toString()));
53 return (StopInfo) m_broker.submitAndParse(GET_ROUTE_SUMMARY_FOR_STOP, params, RouteSummary.class);
55 catch (QDException e) {
56 throw new FrankException(e);
60 public StopInfo getNextTripsForStop(int stopNo, int routeNo)
64 ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
65 params.add(new BasicNameValuePair(STOP_NO, Integer.valueOf(stopNo).toString()));
66 params.add(new BasicNameValuePair(ROUTE_NO, Integer.valueOf(routeNo).toString()));
67 return (StopInfo) m_broker.submitAndParse(GET_NEXT_TRIPS_FOR_STOP, params, NextTrips.class);
69 catch (QDException e) {
70 throw new FrankException(e);
74 public StopInfo getNextTripsForStopAllRoutes(int stopNo)
78 ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
79 params.add(new BasicNameValuePair(STOP_NO, Integer.valueOf(stopNo).toString()));
80 return (StopInfo) m_broker.submitAndParse(GET_NEXT_TRIPS_FOR_STOP_ALL_ROUTES, params, RouteSummary.class);
82 catch (QDException e) {
83 throw new FrankException(e);