// Path: src/main/java/com/stackify/api/common/ApiConfiguration.java
// @ToString
// @Getter
// @Builder(builderClassName = "Builder", toBuilder = true, builderMethodName = "newBuilder")
// public class ApiConfiguration {
// 
//     public static final String TRANSPORT_DIRECT = "direct";
//     public static final String TRANSPORT_AGENT_SOCKET = "agent_socket";
// 
//     private static final String DEFAULT_TRANSPORT = TRANSPORT_DIRECT;
//     private static final String DEFAULT_AGENT_SOCKET_PATH_UNIX = "/usr/local/stackify/stackify.sock";
// 
//     /**
//      * Default API URL
//      */
//     private static final String DEFAULT_API_URL = "https://api.stackify.com";
// 
//     /**
//      * API URL
//      */
//     private final String apiUrl;
// 
//     /**
//      * API Key
//      */
//     private final String apiKey;
// 
//     /**
//      * Application name
//      */
//     private final String application;
// 
//     /**
//      * Environment
//      */
//     private final String environment;
// 
//     /**
//      * Environment details
//      */
//     private final EnvironmentDetail envDetail;
// 
//     /**
//      * Add #SKIPJSON tag to messages containing Json
//      */
//     private final Boolean skipJson;
// 
//     /**
//      * Allow logging from com.stackify.*
//      */
//     private final Boolean allowComDotStackify;
// 
//     /**
//      * Http Proxy Host ie) 10.20.30.40
//      */
//     private final String httpProxyHost;
// 
//     /**
//      * Http Proxy Port ie) 8080
//      */
//     private final String httpProxyPort;
// 
//     private final String transport;
// 
//     /**
//      * @return the apiUrl
//      */
//     public String getApiUrl() {
//         return apiUrl != null ? apiUrl : DEFAULT_API_URL;
//     }
// 
//     public String getTransport() {
//         return transport != null ? transport : DEFAULT_TRANSPORT;
//     }
// 
//     public String getAgentSocketPath() {
//         return DEFAULT_AGENT_SOCKET_PATH_UNIX;
//     }
// }
// 
// Path: src/main/java/com/stackify/api/common/util/CharStreams.java
// public class CharStreams {
// 
// 	/**
// 	 * Read char stream to a string
// 	 * @param r Readable
// 	 * @return String
// 	 * @throws IOException
// 	 */
// 	public static String toString(final Readable r) throws IOException {
// 		Preconditions.checkNotNull(r);
// 		
// 	    StringBuilder sb = new StringBuilder();
// 
// 	    CharBuffer buf = CharBuffer.allocate(0x800);
// 
// 	    while (r.read(buf) != -1) {
// 	    	buf.flip();
// 	    	sb.append(buf);
// 	    	buf.clear();
// 	    }
// 	    
// 	    return sb.toString();
// 	}
// 
// 	/**
// 	 * Hidden to prevent construction
// 	 */
// 	private CharStreams() {
// 	}
// }
// 
// Path: src/main/java/com/stackify/api/common/util/Preconditions.java
// public class Preconditions {
// 
// 	/**
// 	 * Throws NullPointerException if the argument is null
// 	 * @param o The object to check
// 	 * @throws NullPointerException
// 	 */
// 	public static void checkNotNull(final Object o) {
// 		if (o == null) {
// 			throw new NullPointerException();
// 		}
// 	}
// 	
// 	/**
// 	 * Throws IllegalArgumentException if the expression is false
// 	 * @param expression The expression
// 	 * @throws IllegalArgumentException
// 	 */
// 	public static void checkArgument(final boolean expression) {
// 		if (!expression) {
// 			throw new IllegalArgumentException();
// 		}
// 	}
// 	
// 	/**
// 	 * Hidden to prevent construction
// 	 */
// 	private Preconditions() {
// 	}
// }


import com.stackify.api.common.ApiConfiguration;
import com.stackify.api.common.util.CharStreams;
import com.stackify.api.common.util.Preconditions;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL;
import java.util.zip.GZIPOutputStream;
/*
 * Copyright 2014 Stackify
 *
 * 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.stackify.api.common.http;



/**
 * HttpClient
 * @author Eric Martin
 */
public class HttpClient {

	/**
	 * CONNECT_TIMEOUT
	 */
	private static final int CONNECT_TIMEOUT = 5000;

	/**
	 * READ_TIMEOUT
	 */
	private static final int READ_TIMEOUT = 15000;

	/**
	 * API configuration
	 */
	private final ApiConfiguration apiConfig;

	/**
	 * HTTP proxy
	 */
	private final Proxy proxy;

