// Path: architecture/src/main/java/com/jiang/android/architecture/okhttp/Param.java
// public class Param {
//     public Param(String key,String value) {
//         this.key = key;
//         this.value = value;
//     }
// 
//     public String key;
//     public String value;
// 
// 
//     @Override
//     public String toString() {
//         return key + "=" + value;
//     }
// }
// 
// Path: architecture/src/main/java/com/jiang/android/architecture/okhttp/utils/HeaderUtils.java
// public class HeaderUtils {
// 
//     public static List<Param> validateHeaders(Map<String, String> header) {
//         if (header == null || header.size() == 0)
//             return null;
//         List<Param> results = new LinkedList<>();
//         Set<Map.Entry<String, String>> entrySet = header.entrySet();
//         for (Map.Entry<String, String> entry : entrySet) {
//             Param param = new Param(entry.getKey(), entry.getValue());
//             results.add(param);
//         }
//         return results;
// 
// 
//     }
// }
// 
// Path: architecture/src/main/java/com/jiang/android/architecture/okhttp/utils/HttpUtils.java
// public class HttpUtils {
// 
//     public static String parseParams2String(Map<String, String> param) {
//         if (param == null || param.size() == 0)
//             return "";
// 
//         StringBuffer buffer = new StringBuffer();
//         Set<Map.Entry<String, String>> entrySet = param.entrySet();
//         for (Map.Entry<String, String> entry : entrySet) {
//             Param par = new Param(entry.getKey(), entry.getValue());
//             buffer.append(par.toString()).append("&");
// 
//         }
//         return buffer.substring(0, buffer.length() - 1);
// 
//     }
// 
// 
//     public static boolean isNetworkConnected(Context ct) {
//         ConnectivityManager cm = (ConnectivityManager) ct.getSystemService(Context.CONNECTIVITY_SERVICE);
//         NetworkInfo ni = cm.getActiveNetworkInfo();
//         return ni != null && ni.isConnectedOrConnecting();
//     }
// 
//     public static final int NETTYPE_WIFI = 0x01;
//     public static final int NETTYPE_CMWAP = 0x02;
//     public static final int NETTYPE_CMNET = 0x03;
// 
//     public static int getNetworkType(Context ct) {
//         int netType = 0;
//         ConnectivityManager connectivityManager = (ConnectivityManager) ct.getSystemService(Context.CONNECTIVITY_SERVICE);
//         NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
//         if (networkInfo == null) {
//             return netType;
//         }
//         int nType = networkInfo.getType();
//         if (nType == ConnectivityManager.TYPE_MOBILE) {
//             String extraInfo = networkInfo.getExtraInfo();
//             if (!TextUtils.isEmpty(extraInfo)) {
//                 if (extraInfo.toLowerCase().equals("cmnet")) {
//                     netType = NETTYPE_CMNET;
//                 } else {
//                     netType = NETTYPE_CMWAP;
//                 }
//             }
//         } else if (nType == ConnectivityManager.TYPE_WIFI) {
//             netType = NETTYPE_WIFI;
//         }
//         return netType;
//     }
// 
// }


import java.util.List;
import java.util.Map;
import okhttp3.Request;
import com.jiang.android.architecture.okhttp.Param;
import com.jiang.android.architecture.okhttp.utils.HeaderUtils;
import com.jiang.android.architecture.okhttp.utils.HttpUtils;
/**
 * created by jiang, 15/10/19
 * Copyright (c) 2015, jyuesong@gmail.com All Rights Reserved.
 * *                #                                                   #
 * #                       _oo0oo_                     #
 * #                      o8888888o                    #
 * #                      88" . "88                    #
 * #                      (| -_- |)                    #
 * #                      0\  =  /0                    #
 * #                    ___/`---'\___                  #
 * #                  .' \\|     |# '.                 #
 * #                 / \\|||  :  |||# \                #
 * #                / _||||| -:- |||||- \              #
 * #               |   | \\\  -  #/ |   |              #
 * #               | \_|  ''\---/''  |_/ |             #
 * #               \  .-\__  '-'  ___/-. /             #
 * #             ___'. .'  /--.--\  `. .'___           #
 * #          ."" '<  `.___\_<|>_/___.' >' "".         #
 * #         | | :  `- \`.;`\ _ /`;.`/ - ` : | |       #
 * #         \  \ `_.   \_ __\ /__ _/   .-` /  /       #
 * #     =====`-.____`.___ \_____/___.-`___.-'=====    #
 * #                       `=---='                     #
 * #     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   #
 * #                                                   #
 * #               佛祖保佑         永无BUG              #
 * #                                                   #
 */
package com.jiang.android.architecture.okhttp.request;




/**
 * 生成get请求需要的request
 * Created by jiang on 15/10/16.
 */
public class getRequest  {

