Skip to content

Commit 60f7ef8

Browse files
Remove deprecated OlpClient functions (#1559)
Constructor should be used instead Relates-To: OCMAM-212 Signed-off-by: Andrey Kashcheev <[email protected]>
1 parent 4f07bae commit 60f7ef8

File tree

11 files changed

+216
-218
lines changed

11 files changed

+216
-218
lines changed

olp-cpp-sdk-authentication/src/AuthenticationClientUtils.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,7 @@ client::OlpClient CreateOlpClient(
275275
settings.retry_settings.max_attempts = 0;
276276
}
277277

278-
client::OlpClient client;
279-
client.SetBaseUrl(auth_settings.token_endpoint_url);
280-
client.SetSettings(std::move(settings));
278+
client::OlpClient client(settings, auth_settings.token_endpoint_url);
281279
return client;
282280
}
283281

olp-cpp-sdk-core/include/olp/core/client/OlpClient.h

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2023 HERE Europe B.V.
2+
* Copyright (C) 2019-2024 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -92,21 +92,6 @@ class CORE_API OlpClient {
9292
*/
9393
ParametersType& GetMutableDefaultHeaders();
9494

95-
/**
96-
* @brief Sets the client settings.
97-
*
98-
* @note Handle with care and do not change while requests are ongoing.
99-
* Ideally the settings would not change during the lifecycle of this
100-
* instance.
101-
*
102-
* @param settings The client settings.
103-
*
104-
* @deprecated This method will be removed by 05.2021. Please use the
105-
* constructor instead. The settings should not change during the lifetime of
106-
* the instance.
107-
*/
108-
void SetSettings(const OlpClientSettings& settings);
109-
11095
/**
11196
* @brief Getter function to retrieve client settings.
11297
*

olp-cpp-sdk-core/src/client/ApiLookupClientImpl.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2020-2022 HERE Europe B.V.
2+
* Copyright (C) 2020-2024 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -47,9 +47,7 @@ std::string FindApi(const Apis& apis, const std::string& service,
4747

4848
OlpClient CreateClient(const std::string& base_url,
4949
const OlpClientSettings& settings) {
50-
OlpClient client;
51-
client.SetBaseUrl(base_url);
52-
client.SetSettings(settings);
50+
OlpClient client(settings, base_url);
5351
return client;
5452
}
5553

@@ -227,20 +225,28 @@ CancellationToken ApiLookupClientImpl::LookupApi(
227225
OlpClient ApiLookupClientImpl::CreateAndCacheClient(
228226
const std::string& base_url, const std::string& cache_key,
229227
boost::optional<time_t> expiration) {
228+
const auto new_expiration =
229+
std::chrono::steady_clock::now() +
230+
std::chrono::seconds(expiration.value_or(kLookupApiDefaultExpiryTime));
231+
230232
std::lock_guard<std::mutex> lock(cached_clients_mutex_);
231-
ClientWithExpiration& client_with_expiration = cached_clients_[cache_key];
232233

233-
const auto current_base_url = client_with_expiration.client.GetBaseUrl();
234-
if (current_base_url.empty()) {
235-
client_with_expiration.client.SetSettings(settings_);
234+
auto findIt = cached_clients_.find(cache_key);
235+
if (findIt == cached_clients_.end()) {
236+
auto emplace_result = cached_clients_.emplace(
237+
cache_key,
238+
ClientWithExpiration{OlpClient(settings_, base_url), new_expiration});
239+
return emplace_result.first->second.client;
236240
}
241+
242+
ClientWithExpiration& client_with_expiration = findIt->second;
243+
const auto current_base_url = client_with_expiration.client.GetBaseUrl();
237244
if (current_base_url != base_url) {
238245
client_with_expiration.client.SetBaseUrl(base_url);
239246
}
240247

241-
client_with_expiration.expire_at =
242-
std::chrono::steady_clock::now() +
243-
std::chrono::seconds(expiration.value_or(kLookupApiDefaultExpiryTime));
248+
client_with_expiration.expire_at = new_expiration;
249+
244250
return client_with_expiration.client;
245251
}
246252

olp-cpp-sdk-core/src/client/OlpClient.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,6 @@ class OlpClient::OlpClientImpl {
466466
std::string GetBaseUrl() const;
467467

468468
ParametersType& GetMutableDefaultHeaders();
469-
void SetSettings(const OlpClientSettings& settings);
470469
const OlpClientSettings& GetSettings() const { return settings_; }
471470

472471
CancellationToken CallApi(const std::string& path, const std::string& method,
@@ -527,11 +526,6 @@ OlpClient::OlpClientImpl::GetMutableDefaultHeaders() {
527526
return default_headers_;
528527
}
529528

530-
void OlpClient::OlpClientImpl::SetSettings(const OlpClientSettings& settings) {
531-
// I would not expect that settings change during lifetime of the instance.
532-
settings_ = settings;
533-
}
534-
535529
boost::optional<client::ApiError> OlpClient::OlpClientImpl::AddBearer(
536530
bool query_empty, http::NetworkRequest& request,
537531
CancellationContext& context) const {
@@ -853,10 +847,6 @@ OlpClient::ParametersType& OlpClient::GetMutableDefaultHeaders() {
853847
return impl_->GetMutableDefaultHeaders();
854848
}
855849

856-
void OlpClient::SetSettings(const OlpClientSettings& settings) {
857-
impl_->SetSettings(settings);
858-
}
859-
860850
const OlpClientSettings& OlpClient::GetSettings() const {
861851
return impl_->GetSettings();
862852
}

olp-cpp-sdk-core/src/client/OlpClientFactory.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2021 HERE Europe B.V.
2+
* Copyright (C) 2019-2024 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,8 +27,8 @@ namespace client {
2727

2828
std::shared_ptr<OlpClient> OlpClientFactory::Create(
2929
const OlpClientSettings& settings) {
30-
auto olp_client = std::make_shared<OlpClient>();
31-
olp_client->SetSettings(settings);
30+
const auto kEmptyBaseUrl = std::string();
31+
auto olp_client = std::make_shared<OlpClient>(settings, kEmptyBaseUrl);
3232
return olp_client;
3333
}
3434

0 commit comments

Comments
 (0)