Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/backend/FiveTAPIFetcher.java
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | public Palina ReadArrivalTimesAll(String stopID, AtomicReference<Result> res) { | ||||
Palina p = new Palina(stopID); | Palina p = new Palina(stopID); | ||||
//request parameters | //request parameters | ||||
String response = performAPIRequest(QueryType.ARRIVALS,stopID,res); | String response = performAPIRequest(QueryType.ARRIVALS,stopID,res); | ||||
if(response==null) { | if(response==null) { | ||||
if(res.get()== Result.SERVER_ERROR_404) { | if(res.get()== Result.SERVER_ERROR_404) { | ||||
Log.w(DEBUG_NAME,"Got 404, either the server failed, or the stop was not found, or the address is wrong"); | Log.w(DEBUG_NAME,"Got 404, either the server failed, or the stop was not found, or the address is wrong"); | ||||
res.set(Result.EMPTY_RESULT_SET); | //res.set(Result.S); | ||||
} | } | ||||
return p; | return p; | ||||
} | } | ||||
List<Route> routes = parseArrivalsServerResponse(response, res); | List<Route> routes = parseArrivalsServerResponse(response, res); | ||||
if(res.get()==Result.OK) { | if(res.get()==Result.OK) { | ||||
for (Route r : routes) { | for (Route r : routes) { | ||||
p.addRoute(r); | p.addRoute(r); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 317 Lines • ▼ Show 20 Lines | public static String performAPIRequest(QueryType t,@Nullable String stopID, AtomicReference<Result> res){ | ||||
//Log.d(DEBUG_NAME,"The address to query is: "+address); | //Log.d(DEBUG_NAME,"The address to query is: "+address); | ||||
param = getDefaultHeaders(); | param = getDefaultHeaders(); | ||||
u = new URL(address); | u = new URL(address); | ||||
} catch (UnsupportedEncodingException |MalformedURLException e) { | } catch (UnsupportedEncodingException |MalformedURLException e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
res.set(Result.PARSER_ERROR); | res.set(Result.PARSER_ERROR); | ||||
return null; | return null; | ||||
} | } | ||||
String response = networkTools.queryURL(u,res,param); | |||||
return response; | return networkTools.queryURL(u,res,param); | ||||
} | } | ||||
/** | /** | ||||
* Get the right url for the operation you are doing, to be fed into the queryURL method | * Get the right url for the operation you are doing, to be fed into the queryURL method | ||||
* @param t type of operation | * @param t type of operation | ||||
* @param stopID stop on which you are working on | * @param stopID stop on which you are working on | ||||
* @return the Url to go to | * @return the Url to go to | ||||
* @throws UnsupportedEncodingException if it cannot be converted to utf-8 | * @throws UnsupportedEncodingException if it cannot be converted to utf-8 | ||||
Show All 33 Lines |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register