    public static Request buildGetRequest(String url, Map<String, String> params, Object tag, Map<String, String> headers) {
        Request.Builder builder = new Request.Builder();

        List<Param> valdatedHeaders = HeaderUtils.validateHeaders(headers);
        if (valdatedHeaders != null && valdatedHeaders.size() != 0) {
            for (int i = 0; i < valdatedHeaders.size(); i++) {
                Param param = valdatedHeaders.get(i);
                String key = param.key;
                String value = param.value;
                builder.addHeader(key, value);
            }

        }

        if (params != null && params.size() != 0) {
// Path: architecture/src/main/java/com/jiang/android/architecture/okhttp/Param.java
// public class Param {
//     public Param(String key,String value) {
//         this.key = key;
//         this.value = value;
//     }
// 
//     public String key;
//     public String value;
// 
// 
//     @Override
//     public String toString() {
//         return key + "=" + value;
//     }
// }
// 
// Path: architecture/src/main/java/com/jiang/android/architecture/okhttp/utils/HeaderUtils.java
// public class HeaderUtils {
// 
//     public static List<Param> validateHeaders(Map<String, String> header) {
//         if (header == null || header.size() == 0)
//             return null;
//         List<Param> results = new LinkedList<>();
//         Set<Map.Entry<String, String>> entrySet = header.entrySet();
//         for (Map.Entry<String, String> entry : entrySet) {
//             Param param = new Param(entry.getKey(), entry.getValue());
//             results.add(param);
//         }
//         return results;
// 
// 
//     }
// }
// 
// Path: architecture/src/main/java/com/jiang/android/architecture/okhttp/utils/HttpUtils.java
// public class HttpUtils {
// 
//     public static String parseParams2String(Map<String, String> param) {
//         if (param == null || param.size() == 0)
//             return "";
// 
//         StringBuffer buffer = new StringBuffer();
//         Set<Map.Entry<String, String>> entrySet = param.entrySet();
//         for (Map.Entry<String, String> entry : entrySet) {
//             Param par = new Param(entry.getKey(), entry.getValue());
//             buffer.append(par.toString()).append("&");
// 
//         }
//         return buffer.substring(0, buffer.length() - 1);
// 
//     }
// 
// 
//     public static boolean isNetworkConnected(Context ct) {
//         ConnectivityManager cm = (ConnectivityManager) ct.getSystemService(Context.CONNECTIVITY_SERVICE);
//         NetworkInfo ni = cm.getActiveNetworkInfo();
//         return ni != null && ni.isConnectedOrConnecting();
//     }
// 
//     public static final int NETTYPE_WIFI = 0x01;
//     public static final int NETTYPE_CMWAP = 0x02;
//     public static final int NETTYPE_CMNET = 0x03;
// 
//     public static int getNetworkType(Context ct) {
//         int netType = 0;
//         ConnectivityManager connectivityManager = (ConnectivityManager) ct.getSystemService(Context.CONNECTIVITY_SERVICE);
//         NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
//         if (networkInfo == null) {
//             return netType;
//         }
//         int nType = networkInfo.getType();
//         if (nType == ConnectivityManager.TYPE_MOBILE) {
//             String extraInfo = networkInfo.getExtraInfo();
//             if (!TextUtils.isEmpty(extraInfo)) {
//                 if (extraInfo.toLowerCase().equals("cmnet")) {
//                     netType = NETTYPE_CMNET;
//                 } else {
//                     netType = NETTYPE_CMWAP;
//                 }
//             }
//         } else if (nType == ConnectivityManager.TYPE_WIFI) {
//             netType = NETTYPE_WIFI;
//         }
//         return netType;
//     }
// 
// }


// Path: architecture/src/main/java/com/jiang/android/architecture/okhttp/request/getRequest.java
import java.util.List;
import java.util.Map;
import okhttp3.Request;
import com.jiang.android.architecture.okhttp.Param;
import com.jiang.android.architecture.okhttp.utils.HeaderUtils;
import com.jiang.android.architecture.okhttp.utils.HttpUtils;

/**
 * created by jiang, 15/10/19
 * Copyright (c) 2015, jyuesong@gmail.com All Rights Reserved.
 * *                #                                                   #
 * #                       _oo0oo_                     #
 * #                      o8888888o                    #
 * #                      88" . "88                    #
 * #                      (| -_- |)                    #
 * #                      0\  =  /0                    #
 * #                    ___/`---'\___                  #
 * #                  .' \\|     |# '.                 #
 * #                 / \\|||  :  |||# \                #
 * #                / _||||| -:- |||||- \              #
 * #               |   | \\\  -  #/ |   |              #
 * #               | \_|  ''\---/''  |_/ |             #
 * #               \  .-\__  '-'  ___/-. /             #
 * #             ___'. .'  /--.--\  `. .'___           #
 * #          ."" '<  `.___\_<|>_/___.' >' "".         #
 * #         | | :  `- \`.;`\ _ /`;.`/ - ` : | |       #
 * #         \  \ `_.   \_ __\ /__ _/   .-` /  /       #
 * #     =====`-.____`.___ \_____/___.-`___.-'=====    #
 * #                       `=---='                     #
 * #     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   #
 * #                                                   #
 * #               佛祖保佑         永无BUG              #
 * #                                                   #
 */
package com.jiang.android.architecture.okhttp.request;




/**
 * 生成get请求需要的request
 * Created by jiang on 15/10/16.
 */
public class getRequest  {

    public static Request buildGetRequest(String url, Map<String, String> params, Object tag, Map<String, String> headers) {
        Request.Builder builder = new Request.Builder();

        List<Param> valdatedHeaders = HeaderUtils.validateHeaders(headers);
        if (valdatedHeaders != null && valdatedHeaders.size() != 0) {
            for (int i = 0; i < valdatedHeaders.size(); i++) {
                Param param = valdatedHeaders.get(i);
                String key = param.key;
                String value = param.value;
                builder.addHeader(key, value);
            }

        }

        if (params != null && params.size() != 0) {
            String par = HttpUtils.parseParams2String(params);