package net.gini.android.authorization.requests;

import com.android.volley.AuthFailureError;
import com.android.volley.Response;
import com.android.volley.toolbox.JsonObjectRequest;

import net.gini.android.MediaTypes;
import net.gini.android.authorization.Session;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

public class BearerJsonObjectRequest extends JsonObjectRequest {
    final private Session mSession;

    public BearerJsonObjectRequest(int method, String url, JSONObject jsonRequest, Session session, Response.Listener<JSONObject> listener, Response.ErrorListener errorListener) {
        super(method, url, jsonRequest, listener, errorListener);

        mSession = session;
    }

    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
        HashMap<String, String> headers = new HashMap<String, String>();
        headers.put("Accept", String.format("%s, %s", MediaTypes.APPLICATION_JSON, MediaTypes.GINI_JSON_V1));
        headers.put("Authorization", "BEARER " + mSession.getAccessToken());
        return headers;
    }
}

@@ -117,184 +117,431 @@
 ley.
-Response;%0Aimport com.android.volley.toolbox.JsonObjectRequest;%0A%0Aimport net.gini.android.MediaTypes;%0Aimport net.gini.android.authorization.Session;%0A%0Aimport org.json.JSONObject;%0A
+NetworkResponse;%0Aimport com.android.volley.ParseError;%0Aimport com.android.volley.Response;%0Aimport com.android.volley.toolbox.HttpHeaderParser;%0Aimport com.android.volley.toolbox.JsonObjectRequest;%0A%0Aimport net.gini.android.MediaTypes;%0Aimport net.gini.android.authorization.Session;%0A%0Aimport org.apache.http.protocol.HTTP;%0Aimport org.json.JSONException;%0Aimport org.json.JSONObject;%0A%0Aimport java.io.UnsupportedEncodingException;
 %0Aimp
@@ -1343,11 +1343,608 @@
 s;%0A    %7D
+%0A%0A    @Override%0A    protected Response%3CJSONObject%3E parseNetworkResponse(NetworkResponse response) %7B%0A        try %7B%0A            // The Gini API always uses UTF-8.%0A            final String jsonString = new String(response.data, HTTP.UTF_8);%0A            return Response.success(new JSONObject(jsonString),%0A                                    HttpHeaderParser.parseCacheHeaders(response));%0A        %7D catch (UnsupportedEncodingException e) %7B%0A            return Response.error(new ParseError(e));%0A        %7D catch (JSONException je) %7B%0A            return Response.error(new ParseError(je));%0A        %7D%0A    %7D
 %0A%7D%0A

Fix the encoding of API responses.