// Path: src/main/java/com/github/kaklakariada/fritzbox/FritzBoxException.java
// public class FritzBoxException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     public FritzBoxException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public FritzBoxException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/com/github/kaklakariada/fritzbox/mapping/Deserializer.java
// public class Deserializer {
//     private static final Logger LOG = LoggerFactory.getLogger(Deserializer.class);
// 
//     private final Serializer xmlSerializer;
// 
//     public Deserializer() {
//         this(new Persister());
//     }
// 
//     Deserializer(Serializer xmlSerializer) {
//         this.xmlSerializer = xmlSerializer;
//     }
// 
//     public <T> T parse(String data, Class<T> resultType) {
//         if (resultType == String.class) {
//             return resultType.cast(data);
//         }
//         if (resultType == Boolean.class) {
//             return resultType.cast("1".equals(data));
//         }
//         if (resultType == Integer.class) {
//             if (data.isEmpty() || "inval".equals(data)) {
//                 return null;
//             }
//             return resultType.cast(Integer.parseInt(data));
//         }
//         try {
//             final T object = xmlSerializer.read(resultType, data);
//             LOG.trace("Parsed response: {}", object);
//             return object;
//         } catch (final Exception e) {
//             throw new DeserializerException("Error parsing response body '" + data + "'", e);
//         }
//     }
// }


import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import java.io.IOException;
import java.util.Map.Entry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.kaklakariada.fritzbox.FritzBoxException;
import com.github.kaklakariada.fritzbox.mapping.Deserializer;
import okhttp3.HttpUrl;
import okhttp3.HttpUrl.Builder;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
    public <T> T get(String path, Class<T> resultType) {
        return get(path, QueryParameters.builder().build(), resultType);
    }

    public <T> T get(String path, QueryParameters parameters, Class<T> resultType) {
        final HttpUrl url = createUrl(path, parameters);
        return get(resultType, url);
    }

    public <T> T post(String path, QueryParameters parameters, Class<T> resultType) {
        final HttpUrl url = createUrl(path, parameters);
        return post(resultType, url);
    }

    private <T> T get(Class<T> resultType, HttpUrl url) {
        final Request request = new Request.Builder().url(url).get().build();
        final Response response = execute(request);
        return parse(response, resultType);
    }

    private <T> T post(Class<T> resultType, HttpUrl url) {
        final MediaType mediaType = MediaType.parse("application/xml");
        final RequestBody emptyBody = RequestBody.create(new byte[0], mediaType);
        final Request request = new Request.Builder().url(url).post(emptyBody).build();
        final Response response = execute(request);
        return parse(response, resultType);
    }

    private <T> T parse(final Response response, Class<T> resultType) {
        if (!response.isSuccessful()) {
// Path: src/main/java/com/github/kaklakariada/fritzbox/FritzBoxException.java
// public class FritzBoxException extends RuntimeException {
// 
//     private static final long serialVersionUID = 1L;
// 
//     public FritzBoxException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public FritzBoxException(String message) {
//         super(message);
//     }
// }
// 
// Path: src/main/java/com/github/kaklakariada/fritzbox/mapping/Deserializer.java
// public class Deserializer {
//     private static final Logger LOG = LoggerFactory.getLogger(Deserializer.class);
// 
//     private final Serializer xmlSerializer;
// 
//     public Deserializer() {
//         this(new Persister());
//     }
// 
//     Deserializer(Serializer xmlSerializer) {
//         this.xmlSerializer = xmlSerializer;
//     }
// 
//     public <T> T parse(String data, Class<T> resultType) {
//         if (resultType == String.class) {
//             return resultType.cast(data);
//         }
//         if (resultType == Boolean.class) {
//             return resultType.cast("1".equals(data));
//         }
//         if (resultType == Integer.class) {
//             if (data.isEmpty() || "inval".equals(data)) {
//                 return null;
//             }
//             return resultType.cast(Integer.parseInt(data));
//         }
//         try {
//             final T object = xmlSerializer.read(resultType, data);
//             LOG.trace("Parsed response: {}", object);
//             return object;
//         } catch (final Exception e) {
//             throw new DeserializerException("Error parsing response body '" + data + "'", e);
//         }
//     }
// }


// Path: src/main/java/com/github/kaklakariada/fritzbox/http/HttpTemplate.java
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import java.io.IOException;
import java.util.Map.Entry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.kaklakariada.fritzbox.FritzBoxException;
import com.github.kaklakariada.fritzbox.mapping.Deserializer;
import okhttp3.HttpUrl;
import okhttp3.HttpUrl.Builder;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;

    public <T> T get(String path, Class<T> resultType) {
        return get(path, QueryParameters.builder().build(), resultType);
    }

    public <T> T get(String path, QueryParameters parameters, Class<T> resultType) {
        final HttpUrl url = createUrl(path, parameters);
        return get(resultType, url);
    }

    public <T> T post(String path, QueryParameters parameters, Class<T> resultType) {
        final HttpUrl url = createUrl(path, parameters);
        return post(resultType, url);
    }

    private <T> T get(Class<T> resultType, HttpUrl url) {
        final Request request = new Request.Builder().url(url).get().build();
        final Response response = execute(request);
        return parse(response, resultType);
    }

    private <T> T post(Class<T> resultType, HttpUrl url) {
        final MediaType mediaType = MediaType.parse("application/xml");
        final RequestBody emptyBody = RequestBody.create(new byte[0], mediaType);
        final Request request = new Request.Builder().url(url).post(emptyBody).build();
        final Response response = execute(request);
        return parse(response, resultType);
    }

    private <T> T parse(final Response response, Class<T> resultType) {
        if (!response.isSuccessful()) {
            throw new FritzBoxException("Request failed: " + response);