]> git.basschouten.com Git - openhab-addons.git/blob
e3ce89cff85b707cc7c2db235e43538e361fda9c
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.freebox.internal.api.model;
14
15 import org.openhab.binding.freebox.internal.api.FreeboxException;
16
17 /**
18  * The {@link FreeboxResponse} is the Java class used to map the "APIResponse"
19  * structure used by the API
20  * https://dev.freebox.fr/sdk/os/#
21  *
22  * @author Laurent Garnier - Initial contribution
23  */
24 public class FreeboxResponse<T> {
25     private static final String AUTHORIZATION_REQUIRED = "auth_required";
26     private static final String INSUFFICIENT_RIGHTS = "insufficient_rights";
27
28     private Boolean success;
29     private String errorCode;
30     private String uid;
31     private String msg;
32     private String missingRight;
33     private T result;
34
35     public void evaluate() throws FreeboxException {
36         if (!isSuccess()) {
37             throw new FreeboxException(this);
38         }
39     }
40
41     public boolean isAuthRequired() {
42         return AUTHORIZATION_REQUIRED.equalsIgnoreCase(errorCode);
43     }
44
45     public boolean isMissingRights() {
46         return INSUFFICIENT_RIGHTS.equalsIgnoreCase(errorCode);
47     }
48
49     public Boolean isSuccess() {
50         return success;
51     }
52
53     public String getErrorCode() {
54         return errorCode;
55     }
56
57     public String getUid() {
58         return uid;
59     }
60
61     public String getMsg() {
62         return msg;
63     }
64
65     public String getMissingRight() {
66         return missingRight;
67     }
68
69     public T getResult() {
70         return result;
71     }
72 }