<commit_before>package com.malalaoshi.android.net;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.malalaoshi.android.MalaApplication;
import com.malalaoshi.android.entity.CouponEntity;
import com.malalaoshi.android.entity.CreateChargeEntity;

import org.json.JSONObject;

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

/**
 * Network sender
 * Created by tianwei on 1/3/16.
 */
public class NetworkSender {
    private static final String URL_FETCH_VERIFY_CODE = "/api/v1/sms";
    private static final String URL_GET_USER_POLICY = "/api/v1/policy";
    private static final String URL_SAVE_CHILD_NAME = "/api/v1/parents";
    private static final String URL_COUPON_LIST = "/api/v1/coupons";
    private static final String URL_CREATE_COURSE_ORDER = "/api/v1/orders";
    private static List<CouponEntity> couponList;

    public static void verifyCode(final Map<String, String> params, final NetworkListener listener) {
        postStringRequest(URL_FETCH_VERIFY_CODE, params, listener);
    }

    private static void postStringRequest(String url, final Map<String, String> params, final NetworkListener listener) {
        stringRequest(Request.Method.POST, url, params, listener);
    }

    private static void stringRequest(int method, String url,
                                      final Map<String, String> params, final NetworkListener listener) {
        url = MalaApplication.getInstance().getMalaHost() + url;
        RequestQueue queue = MalaApplication.getHttpRequestQueue();
        StringRequest request = new StringRequest(method, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                if (listener != null) {
                    listener.onSucceed(s);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                if (listener != null) {
                    listener.onFailed(volleyError);
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                return params;
            }
        };
        queue.add(request);
    }

    private static void postJsonRequest(String url, final Map<String, String> headers,
                                        JSONObject json, final NetworkListener listener) {
        jsonRequest(Request.Method.POST, url, headers, json, listener);
    }

    private static void jsonRequest(int method, String url, final Map<String, String> headers,
                                    JSONObject json, final NetworkListener listener) {
        url = MalaApplication.getInstance().getMalaHost() + url;
        RequestQueue queue = MalaApplication.getHttpRequestQueue();
        JsonObjectRequest request = new JsonObjectRequest(method, url, json, new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject jsonObject) {<commit_msg>AN-75 Fix stringRequest set error<commit_after>package com.malalaoshi.android.net;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.StringRequest;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.malalaoshi.android.MalaApplication;
import com.malalaoshi.android.entity.CouponEntity;
import com.malalaoshi.android.entity.CreateChargeEntity;

import org.json.JSONObject;

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

/**
 * Network sender
 * Created by tianwei on 1/3/16.
 */
public class NetworkSender {
    private static final String URL_FETCH_VERIFY_CODE = "/api/v1/sms";
    private static final String URL_GET_USER_POLICY = "/api/v1/policy";
    private static final String URL_SAVE_CHILD_NAME = "/api/v1/parents";
    private static final String URL_COUPON_LIST = "/api/v1/coupons";
    private static final String URL_CREATE_COURSE_ORDER = "/api/v1/orders";
    private static List<CouponEntity> couponList;

    public static void verifyCode(final Map<String, String> params, final NetworkListener listener) {
        postStringRequest(URL_FETCH_VERIFY_CODE, params, listener);
    }

    private static void postStringRequest(String url, final Map<String, String> params, final NetworkListener listener) {
        url = MalaApplication.getInstance().getMalaHost() + url;
        RequestQueue queue = MalaApplication.getHttpRequestQueue();
        StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                if (listener != null) {
                    listener.onSucceed(s);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                if (listener != null) {
                    listener.onFailed(volleyError);
                }
            }
        }) {
            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                return params;
            }
        };
        queue.add(request);
    }

    private static void stringRequest(int method, String url, final Map<String, String> headers, final NetworkListener listener) {
        url = MalaApplication.getInstance().getMalaHost() + url;
        RequestQueue queue = MalaApplication.getHttpRequestQueue();
        StringRequest request = new StringRequest(method, url, new Response.Listener<String>() {
            @Override
            public void onResponse(String s) {
                if (listener != null) {
                    listener.onSucceed(s);
                }
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError volleyError) {
                if (listener != null) {
                    listener.onFailed(volleyError);
                }
            }
        }) {
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                return headers;
            }
        };
        queue.add(request);
    }

    private static void postJsonRequest(String url, final Map<String, String> headers,
                                        JSONObject json, final NetworkListener listener) {
        jsonRequest(Request.Method.POST, url, headers, json, listener);
    }

    private static void jsonRequest(int method, String url, final Map<String, String> headers,
                                    JSONObject json, final NetworkListener listener) {
        url = MalaApplication.getInstance().getMalaHost() + url;
        RequestQueue queue = MalaApplication.getHttpRequestQueue();
        JsonObjectRequest request = new JsonObjectRequest(method, url, json, new Response.Listener<JSONObject>() {

            @Override
            public void onResponse(JSONObject jsonObject) {
{'fraction_non_alphanumeric': 0.08784324180218608, 'fraction_numerical': 0.002665955745134631, 'mean_word_length': 2.5848064978499763, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4334207', 'n_tokens_mistral': 1967, 'n_tokens_neox': 1910, 'n_words': 475}