package im.nll.data.fluent;

import org.apache.http.HttpHost;
import org.apache.http.client.fluent.Executor;
import org.apache.http.client.fluent.Request;
import org.apache.http.client.fluent.Response;

import java.io.IOException;

/**
 * @author <a href="mailto:fivesmallq@gmail.com">fivesmallq</a>
 * @version Revision: 1.0
 * @date 16/4/11 下午7:13
 */
public class Proxies {
    private Proxy proxy;
    private Executor executor = Executor.newInstance();

    public Proxies(Proxy proxy) {
        this.proxy = proxy;
    }

    /**
     * create proxies instance with proxy.
     *
     * @param proxy
     * @return
     */
    public static Proxies of(Proxy proxy) {
        return new Proxies(proxy);
    }

    /**
     * create proxies instance with proxy string.
     *
     * @param proxy
     * @return
     */
    public static Proxies of(String proxy) {
        return new Proxies(Proxy.parse(proxy));
    }

    public Proxies executor(Executor executor) {
        this.executor = executor;
        return this;
    }

    /**
     * execute request use default proxy
     *
     * @param request
     * @return
     * @throws IOException
     */
    public Response execute(Request request) throws IOException {
        return execute(proxy, request);
    }

    public Response execute(String proxy, Request request) throws IOException {
        Proxy p = Proxy.parse(proxy);
        return execute(p, request);
    }

    public Response execute(Proxy proxy, Request request) throws IOException {
        HttpHost httpHost = proxy.getHttpHost();
        executor.auth(httpHost, proxy.getUsername(), proxy.getPassword());
        executor.authPreemptiveProxy(httpHost);
        request.viaProxy(httpHost);
        return executor.execute(request);
    }


}

@@ -223,16 +223,64 @@
 ception;
+%0Aimport java.util.Arrays;%0Aimport java.util.List;
 %0A%0A/**%0A *
@@ -430,27 +430,35 @@
 private 
+List%3C
 Proxy
+%3E
  prox
-y
+ies
 ;%0A    pr
@@ -506,16 +506,57 @@
 tance();
+%0A    private ProxySelector proxySelector;
 %0A%0A    pu
@@ -569,30 +569,35 @@
 roxies(Proxy
+...
  prox
-y
+ies
 ) %7B%0A        
@@ -609,17 +609,36 @@
 prox
-y = proxy
+ies = Arrays.asList(proxies)
 ;%0A  
@@ -660,32 +660,24 @@
    * create 
-proxies 
 instance wit
@@ -682,17 +682,19 @@
 ith prox
-y
+ies
 .%0A     *
@@ -704,33 +704,35 @@
    * @param prox
-y
+ies
 %0A     * @return%0A
@@ -773,22 +773,27 @@
 of(Proxy
+...
  prox
-y
+ies
 ) %7B%0A    
@@ -815,25 +815,27 @@
 Proxies(prox
-y
+ies
 );%0A    %7D%0A%0A  
@@ -1373,16 +1373,40 @@
 te(proxy
+Selector.select(request)
 , reques

add maven pom