2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.freeboxos.internal.api.rest;
15 import javax.ws.rs.core.UriBuilder;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.eclipse.jdt.annotation.Nullable;
19 import org.openhab.binding.freeboxos.internal.api.FreeboxException;
20 import org.openhab.binding.freeboxos.internal.api.Response;
23 * The {@link ConfigurableRest} is the Java class used to handle portions of the Api that accept to get and set
24 * configuration based on a given DTO
26 * @author Gaƫl L'hopital - Initial contribution
29 public class ConfigurableRest<T, Y extends Response<T>> extends RestManager {
30 protected static final String CONFIG_PATH = "config";
32 private final Class<Y> responseClazz;
33 private final @Nullable String configPath;
35 protected ConfigurableRest(FreeboxOsSession session, LoginManager.Permission required, Class<Y> responseClazz,
36 UriBuilder uri, @Nullable String configPath) throws FreeboxException {
37 super(session, required, uri);
38 this.responseClazz = responseClazz;
39 this.configPath = configPath;
42 public T getConfig() throws FreeboxException {
43 return configPath != null ? getSingle(responseClazz, configPath) : getSingle(responseClazz);
46 protected T setConfig(T config) throws FreeboxException {
47 return configPath != null ? put(responseClazz, config, configPath) : put(responseClazz, config);