]> git.basschouten.com Git - openhab-addons.git/blob
5fb691009a9848172cc3632943f8625c38e86594
[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.vesync.internal.dto.requests;
14
15 import org.openhab.binding.vesync.internal.dto.responses.VeSyncUserSession;
16 import org.openhab.binding.vesync.internal.exceptions.AuthenticationException;
17
18 import com.google.gson.annotations.SerializedName;
19
20 /**
21  * The {@link VeSyncAuthenticatedRequest} is a Java class used as a DTO to hold the Vesync's API's common request data.
22  *
23  * @author David Goodyear - Initial contribution
24  */
25 public class VeSyncAuthenticatedRequest extends VeSyncRequest {
26
27     @SerializedName("accountID")
28     public String accountId;
29
30     @SerializedName("token")
31     public String token;
32
33     public VeSyncAuthenticatedRequest() {
34         super();
35     }
36
37     public VeSyncAuthenticatedRequest(final VeSyncUserSession user) throws AuthenticationException {
38         super();
39         if (user == null) {
40             throw new AuthenticationException("User is not logged in");
41         }
42         this.token = user.getToken();
43         this.accountId = user.getAccountId();
44     }
45
46     public void applyAuthentication(final VeSyncUserSession userSession) throws AuthenticationException {
47         if (userSession == null) {
48             throw new AuthenticationException("User is not logged in");
49         }
50         this.accountId = userSession.getAccountId();
51         this.token = userSession.getToken();
52     }
53 }