|
1 | | -from typing import List, Optional |
| 1 | +import warnings |
2 | 2 |
|
3 | | -from openeo.capabilities import Capabilities |
4 | | -from openeo.internal.jupyter import render_component |
5 | | -from openeo.util import deep_get |
| 3 | +from openeo.internal.warnings import UserDeprecationWarning |
| 4 | +from openeo.rest.capabilities import OpenEoCapabilities |
6 | 5 |
|
| 6 | +warnings.warn( |
| 7 | + message="`RESTCapabilities` from `openeo.rest.rest_capabilities` is deprecated. Instead use `OpenEoCapabilities` from `openeo.rest.capabilities`.", |
| 8 | + category=UserDeprecationWarning, |
| 9 | + stacklevel=2, |
| 10 | +) |
7 | 11 |
|
8 | | -class RESTCapabilities(Capabilities): |
9 | | - """Represents REST capabilities of a connection / back end.""" |
| 12 | +__all__ = ["RESTCapabilities"] |
10 | 13 |
|
11 | | - def __init__(self, data: dict, url: str = None): |
12 | | - super(RESTCapabilities, self).__init__(data) |
13 | | - self.capabilities = data |
14 | | - self.url = url |
15 | | - |
16 | | - def get(self, key: str, default=None): |
17 | | - return self.capabilities.get(key, default) |
18 | | - |
19 | | - def deep_get(self, *keys, default=None): |
20 | | - return deep_get(self.capabilities, *keys, default=default) |
21 | | - |
22 | | - def api_version(self) -> str: |
23 | | - """ Get openEO version.""" |
24 | | - if 'api_version' in self.capabilities: |
25 | | - return self.capabilities.get('api_version') |
26 | | - else: |
27 | | - # Legacy/deprecated |
28 | | - return self.capabilities.get('version') |
29 | | - |
30 | | - def list_features(self): |
31 | | - """ List all supported features / endpoints.""" |
32 | | - return self.capabilities.get('endpoints') |
33 | | - |
34 | | - def has_features(self, method_name): |
35 | | - """ Check whether a feature / endpoint is supported.""" |
36 | | - # Field: endpoints > ... TODO |
37 | | - pass |
38 | | - |
39 | | - def supports_endpoint(self, path: str, method="GET"): |
40 | | - return any( |
41 | | - endpoint.get("path") == path and method.upper() in endpoint.get("methods", []) |
42 | | - for endpoint in self.capabilities.get("endpoints", []) |
43 | | - ) |
44 | | - |
45 | | - def currency(self) -> Optional[str]: |
46 | | - """Get default billing currency.""" |
47 | | - return self.deep_get("billing", "currency", default=None) |
48 | | - |
49 | | - def list_plans(self) -> List[dict]: |
50 | | - """List all billing plans.""" |
51 | | - return self.deep_get("billing", "plans", default=[]) |
52 | | - |
53 | | - def _repr_html_(self): |
54 | | - return render_component("capabilities", data = self.capabilities, parameters = {"url": self.url}) |
| 14 | +# Legacy alias |
| 15 | +RESTCapabilities = OpenEoCapabilities |
0 commit comments