Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

package com.saholic.profittill.Volley;

import android.content.Context;

import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.toolbox.StringRequest;
import com.saholic.profittill.Constants.ProfitTillConstants;

import org.json.JSONObject;

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

/**
 * Created by kshitij on 24/7/15.
 */
public class Analytics extends Request<JSONObject> {


    private Response.Listener<JSONObject> listener;
    private Response.Listener<String> stringListener;
    private Response.ErrorListener errorListener ;
    private Map<String, String> params;
    private String analyticsUrl;


    public Analytics(String url, Map<String, String> params,
                     Response.Listener<JSONObject> reponseListener, Response.ErrorListener errorListener) {
        super(Method.GET, url, errorListener);
        this.listener = reponseListener;
        this.errorListener = errorListener;
        this.params = params;
        this.analyticsUrl=url;
    }

    public Analytics(String url, Map<String, String> params,
                     Response.Listener<String> reponseListener, Response.ErrorListener errorListener,int i) {
        super(Method.GET, url, errorListener);
        this.stringListener = reponseListener;
        this.errorListener = errorListener;
        this.params = params;
        this.analyticsUrl=url;
    }

    public void anlyticsRequest(Context c){
        RequestQueue queue = AnalyticsSingleton.getmInstance().getRequestQueue();
        StringRequest request = new StringRequest(
                Method.POST,
                analyticsUrl,
                AnalyticsStringResponse.getAnalyticsStringRequestInstance(),
                errorListener
        ){
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                return params;
            }

            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                String auth = ProfitTillConstants.BASIC_AUTH;
                headers.put("Authorization", auth);
                return headers;
            }
        };
        queue.add(request);
    }

    @Override
    protected Response<JSONObject> parseNetworkResponse(NetworkResponse response) {
        return null;
    }

    @Override
    protected void deliverResponse(JSONObject response) {

    }
}