From 3c1cbaa769c9fafa7b5f1bd6dd07f46bc262b19d Mon Sep 17 00:00:00 2001 From: Jacob Laursen Date: Fri, 2 Jun 2023 12:29:42 +0200 Subject: [PATCH] [surepetcare] Adapt blocked user agent (#15047) * Adapt blocked user agent Fixes #15046 Signed-off-by: Jacob Laursen --- .../surepetcare/internal/SurePetcareAPIHelper.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/SurePetcareAPIHelper.java b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/SurePetcareAPIHelper.java index 9328713d8d8..e9a1747384e 100644 --- a/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/SurePetcareAPIHelper.java +++ b/bundles/org.openhab.binding.surepetcare/src/main/java/org/openhab/binding/surepetcare/internal/SurePetcareAPIHelper.java @@ -63,8 +63,6 @@ public class SurePetcareAPIHelper { private final Logger logger = LoggerFactory.getLogger(SurePetcareAPIHelper.class); - private static final String API_USER_AGENT = "Mozilla/5.0 (Linux; Android 7.0; SM-G930F Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/64.0.3282.137 Mobile Safari/537.36"; - private static final String API_URL = "https://app.api.surehub.io/api"; private static final String TOPOLOGY_URL = API_URL + "/me/start"; private static final String PET_BASE_URL = API_URL + "/pet"; @@ -78,9 +76,15 @@ public class SurePetcareAPIHelper { private String username = ""; private String password = ""; + private final String userAgent; + private @NonNullByDefault({}) HttpClient httpClient; private SurePetcareTopology topologyCache = new SurePetcareTopology(); + public SurePetcareAPIHelper() { + userAgent = "openHAB/" + org.openhab.core.OpenHAB.getVersion(); + } + /** * Sets the httpClient object to be used for API calls to Sure Petcare. * @@ -369,7 +373,7 @@ public class SurePetcareAPIHelper { request.header(HttpHeader.AUTHORIZATION, "Bearer " + authenticationToken); request.header(HttpHeader.CONNECTION, "keep-alive"); request.header(HttpHeader.CONTENT_TYPE, "application/json; utf-8"); - request.header(HttpHeader.USER_AGENT, API_USER_AGENT); + request.header(HttpHeader.USER_AGENT, userAgent); request.header(HttpHeader.REFERER, "https://surepetcare.io/"); request.header("Origin", "https://surepetcare.io"); request.header("Referer", "https://surepetcare.io");