	/**
	 * Constructor
	 * @param apiConfig API configuration
	 */
    public HttpClient(final ApiConfiguration apiConfig) {
// Path: src/main/java/com/stackify/api/common/ApiConfiguration.java
// @ToString
// @Getter
// @Builder(builderClassName = "Builder", toBuilder = true, builderMethodName = "newBuilder")
// public class ApiConfiguration {
// 
//     public static final String TRANSPORT_DIRECT = "direct";
//     public static final String TRANSPORT_AGENT_SOCKET = "agent_socket";
// 
//     private static final String DEFAULT_TRANSPORT = TRANSPORT_DIRECT;
//     private static final String DEFAULT_AGENT_SOCKET_PATH_UNIX = "/usr/local/stackify/stackify.sock";
// 
//     /**
//      * Default API URL
//      */
//     private static final String DEFAULT_API_URL = "https://api.stackify.com";
// 
//     /**
//      * API URL
//      */
//     private final String apiUrl;
// 
//     /**
//      * API Key
//      */
//     private final String apiKey;
// 
//     /**
//      * Application name
//      */
//     private final String application;
// 
//     /**
//      * Environment
//      */
//     private final String environment;
// 
//     /**
//      * Environment details
//      */
//     private final EnvironmentDetail envDetail;
// 
//     /**
//      * Add #SKIPJSON tag to messages containing Json
//      */
//     private final Boolean skipJson;
// 
//     /**
//      * Allow logging from com.stackify.*
//      */
//     private final Boolean allowComDotStackify;
// 
//     /**
//      * Http Proxy Host ie) 10.20.30.40
//      */
//     private final String httpProxyHost;
// 
//     /**
//      * Http Proxy Port ie) 8080
//      */
//     private final String httpProxyPort;
// 
//     private final String transport;
// 
//     /**
//      * @return the apiUrl
//      */
//     public String getApiUrl() {
//         return apiUrl != null ? apiUrl : DEFAULT_API_URL;
//     }
// 
//     public String getTransport() {
//         return transport != null ? transport : DEFAULT_TRANSPORT;
//     }
// 
//     public String getAgentSocketPath() {
//         return DEFAULT_AGENT_SOCKET_PATH_UNIX;
//     }
// }
// 
// Path: src/main/java/com/stackify/api/common/util/CharStreams.java
// public class CharStreams {
// 
// 	/**
// 	 * Read char stream to a string
// 	 * @param r Readable
// 	 * @return String
// 	 * @throws IOException
// 	 */
// 	public static String toString(final Readable r) throws IOException {
// 		Preconditions.checkNotNull(r);
// 		
// 	    StringBuilder sb = new StringBuilder();
// 
// 	    CharBuffer buf = CharBuffer.allocate(0x800);
// 
// 	    while (r.read(buf) != -1) {
// 	    	buf.flip();
// 	    	sb.append(buf);
// 	    	buf.clear();
// 	    }
// 	    
// 	    return sb.toString();
// 	}
// 
// 	/**
// 	 * Hidden to prevent construction
// 	 */
// 	private CharStreams() {
// 	}
// }
// 
// Path: src/main/java/com/stackify/api/common/util/Preconditions.java
// public class Preconditions {
// 
// 	/**
// 	 * Throws NullPointerException if the argument is null
// 	 * @param o The object to check
// 	 * @throws NullPointerException
// 	 */
// 	public static void checkNotNull(final Object o) {
// 		if (o == null) {
// 			throw new NullPointerException();
// 		}
// 	}
// 	
// 	/**
// 	 * Throws IllegalArgumentException if the expression is false
// 	 * @param expression The expression
// 	 * @throws IllegalArgumentException
// 	 */
// 	public static void checkArgument(final boolean expression) {
// 		if (!expression) {
// 			throw new IllegalArgumentException();
// 		}
// 	}
// 	
// 	/**
// 	 * Hidden to prevent construction
// 	 */
// 	private Preconditions() {
// 	}
// }


// Path: src/main/java/com/stackify/api/common/http/HttpClient.java
import com.stackify.api.common.ApiConfiguration;
import com.stackify.api.common.util.CharStreams;
import com.stackify.api.common.util.Preconditions;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL;
import java.util.zip.GZIPOutputStream;

/*
 * Copyright 2014 Stackify
 *
 * 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.stackify.api.common.http;



/**
 * HttpClient
 * @author Eric Martin
 */
public class HttpClient {

	/**
	 * CONNECT_TIMEOUT
	 */
	private static final int CONNECT_TIMEOUT = 5000;

	/**
	 * READ_TIMEOUT
	 */
	private static final int READ_TIMEOUT = 15000;

	/**
	 * API configuration
	 */
	private final ApiConfiguration apiConfig;

	/**
	 * HTTP proxy
	 */
	private final Proxy proxy;

	/**
	 * Constructor
	 * @param apiConfig API configuration
	 */
    public HttpClient(final ApiConfiguration apiConfig) {
        Preconditions.checkNotNull(apiConfig);