// Path: src/io/andrewohara/tinkertime/io/crawlers/pageLoaders/PageLoader.java
// public abstract class PageLoader<T> {
// 
// 	public static final int CACHING_EXIPIRY_MINUTES = 1;
// 	private final LoadingCache<URL, T> cache;
// 
// 	public PageLoader(){
// 		System.setProperty("http.agent", "TinkerTime Mod Manager Agent");
// 		cache = CacheBuilder.newBuilder()
// 				.expireAfterAccess(CACHING_EXIPIRY_MINUTES, TimeUnit.MINUTES)
// 				.build(
// 						new CacheLoader<URL, T>() {
// 							@Override
// 							public T load(URL url) throws IOException {
// 								return loadPage(url);
// 							}
// 						});
// 	}
// 
// 	protected abstract T loadPage(URL url) throws IOException;
// 
// 	public T getPage(URL url) throws IOException {
// 		try {
// 			return cache.get(url);
// 		} catch (ExecutionException e) {
// 			throw new IOException(e);
// 		}
// 	}
// }


import io.andrewohara.tinkertime.io.crawlers.pageLoaders.PageLoader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
package io.andrewohara.tinkertime.io.crawlers;




public class KerbalStuffCrawler extends Crawler<JsonElement>{

	private static Pattern ID_PATTERN = Pattern.compile("(mod/)(\\d+)(/*)");
	private URL cachedApiUrl = null;

	public KerbalStuffCrawler(URL url, PageLoader<JsonElement> pageLoader) {
		super(url, pageLoader);
	}

	@Override
	protected URL getApiUrl() throws MalformedURLException {
		if (cachedApiUrl == null){
			try {
				// Get Id from path
				Matcher m = ID_PATTERN.matcher(getPageUrl().getPath());
				if (!m.find()){
					throw new MalformedURLException();
				}

				// Construct API URL
				cachedApiUrl = new URL("https", CrawlerFactory.HOST_KERBAL_STUFF, String.format("/api/mod/%s", m.group(2)));
			} catch (IOException e) {
				throw new MalformedURLException(e.getMessage());
			}
		}
		return cachedApiUrl;
	}

	@Override
// Path: src/io/andrewohara/tinkertime/io/crawlers/pageLoaders/PageLoader.java
// public abstract class PageLoader<T> {
// 
// 	public static final int CACHING_EXIPIRY_MINUTES = 1;
// 	private final LoadingCache<URL, T> cache;
// 
// 	public PageLoader(){
// 		System.setProperty("http.agent", "TinkerTime Mod Manager Agent");
// 		cache = CacheBuilder.newBuilder()
// 				.expireAfterAccess(CACHING_EXIPIRY_MINUTES, TimeUnit.MINUTES)
// 				.build(
// 						new CacheLoader<URL, T>() {
// 							@Override
// 							public T load(URL url) throws IOException {
// 								return loadPage(url);
// 							}
// 						});
// 	}
// 
// 	protected abstract T loadPage(URL url) throws IOException;
// 
// 	public T getPage(URL url) throws IOException {
// 		try {
// 			return cache.get(url);
// 		} catch (ExecutionException e) {
// 			throw new IOException(e);
// 		}
// 	}
// }


// Path: src/io/andrewohara/tinkertime/io/crawlers/KerbalStuffCrawler.java
import io.andrewohara.tinkertime.io.crawlers.pageLoaders.PageLoader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collection;
import java.util.Date;
import java.util.LinkedList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

package io.andrewohara.tinkertime.io.crawlers;




public class KerbalStuffCrawler extends Crawler<JsonElement>{

	private static Pattern ID_PATTERN = Pattern.compile("(mod/)(\\d+)(/*)");
	private URL cachedApiUrl = null;

	public KerbalStuffCrawler(URL url, PageLoader<JsonElement> pageLoader) {
		super(url, pageLoader);
	}

	@Override
	protected URL getApiUrl() throws MalformedURLException {
		if (cachedApiUrl == null){
			try {
				// Get Id from path
				Matcher m = ID_PATTERN.matcher(getPageUrl().getPath());
				if (!m.find()){
					throw new MalformedURLException();
				}

				// Construct API URL
				cachedApiUrl = new URL("https", CrawlerFactory.HOST_KERBAL_STUFF, String.format("/api/mod/%s", m.group(2)));
			} catch (IOException e) {
				throw new MalformedURLException(e.getMessage());
			}
		}
		return cachedApiUrl;
	}

	@Override
	public String getName() throws IOException {