cesium-native 0.44.2
Loading...
Searching...
No Matches
Connection.h
1#pragma once
2
3#include <CesiumAsync/AsyncSystem.h>
4#include <CesiumAsync/IAssetAccessor.h>
5#include <CesiumAsync/Library.h>
6#include <CesiumIonClient/ApplicationData.h>
7#include <CesiumIonClient/Assets.h>
8#include <CesiumIonClient/Defaults.h>
9#include <CesiumIonClient/Geocoder.h>
10#include <CesiumIonClient/Profile.h>
11#include <CesiumIonClient/Response.h>
12#include <CesiumIonClient/Token.h>
13#include <CesiumIonClient/TokenList.h>
14
15#include <cstdint>
16
17namespace CesiumIonClient {
18
22enum class SortOrder { Ascending, Descending };
23
35 std::optional<int32_t> limit;
36
40 std::optional<int32_t> page;
41
47 std::optional<std::string> search;
48
53 std::optional<std::string> sortBy;
54
59 std::optional<SortOrder> sortOrder;
60};
61
66class CESIUMASYNC_API Connection {
67public:
101 const CesiumAsync::AsyncSystem& asyncSystem,
102 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
103 const std::string& friendlyApplicationName,
104 int64_t clientID,
105 const std::string& redirectPath,
106 const std::vector<std::string>& scopes,
107 std::function<void(const std::string&)>&& openUrlCallback,
109 const std::string& ionApiUrl = "https://api.cesium.com/",
110 const std::string& ionAuthorizeUrl = "https://ion.cesium.com/oauth");
111
122 const CesiumAsync::AsyncSystem& asyncSystem,
123 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
124 const std::string& apiUrl = "https://api.cesium.com");
125
143 const CesiumAsync::AsyncSystem& asyncSystem,
144 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
145 const std::string& ionUrl);
146
158 const CesiumAsync::AsyncSystem& asyncSystem,
159 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
160 const std::string& accessToken,
162 const std::string& apiUrl = "https://api.cesium.com");
163
167 const CesiumAsync::AsyncSystem& getAsyncSystem() const noexcept {
168 return this->_asyncSystem;
169 }
170
175 const std::shared_ptr<CesiumAsync::IAssetAccessor>&
176 getAssetAccessor() const noexcept {
177 return this->_pAssetAccessor;
178 }
179
183 const std::string& getAccessToken() const noexcept {
184 return this->_accessToken;
185 }
186
190 const std::string& getApiUrl() const noexcept { return this->_apiUrl; }
191
202
213
220
232 tokens(const ListTokensOptions& options = {}) const;
233
241
248 CesiumAsync::Future<Response<Token>> token(const std::string& tokenID) const;
249
261 nextPage(const Response<TokenList>& currentPage) const;
262
274 previousPage(const Response<TokenList>& currentPage) const;
275
288 const std::string& name,
289 const std::vector<std::string>& scopes,
290 const std::optional<std::vector<int64_t>>& assetIds = std::nullopt,
291 const std::optional<std::vector<std::string>>& allowedUrls =
292 std::nullopt) const;
293
308 const std::string& tokenID,
309 const std::string& newName,
310 const std::optional<std::vector<int64_t>>& newAssetIDs,
311 const std::vector<std::string>& newScopes,
312 const std::optional<std::vector<std::string>>& newAllowedUrls) const;
313
325 GeocoderProviderType provider,
327 const std::string& query);
328
336 static std::optional<std::string> getIdFromToken(const std::string& token);
337
338private:
339 static CesiumAsync::Future<Connection> completeTokenExchange(
340 const CesiumAsync::AsyncSystem& asyncSystem,
341 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
342 int64_t clientID,
343 const std::string& ionApiUrl,
345 const std::string& code,
346 const std::string& redirectUrl,
347 const std::string& codeVerifier);
348
349 CesiumAsync::Future<Response<TokenList>> tokens(const std::string& url) const;
350
351 CesiumAsync::AsyncSystem _asyncSystem;
352 std::shared_ptr<CesiumAsync::IAssetAccessor> _pAssetAccessor;
353 std::string _accessToken;
354 std::string _apiUrl;
356};
357} // namespace CesiumIonClient
A system for managing asynchronous requests and tasks.
Definition AsyncSystem.h:36
A value that will be available in the future, as produced by AsyncSystem.
Definition Promise.h:12
A connection to Cesium ion that can be used to interact with it via its REST API.
Definition Connection.h:66
CesiumAsync::Future< Response< TokenList > > tokens(const ListTokensOptions &options={}) const
Invokes the "List tokens" service to get the list of available tokens.
static CesiumAsync::Future< std::optional< std::string > > getApiUrl(const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const std::string &ionUrl)
Attempts to retrieve the ion endpoint URL by looking for a config.json file on the server.
static CesiumAsync::Future< Connection > authorize(const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const std::string &friendlyApplicationName, int64_t clientID, const std::string &redirectPath, const std::vector< std::string > &scopes, std::function< void(const std::string &)> &&openUrlCallback, const CesiumIonClient::ApplicationData &appData, const std::string &ionApiUrl="https://api.cesium.com/", const std::string &ionAuthorizeUrl="https://ion.cesium.com/oauth")
Authorizes access to Cesium ion on behalf of a user, and returns a Connection that can be used to int...
CesiumAsync::Future< Response< Profile > > me() const
Retrieves profile information for the access token currently being used to make API calls.
Connection(const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const std::string &accessToken, const CesiumIonClient::ApplicationData &appData, const std::string &apiUrl="https://api.cesium.com")
Creates a connection to Cesium ion using the provided access token.
CesiumAsync::Future< Response< GeocoderResult > > geocode(GeocoderProviderType provider, GeocoderRequestType type, const std::string &query)
Makes a request to the ion geocoding service.
const std::string & getApiUrl() const noexcept
Gets the Cesium ion API base URL.
Definition Connection.h:190
CesiumAsync::Future< Response< Defaults > > defaults() const
Retrieves default imagery, terrain and building assets along with quick add assets that can be useful...
CesiumAsync::Future< Response< NoValue > > modifyToken(const std::string &tokenID, const std::string &newName, const std::optional< std::vector< int64_t > > &newAssetIDs, const std::vector< std::string > &newScopes, const std::optional< std::vector< std::string > > &newAllowedUrls) const
Modifies a token.
CesiumAsync::Future< Response< TokenList > > nextPage(const Response< TokenList > &currentPage) const
Gets the next page of results from the "List tokens" service.
CesiumAsync::Future< Response< Assets > > assets() const
Gets the list of available assets.
const CesiumAsync::AsyncSystem & getAsyncSystem() const noexcept
Gets the async system used by this connection to do work in threads.
Definition Connection.h:167
static std::optional< std::string > getIdFromToken(const std::string &token)
Decodes a token ID from a token.
const std::string & getAccessToken() const noexcept
Gets the access token used by this connection.
Definition Connection.h:183
CesiumAsync::Future< Response< Token > > token(const std::string &tokenID) const
Gets details of the token with the given ID.
const std::shared_ptr< CesiumAsync::IAssetAccessor > & getAssetAccessor() const noexcept
Gets the interface used by this connection to interact with the Cesium ion REST API.
Definition Connection.h:176
CesiumAsync::Future< Response< TokenList > > previousPage(const Response< TokenList > &currentPage) const
Gets the previous page of results from the "List tokens" service.
CesiumAsync::Future< Response< Token > > createToken(const std::string &name, const std::vector< std::string > &scopes, const std::optional< std::vector< int64_t > > &assetIds=std::nullopt, const std::optional< std::vector< std::string > > &allowedUrls=std::nullopt) const
Creates a new token.
static CesiumAsync::Future< Response< ApplicationData > > appData(const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const std::string &apiUrl="https://api.cesium.com")
Retrieves information about the ion API server.
CesiumAsync::Future< Response< Asset > > asset(int64_t assetID) const
Gets details of the asset with the given ID.
Classes for working with Cesium ion clients.
GeocoderProviderType
The supported providers that can be accessed through ion's geocoder API.
Definition Geocoder.h:34
SortOrder
Whether sorted results should be ascending or descending.
Definition Connection.h:22
GeocoderRequestType
The supported types of requests to geocoding API.
Definition Geocoder.h:16
Data retrieved from the Cesium ion server via an "appData" request from Cesium ion....
Options to be passed to Connection::tokens.
Definition Connection.h:27
std::optional< std::string > search
One or more keywords separated by whitespace by which to filter the list of tokens....
Definition Connection.h:47
std::optional< int32_t > page
The page number, where the first page of results is page 1 (not 0).
Definition Connection.h:40
std::optional< std::string > sortBy
The property by which to sort results. Valid values are "NAME" and "LAST_USED".
Definition Connection.h:53
std::optional< int32_t > limit
The maximum number of tokens to return in a single page.
Definition Connection.h:35
std::optional< SortOrder > sortOrder
The property by which to sort results. Valid values are "NAME" and "LAST_USED".
Definition Connection.h:59
A response from Cesium ion.
Definition Response.h:19