// Path: CoolHttp/app/src/main/java/com/yanzhenjie/coolhttp/http/execute/HttpExecutor.java
// public interface HttpExecutor {
// 
//     HttpURLConnection openUrl(URL url, Proxy proxy) throws IOException;
// 
// }
// 
// Path: CoolHttp/app/src/main/java/com/yanzhenjie/coolhttp/http/execute/OkHttpExecutor.java
// public class OkHttpExecutor implements HttpExecutor {
// 
// 
//     private static OkHttpExecutor instance;
// 
//     public static HttpExecutor getInstance() {
//         if (instance == null)
//             synchronized (OkHttpExecutor.class) {
//                 if (instance == null)
//                     instance = new OkHttpExecutor();
//             }
//         return instance;
//     }
// 
//     private OkHttpClient okHttpClient;
// 
//     private OkHttpExecutor() {
//         okHttpClient = new OkHttpClient();
//     }
// 
//     @Override
//     public HttpURLConnection openUrl(URL url, Proxy proxy) throws IOException {
//         String protocol = url.getProtocol(); // http or https.
//         OkHttpClient copy = okHttpClient.newBuilder().proxy(proxy).build();
// 
//         if (protocol.equals("http")) return new OkHttpURLConnection(url, copy);
//         if (protocol.equals("https")) return new OkHttpsURLConnection(url, copy);
//         throw new IllegalArgumentException("Unexpected protocol: " + protocol);
//     }
// 
// }


import android.content.Context;
import com.yanzhenjie.coolhttp.http.execute.HttpExecutor;
import com.yanzhenjie.coolhttp.http.execute.OkHttpExecutor;
/*
 * Copyright © Yan Zhenjie. All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.yanzhenjie.coolhttp.http;



/**
 * Created by Yan Zhenjie on 2017/1/8.
 */
public class CoolHttp {


    /**
     * https://git.oschina.net/ysb/NoHttpUtil
     *
     * https://github.com/LiqiNew/NohttpRxUtils
     */

    private static Context sContext;
    private static HttpConfig sHttpConfig;

    public static void initialize(Context context) {
        initialize(context, new HttpConfig());
    }

    public static void initialize(Context context, HttpConfig httpConfig) {
        sContext = context;
        sHttpConfig = httpConfig;
    }

    private static void hasInitialize() {
        if (sContext == null)
            throw new ExceptionInInitializerError("Please invoke CoolHttp.initialize(Application) in Application#onCreate()");
    }

// Path: CoolHttp/app/src/main/java/com/yanzhenjie/coolhttp/http/execute/HttpExecutor.java
// public interface HttpExecutor {
// 
//     HttpURLConnection openUrl(URL url, Proxy proxy) throws IOException;
// 
// }
// 
// Path: CoolHttp/app/src/main/java/com/yanzhenjie/coolhttp/http/execute/OkHttpExecutor.java
// public class OkHttpExecutor implements HttpExecutor {
// 
// 
//     private static OkHttpExecutor instance;
// 
//     public static HttpExecutor getInstance() {
//         if (instance == null)
//             synchronized (OkHttpExecutor.class) {
//                 if (instance == null)
//                     instance = new OkHttpExecutor();
//             }
//         return instance;
//     }
// 
//     private OkHttpClient okHttpClient;
// 
//     private OkHttpExecutor() {
//         okHttpClient = new OkHttpClient();
//     }
// 
//     @Override
//     public HttpURLConnection openUrl(URL url, Proxy proxy) throws IOException {
//         String protocol = url.getProtocol(); // http or https.
//         OkHttpClient copy = okHttpClient.newBuilder().proxy(proxy).build();
// 
//         if (protocol.equals("http")) return new OkHttpURLConnection(url, copy);
//         if (protocol.equals("https")) return new OkHttpsURLConnection(url, copy);
//         throw new IllegalArgumentException("Unexpected protocol: " + protocol);
//     }
// 
// }


// Path: CoolHttp/app/src/main/java/com/yanzhenjie/coolhttp/http/CoolHttp.java
import android.content.Context;
import com.yanzhenjie.coolhttp.http.execute.HttpExecutor;
import com.yanzhenjie.coolhttp.http.execute.OkHttpExecutor;

/*
 * Copyright © Yan Zhenjie. All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.yanzhenjie.coolhttp.http;



/**
 * Created by Yan Zhenjie on 2017/1/8.
 */
public class CoolHttp {


    /**
     * https://git.oschina.net/ysb/NoHttpUtil
     *
     * https://github.com/LiqiNew/NohttpRxUtils
     */

    private static Context sContext;
    private static HttpConfig sHttpConfig;

    public static void initialize(Context context) {
        initialize(context, new HttpConfig());
    }

    public static void initialize(Context context, HttpConfig httpConfig) {
        sContext = context;
        sHttpConfig = httpConfig;
    }

    private static void hasInitialize() {
        if (sContext == null)
            throw new ExceptionInInitializerError("Please invoke CoolHttp.initialize(Application) in Application#onCreate()");
    }

    public static HttpExecutor getHttpExecutor() {