<commit_before>package com.github.norwae.whatiread.googlebooks;

import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;

import android.util.Log;

import com.github.norwae.whatiread.data.BookInfo;
import com.github.norwae.whatiread.data.ISBN13;

public class GoogleBooksISBNRequest {
	
	private static final String QUERY_TEMPLATE = "https://www.googleapis.com/books/v1/volumes?q=isbn:$ISBN&key=$KEY&country=$COUNTRY&projection=lite";

	private final String key;
	private final String code;
	private final Locale locale;

	public GoogleBooksISBNRequest(ISBN13 isbn, String key, Locale locale) {
		this.key = key;
		this.code = isbn.toString();
		this.locale = locale;
		
	}

	public BookInfo execute() {
		URL serviceURL;
		try {
			serviceURL = composeServiceURL();
			

			Log.i("google-books-api", "preparing to call: " + serviceURL);			
			HttpURLConnection connection = (HttpURLConnection) serviceURL.openConnection();
			if (HttpURLConnection.HTTP_OK != connection.getResponseCode()) {
				Log.i("google-books-api", "API rejected call with code " + connection.getResponseCode() + " <" + connection.getResponseMessage() + ">");
			}
			
			GoogleBooksJSONParser parser = new GoogleBooksJSONParser(connection.getInputStream(), code);
			
			GoogleBooksAPIResult result = parser.parse();
			
			if (!result.getBookInfos().isEmpty()) {
				return result.getBookInfos().get(0);
			}
		} catch (Exception e) {
			Log.e("google-books-api", "failed to call", e);
		}
		
		return null;
	}

	private URL composeServiceURL() throws MalformedURLException {
		String url = QUERY_TEMPLATE.replace("$ISBN", code).replace("$KEY", key).replace("$COUNTRY", locale.getCountry());<commit_msg>Fixed error detection / reporting<commit_after>package com.github.norwae.whatiread.googlebooks;

import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Locale;

import android.util.Log;

import com.github.norwae.whatiread.data.BookInfo;
import com.github.norwae.whatiread.data.ISBN13;

public class GoogleBooksISBNRequest {
	
	private static final String QUERY_TEMPLATE = "https://www.googleapis.com/books/v1/volumes?q=isbn:$ISBN&key=$KEY&country=$COUNTRY&projection=lite";

	private final String key;
	private final String code;
	private final Locale locale;

	public GoogleBooksISBNRequest(ISBN13 isbn, String key, Locale locale) {
		this.key = key;
		this.code = isbn.toString();
		this.locale = locale;
		
	}

	public BookInfo execute() {
		URL serviceURL;
		try {
			serviceURL = composeServiceURL();
			

			Log.i("google-books-api", "preparing to call: " + serviceURL);			
			HttpURLConnection connection = (HttpURLConnection) serviceURL.openConnection();
			if (HttpURLConnection.HTTP_OK == connection.getResponseCode()) {
				GoogleBooksJSONParser parser = new GoogleBooksJSONParser(connection.getInputStream(), code);
				
				GoogleBooksAPIResult result = parser.parse();
				
				if (!result.getBookInfos().isEmpty()) {
					return result.getBookInfos().get(0);
				}	
			} else {
				Log.i("google-books-api", "API rejected call with code " + connection.getResponseCode() + " <" + connection.getResponseMessage() + ">");
			}
		} catch (Exception e) {
			Log.e("google-books-api", "failed to call", e);
		}
		
		return null;
	}

	private URL composeServiceURL() throws MalformedURLException {
		String url = QUERY_TEMPLATE.replace("$ISBN", code).replace("$KEY", key).replace("$COUNTRY", locale.getCountry());
{'fraction_non_alphanumeric': 0.12926136363636365, 'fraction_numerical': 0.003409090909090909, 'mean_word_length': 4.642628205128205, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3404345', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1079, 'n_words': 225}