Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/backend/mato/MapiArrivalRequest.java
/* | |||||
BusTO - Backend components | |||||
Copyright (C) 2021 Fabio Mazza | |||||
This program is free software: you can redistribute it and/or modify | |||||
it under the terms of the GNU General Public License as published by | |||||
the Free Software Foundation, either version 3 of the License, or | |||||
(at your option) any later version. | |||||
This program is distributed in the hope that it will be useful, | |||||
but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
GNU General Public License for more details. | |||||
You should have received a copy of the GNU General Public License | |||||
along with this program. If not, see <http://www.gnu.org/licenses/>. | |||||
*/ | |||||
package it.reyboz.bustorino.backend.mato; | package it.reyboz.bustorino.backend.mato; | ||||
import android.util.Log; | import android.util.Log; | ||||
import androidx.annotation.Nullable; | import androidx.annotation.Nullable; | ||||
import com.android.volley.AuthFailureError; | import com.android.volley.AuthFailureError; | ||||
import com.android.volley.NetworkResponse; | import com.android.volley.NetworkResponse; | ||||
Show All 38 Lines | public byte[] getBody() throws AuthFailureError { | ||||
data.put("operationName","AllStopsDirect"); | data.put("operationName","AllStopsDirect"); | ||||
variables.put("name", stopName); | variables.put("name", stopName); | ||||
variables.put("startTime", (long) startingTime.getTime()/1000); | variables.put("startTime", (long) startingTime.getTime()/1000); | ||||
variables.put("timeRange", timeRange); | variables.put("timeRange", timeRange); | ||||
variables.put("numberOfDepartures", numberOfDepartures); | variables.put("numberOfDepartures", numberOfDepartures); | ||||
data.put("variables", variables); | data.put("variables", variables); | ||||
data.put("query", MatoAPIFetcher.QUERY_ARRIVALS); | data.put("query", MatoQueries.QUERY_ARRIVALS); | ||||
} catch (JSONException e) { | } catch (JSONException e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
throw new AuthFailureError("Error with JSON enconding",e); | throw new AuthFailureError("Error with JSON enconding",e); | ||||
} | } | ||||
String requestBody = data.toString(); | String requestBody = data.toString(); | ||||
Log.d("MapiArrivalBusTO", "Request variables: "+ variables); | Log.d("MapiArrivalBusTO", "Request variables: "+ variables); | ||||
return requestBody.getBytes(); | return requestBody.getBytes(); | ||||
} | } | ||||
Show All 30 Lines | protected Response<Palina> parseNetworkResponse(NetworkResponse response) { | ||||
} catch (JSONException e) { | } catch (JSONException e) { | ||||
e.printStackTrace(); | e.printStackTrace(); | ||||
Log.e("BusTO:MapiRequest", "Error parsing JSON: "+stringResponse); | Log.e("BusTO:MapiRequest", "Error parsing JSON: "+stringResponse); | ||||
return Response.error(new VolleyError("Error parsing the response in JSON", | return Response.error(new VolleyError("Error parsing the response in JSON", | ||||
e)); | e)); | ||||
} | } | ||||
return Response.success(p, HttpHeaderParser.parseCacheHeaders(response)); | return Response.success(p, HttpHeaderParser.parseCacheHeaders(response)); | ||||
} | } | ||||
@Nullable | |||||
@Override | |||||
protected Map<String, String> getParams() throws AuthFailureError { | |||||
return new HashMap<>(); | |||||
} | |||||
} | } |
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