// Path: cdi/src/main/java/org/onsteroids/eve/api/InternalApiException.java
// public final class InternalApiException extends ApiException {
// 	private static final Logger LOG = LoggerFactory.getLogger(InternalApiException.class);
// 
// 	public InternalApiException(String message) {
// 		super(message);
// 	}
// 
// 	public InternalApiException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public InternalApiException(Throwable cause) {
// 		super(cause);
// 	}
// }


import com.eveonline.api.exceptions.ApiException;
import com.eveonline.api.img.CharacterPortrait;
import com.eveonline.api.img.CharacterPortraitApi;
import com.google.common.collect.Lists;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import org.onsteroids.eve.api.InternalApiException;
import org.onsteroids.eve.api.connector.http.ApiClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;
/**
 * Copyright 2010 Tobias Sarnowski
 *
 * 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 org.onsteroids.eve.api.provider.img;



/**
 * @author Tobias Sarnowski
 */
@Singleton
final class DefaultCharacterPortraitApi implements CharacterPortraitApi {
	private static final Logger LOG = LoggerFactory.getLogger(DefaultCharacterPortraitApi.class);

	private static final String FORMAT = "image/jpeg";

	private final Provider<HttpClient> httpClientProvider;
	private final URI serverUri;


	@Inject
	public DefaultCharacterPortraitApi(@ApiClient Provider<HttpClient> httpClientProvider) throws URISyntaxException {
		this.httpClientProvider = httpClientProvider;
		serverUri = new URI(CharacterPortraitApi.URL);
	}


	@Override
	public CharacterPortrait getCharacterPortrait(long characterId, PortraitSize size) throws ApiException {
		HttpClient httpClient = httpClientProvider.get();

		List<NameValuePair> qparams = Lists.newArrayList();
		qparams.add(new BasicNameValuePair("c", Long.toString(characterId)));
		qparams.add(new BasicNameValuePair("s", Integer.toString(size.getSize())));

		final URI requestURI;
		try {
			requestURI = URIUtils.createURI(
					serverUri.getScheme(),
					serverUri.getHost(),
					serverUri.getPort(),
					serverUri.getPath(),
					URLEncodedUtils.format(qparams, "UTF-8"),
					null
			);
		} catch (URISyntaxException e) {
// Path: cdi/src/main/java/org/onsteroids/eve/api/InternalApiException.java
// public final class InternalApiException extends ApiException {
// 	private static final Logger LOG = LoggerFactory.getLogger(InternalApiException.class);
// 
// 	public InternalApiException(String message) {
// 		super(message);
// 	}
// 
// 	public InternalApiException(String message, Throwable cause) {
// 		super(message, cause);
// 	}
// 
// 	public InternalApiException(Throwable cause) {
// 		super(cause);
// 	}
// }


// Path: cdi/src/main/java/org/onsteroids/eve/api/provider/img/DefaultCharacterPortraitApi.java
import com.eveonline.api.exceptions.ApiException;
import com.eveonline.api.img.CharacterPortrait;
import com.eveonline.api.img.CharacterPortraitApi;
import com.google.common.collect.Lists;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import org.onsteroids.eve.api.InternalApiException;
import org.onsteroids.eve.api.connector.http.ApiClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;

/**
 * Copyright 2010 Tobias Sarnowski
 *
 * 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 org.onsteroids.eve.api.provider.img;



/**
 * @author Tobias Sarnowski
 */
@Singleton
final class DefaultCharacterPortraitApi implements CharacterPortraitApi {
	private static final Logger LOG = LoggerFactory.getLogger(DefaultCharacterPortraitApi.class);

	private static final String FORMAT = "image/jpeg";

	private final Provider<HttpClient> httpClientProvider;
	private final URI serverUri;


	@Inject
	public DefaultCharacterPortraitApi(@ApiClient Provider<HttpClient> httpClientProvider) throws URISyntaxException {
		this.httpClientProvider = httpClientProvider;
		serverUri = new URI(CharacterPortraitApi.URL);
	}


	@Override
	public CharacterPortrait getCharacterPortrait(long characterId, PortraitSize size) throws ApiException {
		HttpClient httpClient = httpClientProvider.get();

		List<NameValuePair> qparams = Lists.newArrayList();
		qparams.add(new BasicNameValuePair("c", Long.toString(characterId)));
		qparams.add(new BasicNameValuePair("s", Integer.toString(size.getSize())));

		final URI requestURI;
		try {
			requestURI = URIUtils.createURI(
					serverUri.getScheme(),
					serverUri.getHost(),
					serverUri.getPort(),
					serverUri.getPath(),
					URLEncodedUtils.format(qparams, "UTF-8"),
					null
			);
		} catch (URISyntaxException e) {
			throw new InternalApiException(e);