]> git.basschouten.com Git - openhab-addons.git/blob
745bf37b6d5a87d675d0c6f0a331ab2f664c1de6
[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.ecovacs.internal.api.impl;
14
15 import org.eclipse.jdt.annotation.NonNullByDefault;
16 import org.openhab.binding.ecovacs.internal.api.EcovacsApiConfiguration;
17
18 /**
19  * @author Johannes Ptaszyk - Initial contribution
20  */
21 @NonNullByDefault
22 public final class EcovacsApiUrlFactory {
23
24     private EcovacsApiUrlFactory() {
25         // Prevent instantiation
26     }
27
28     private static final String MAIN_URL_LOGIN_PATH = "/user/login";
29
30     private static final String PORTAL_USERS_PATH = "/users/user.do";
31     private static final String PORTAL_IOT_PRODUCT_PATH = "/pim/product/getProductIotMap";
32     private static final String PORTAL_IOT_DEVMANAGER_PATH = "/iot/devmanager.do";
33     private static final String PORTAL_LOG_PATH = "/lg/log.do";
34
35     public static String getLoginUrl(EcovacsApiConfiguration config) {
36         return getMainUrl(config) + MAIN_URL_LOGIN_PATH;
37     }
38
39     public static String getAuthUrl(EcovacsApiConfiguration config) {
40         return String.format("https://gl-%1$s-openapi.ecovacs.%2$s/v1/global/auth/getAuthCode", config.getCountry(),
41                 getApiUrlTld(config));
42     }
43
44     public static String getPortalUsersUrl(EcovacsApiConfiguration config) {
45         return getPortalUrl(config) + PORTAL_USERS_PATH;
46     }
47
48     public static String getPortalProductIotMapUrl(EcovacsApiConfiguration config) {
49         return getPortalUrl(config) + PORTAL_IOT_PRODUCT_PATH;
50     }
51
52     public static String getPortalIotDeviceManagerUrl(EcovacsApiConfiguration config) {
53         return getPortalUrl(config) + PORTAL_IOT_DEVMANAGER_PATH;
54     }
55
56     public static String getPortalLogUrl(EcovacsApiConfiguration config) {
57         return getPortalUrl(config) + PORTAL_LOG_PATH;
58     }
59
60     private static String getPortalUrl(EcovacsApiConfiguration config) {
61         String continentSuffix = "cn".equalsIgnoreCase(config.getCountry()) ? "" : "-" + config.getContinent();
62         return String.format("https://portal%1$s.ecouser.net/api", continentSuffix);
63     }
64
65     private static String getMainUrl(EcovacsApiConfiguration config) {
66         return String.format("https://gl-%1$s-api.ecovacs.%2$s/v1/private/%1$s/%3$s/%4$s/%5$s/%6$s/%7$s/%8$s",
67                 config.getCountry(), getApiUrlTld(config), config.getLanguage(), config.getDeviceId(),
68                 config.getAppCode(), config.getAppVersion(), config.getChannel(), config.getDeviceType());
69     }
70
71     private static String getApiUrlTld(EcovacsApiConfiguration config) {
72         return "cn".equalsIgnoreCase(config.getCountry()) ? "cn" : "com";
73     }
74 }