hostinger-api 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (88) hide show
  1. hostinger_api/__init__.py +105 -0
  2. hostinger_api/api/__init__.py +21 -0
  3. hostinger_api/api/billing_catalog_api.py +282 -0
  4. hostinger_api/api/billing_orders_api.py +313 -0
  5. hostinger_api/api/billing_payment_methods_api.py +819 -0
  6. hostinger_api/api/billing_subscriptions_api.py +584 -0
  7. hostinger_api/api/domains_portfolio_api.py +282 -0
  8. hostinger_api/api/vps_actions_api.py +599 -0
  9. hostinger_api/api/vps_backups_api.py +882 -0
  10. hostinger_api/api/vps_data_centers_api.py +282 -0
  11. hostinger_api/api/vps_firewall_api.py +2872 -0
  12. hostinger_api/api/vps_malware_scanner_api.py +842 -0
  13. hostinger_api/api/vps_post_install_scripts_api.py +1419 -0
  14. hostinger_api/api/vps_public_keys_api.py +1154 -0
  15. hostinger_api/api/vps_recovery_api.py +597 -0
  16. hostinger_api/api/vps_snapshots_api.py +1100 -0
  17. hostinger_api/api/vps_virtual_machine_api.py +3714 -0
  18. hostinger_api/api/vpsos_templates_api.py +551 -0
  19. hostinger_api/api/vpsptr_records_api.py +565 -0
  20. hostinger_api/api_client.py +795 -0
  21. hostinger_api/api_response.py +21 -0
  22. hostinger_api/configuration.py +579 -0
  23. hostinger_api/exceptions.py +214 -0
  24. hostinger_api/models/__init__.py +72 -0
  25. hostinger_api/models/billing_v1_catalog_catalog_item_price_resource.py +107 -0
  26. hostinger_api/models/billing_v1_catalog_catalog_item_resource.py +99 -0
  27. hostinger_api/models/billing_v1_order_order_billing_address_resource.py +145 -0
  28. hostinger_api/models/billing_v1_order_order_resource.py +116 -0
  29. hostinger_api/models/billing_v1_order_store_request.py +97 -0
  30. hostinger_api/models/billing_v1_order_store_request_items_inner.py +87 -0
  31. hostinger_api/models/billing_v1_payment_method_payment_method_resource.py +102 -0
  32. hostinger_api/models/billing_v1_subscription_cancel_request.py +117 -0
  33. hostinger_api/models/billing_v1_subscription_subscription_resource.py +130 -0
  34. hostinger_api/models/common_schema_error_response_schema.py +87 -0
  35. hostinger_api/models/common_schema_pagination_meta_schema.py +89 -0
  36. hostinger_api/models/common_schema_unauthorized_response_schema.py +87 -0
  37. hostinger_api/models/common_schema_unprocessable_content_response_schema.py +93 -0
  38. hostinger_api/models/common_schema_unprocessable_content_response_schema_errors.py +87 -0
  39. hostinger_api/models/common_success_empty_resource.py +85 -0
  40. hostinger_api/models/domains_v1_domain_domain_resource.py +126 -0
  41. hostinger_api/models/vps_get_action_list_v1200_response.py +99 -0
  42. hostinger_api/models/vps_get_backup_list_v1200_response.py +99 -0
  43. hostinger_api/models/vps_get_firewall_list_v1200_response.py +99 -0
  44. hostinger_api/models/vps_get_post_install_script_list_v1200_response.py +99 -0
  45. hostinger_api/models/vps_get_public_key_list_v1200_response.py +99 -0
  46. hostinger_api/models/vpsv1_action_action_resource.py +104 -0
  47. hostinger_api/models/vpsv1_backup_backup_resource.py +90 -0
  48. hostinger_api/models/vpsv1_data_center_data_center_resource.py +113 -0
  49. hostinger_api/models/vpsv1_firewall_firewall_resource.py +104 -0
  50. hostinger_api/models/vpsv1_firewall_firewall_rule_resource.py +115 -0
  51. hostinger_api/models/vpsv1_firewall_rules_store_request.py +105 -0
  52. hostinger_api/models/vpsv1_firewall_store_request.py +85 -0
  53. hostinger_api/models/vpsv1_ip_address_ip_address_resource.py +94 -0
  54. hostinger_api/models/vpsv1_malware_metrics_resource.py +101 -0
  55. hostinger_api/models/vpsv1_metrics_metrics_collection.py +149 -0
  56. hostinger_api/models/vpsv1_metrics_metrics_collection_cpu_usage.py +127 -0
  57. hostinger_api/models/vpsv1_metrics_metrics_collection_disk_space.py +127 -0
  58. hostinger_api/models/vpsv1_metrics_metrics_collection_incoming_traffic.py +127 -0
  59. hostinger_api/models/vpsv1_metrics_metrics_collection_outgoing_traffic.py +127 -0
  60. hostinger_api/models/vpsv1_metrics_metrics_collection_ram_usage.py +127 -0
  61. hostinger_api/models/vpsv1_metrics_metrics_collection_uptime.py +127 -0
  62. hostinger_api/models/vpsv1_metrics_metrics_resource.py +87 -0
  63. hostinger_api/models/vpsv1_post_install_script_post_install_script_resource.py +94 -0
  64. hostinger_api/models/vpsv1_post_install_script_store_request.py +87 -0
  65. hostinger_api/models/vpsv1_public_key_attach_request.py +85 -0
  66. hostinger_api/models/vpsv1_public_key_public_key_resource.py +89 -0
  67. hostinger_api/models/vpsv1_public_key_store_request.py +87 -0
  68. hostinger_api/models/vpsv1_snapshot_snapshot_resource.py +90 -0
  69. hostinger_api/models/vpsv1_template_template_resource.py +96 -0
  70. hostinger_api/models/vpsv1_virtual_machine_hostname_update_request.py +85 -0
  71. hostinger_api/models/vpsv1_virtual_machine_metric_get_request.py +88 -0
  72. hostinger_api/models/vpsv1_virtual_machine_nameservers_update_request.py +87 -0
  73. hostinger_api/models/vpsv1_virtual_machine_panel_password_update_request.py +86 -0
  74. hostinger_api/models/vpsv1_virtual_machine_recovery_start_request.py +85 -0
  75. hostinger_api/models/vpsv1_virtual_machine_recreate_request.py +90 -0
  76. hostinger_api/models/vpsv1_virtual_machine_root_password_update_request.py +86 -0
  77. hostinger_api/models/vpsv1_virtual_machine_setup_request.py +108 -0
  78. hostinger_api/models/vpsv1_virtual_machine_setup_request_public_key.py +87 -0
  79. hostinger_api/models/vpsv1_virtual_machine_virtual_machine_resource.py +190 -0
  80. hostinger_api/models/vpsv1_virtual_machine_virtual_machine_resource_ipv4.py +131 -0
  81. hostinger_api/models/vpsv1_virtual_machine_virtual_machine_resource_ipv6.py +131 -0
  82. hostinger_api/models/vpsv1_virtual_machine_virtual_machine_resource_template.py +127 -0
  83. hostinger_api/py.typed +0 -0
  84. hostinger_api/rest.py +256 -0
  85. hostinger_api-1.0.0.dist-info/METADATA +26 -0
  86. hostinger_api-1.0.0.dist-info/RECORD +88 -0
  87. hostinger_api-1.0.0.dist-info/WHEEL +5 -0
  88. hostinger_api-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ """API response object."""
2
+
3
+ from __future__ import annotations
4
+ from typing import Optional, Generic, Mapping, TypeVar
5
+ from pydantic import Field, StrictInt, StrictBytes, BaseModel
6
+
7
+ T = TypeVar("T")
8
+
9
+ class ApiResponse(BaseModel, Generic[T]):
10
+ """
11
+ API response object
12
+ """
13
+
14
+ status_code: StrictInt = Field(description="HTTP status code")
15
+ headers: Optional[Mapping[str, str]] = Field(None, description="HTTP headers")
16
+ data: T = Field(description="Deserialized data given the data type")
17
+ raw_data: StrictBytes = Field(description="Raw data (HTTP response body)")
18
+
19
+ model_config = {
20
+ "arbitrary_types_allowed": True
21
+ }
@@ -0,0 +1,579 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Hostinger API Python SDK
5
+
6
+ API Version: 0.0.1-beta
7
+
8
+ NOTE: This file is auto-generated, DO NOT EDIT THIS FILE MANUALLY!
9
+ If you want to contribute or request a new feature, please create an issue or pull request on https://github.com/hostinger/api
10
+ """ # noqa: E501
11
+
12
+
13
+ import copy
14
+ import http.client as httplib
15
+ import logging
16
+ from logging import FileHandler
17
+ import multiprocessing
18
+ import sys
19
+ from typing import Any, ClassVar, Dict, List, Literal, Optional, TypedDict, Union
20
+ from typing_extensions import NotRequired, Self
21
+
22
+ import urllib3
23
+
24
+
25
+ JSON_SCHEMA_VALIDATION_KEYWORDS = {
26
+ 'multipleOf', 'maximum', 'exclusiveMaximum',
27
+ 'minimum', 'exclusiveMinimum', 'maxLength',
28
+ 'minLength', 'pattern', 'maxItems', 'minItems'
29
+ }
30
+
31
+ ServerVariablesT = Dict[str, str]
32
+
33
+ GenericAuthSetting = TypedDict(
34
+ "GenericAuthSetting",
35
+ {
36
+ "type": str,
37
+ "in": str,
38
+ "key": str,
39
+ "value": str,
40
+ },
41
+ )
42
+
43
+
44
+ OAuth2AuthSetting = TypedDict(
45
+ "OAuth2AuthSetting",
46
+ {
47
+ "type": Literal["oauth2"],
48
+ "in": Literal["header"],
49
+ "key": Literal["Authorization"],
50
+ "value": str,
51
+ },
52
+ )
53
+
54
+
55
+ APIKeyAuthSetting = TypedDict(
56
+ "APIKeyAuthSetting",
57
+ {
58
+ "type": Literal["api_key"],
59
+ "in": str,
60
+ "key": str,
61
+ "value": Optional[str],
62
+ },
63
+ )
64
+
65
+
66
+ BasicAuthSetting = TypedDict(
67
+ "BasicAuthSetting",
68
+ {
69
+ "type": Literal["basic"],
70
+ "in": Literal["header"],
71
+ "key": Literal["Authorization"],
72
+ "value": Optional[str],
73
+ },
74
+ )
75
+
76
+
77
+ BearerFormatAuthSetting = TypedDict(
78
+ "BearerFormatAuthSetting",
79
+ {
80
+ "type": Literal["bearer"],
81
+ "in": Literal["header"],
82
+ "format": Literal["JWT"],
83
+ "key": Literal["Authorization"],
84
+ "value": str,
85
+ },
86
+ )
87
+
88
+
89
+ BearerAuthSetting = TypedDict(
90
+ "BearerAuthSetting",
91
+ {
92
+ "type": Literal["bearer"],
93
+ "in": Literal["header"],
94
+ "key": Literal["Authorization"],
95
+ "value": str,
96
+ },
97
+ )
98
+
99
+
100
+ HTTPSignatureAuthSetting = TypedDict(
101
+ "HTTPSignatureAuthSetting",
102
+ {
103
+ "type": Literal["http-signature"],
104
+ "in": Literal["header"],
105
+ "key": Literal["Authorization"],
106
+ "value": None,
107
+ },
108
+ )
109
+
110
+
111
+ AuthSettings = TypedDict(
112
+ "AuthSettings",
113
+ {
114
+ "apiToken": BearerAuthSetting,
115
+ },
116
+ total=False,
117
+ )
118
+
119
+
120
+ class HostSettingVariable(TypedDict):
121
+ description: str
122
+ default_value: str
123
+ enum_values: List[str]
124
+
125
+
126
+ class HostSetting(TypedDict):
127
+ url: str
128
+ description: str
129
+ variables: NotRequired[Dict[str, HostSettingVariable]]
130
+
131
+
132
+ class Configuration:
133
+ """This class contains various settings of the API client.
134
+
135
+ :param host: Base url.
136
+ :param ignore_operation_servers
137
+ Boolean to ignore operation servers for the API client.
138
+ Config will use `host` as the base url regardless of the operation servers.
139
+ :param api_key: Dict to store API key(s).
140
+ Each entry in the dict specifies an API key.
141
+ The dict key is the name of the security scheme in the OAS specification.
142
+ The dict value is the API key secret.
143
+ :param api_key_prefix: Dict to store API prefix (e.g. Bearer).
144
+ The dict key is the name of the security scheme in the OAS specification.
145
+ The dict value is an API key prefix when generating the auth data.
146
+ :param username: Username for HTTP basic authentication.
147
+ :param password: Password for HTTP basic authentication.
148
+ :param access_token: Access token.
149
+ :param server_index: Index to servers configuration.
150
+ :param server_variables: Mapping with string values to replace variables in
151
+ templated server configuration. The validation of enums is performed for
152
+ variables with defined enum values before.
153
+ :param server_operation_index: Mapping from operation ID to an index to server
154
+ configuration.
155
+ :param server_operation_variables: Mapping from operation ID to a mapping with
156
+ string values to replace variables in templated server configuration.
157
+ The validation of enums is performed for variables with defined enum
158
+ values before.
159
+ :param ssl_ca_cert: str - the path to a file of concatenated CA certificates
160
+ in PEM format.
161
+ :param retries: Number of retries for API requests.
162
+ :param ca_cert_data: verify the peer using concatenated CA certificate data
163
+ in PEM (str) or DER (bytes) format.
164
+
165
+ :Example:
166
+ """
167
+
168
+ _default: ClassVar[Optional[Self]] = None
169
+
170
+ def __init__(
171
+ self,
172
+ host: Optional[str]=None,
173
+ api_key: Optional[Dict[str, str]]=None,
174
+ api_key_prefix: Optional[Dict[str, str]]=None,
175
+ username: Optional[str]=None,
176
+ password: Optional[str]=None,
177
+ access_token: Optional[str]=None,
178
+ server_index: Optional[int]=None,
179
+ server_variables: Optional[ServerVariablesT]=None,
180
+ server_operation_index: Optional[Dict[int, int]]=None,
181
+ server_operation_variables: Optional[Dict[int, ServerVariablesT]]=None,
182
+ ignore_operation_servers: bool=False,
183
+ ssl_ca_cert: Optional[str]=None,
184
+ retries: Optional[int] = None,
185
+ ca_cert_data: Optional[Union[str, bytes]] = None,
186
+ *,
187
+ debug: Optional[bool] = None,
188
+ ) -> None:
189
+ """Constructor
190
+ """
191
+ self._base_path = "https://developers.hostinger.com" if host is None else host
192
+ """Default Base url
193
+ """
194
+ self.server_index = 0 if server_index is None and host is None else server_index
195
+ self.server_operation_index = server_operation_index or {}
196
+ """Default server index
197
+ """
198
+ self.server_variables = server_variables or {}
199
+ self.server_operation_variables = server_operation_variables or {}
200
+ """Default server variables
201
+ """
202
+ self.ignore_operation_servers = ignore_operation_servers
203
+ """Ignore operation servers
204
+ """
205
+ self.temp_folder_path = None
206
+ """Temp file folder for downloading files
207
+ """
208
+ # Authentication Settings
209
+ self.api_key = {}
210
+ if api_key:
211
+ self.api_key = api_key
212
+ """dict to store API key(s)
213
+ """
214
+ self.api_key_prefix = {}
215
+ if api_key_prefix:
216
+ self.api_key_prefix = api_key_prefix
217
+ """dict to store API prefix (e.g. Bearer)
218
+ """
219
+ self.refresh_api_key_hook = None
220
+ """function hook to refresh API key if expired
221
+ """
222
+ self.username = username
223
+ """Username for HTTP basic authentication
224
+ """
225
+ self.password = password
226
+ """Password for HTTP basic authentication
227
+ """
228
+ self.access_token = access_token
229
+ """Access token
230
+ """
231
+ self.logger = {}
232
+ """Logging Settings
233
+ """
234
+ self.logger["package_logger"] = logging.getLogger("hostinger_api")
235
+ self.logger["urllib3_logger"] = logging.getLogger("urllib3")
236
+ self.logger_format = '%(asctime)s %(levelname)s %(message)s'
237
+ """Log format
238
+ """
239
+ self.logger_stream_handler = None
240
+ """Log stream handler
241
+ """
242
+ self.logger_file_handler: Optional[FileHandler] = None
243
+ """Log file handler
244
+ """
245
+ self.logger_file = None
246
+ """Debug file location
247
+ """
248
+ if debug is not None:
249
+ self.debug = debug
250
+ else:
251
+ self.__debug = False
252
+ """Debug switch
253
+ """
254
+
255
+ self.verify_ssl = True
256
+ """SSL/TLS verification
257
+ Set this to false to skip verifying SSL certificate when calling API
258
+ from https server.
259
+ """
260
+ self.ssl_ca_cert = ssl_ca_cert
261
+ """Set this to customize the certificate file to verify the peer.
262
+ """
263
+ self.ca_cert_data = ca_cert_data
264
+ """Set this to verify the peer using PEM (str) or DER (bytes)
265
+ certificate data.
266
+ """
267
+ self.cert_file = None
268
+ """client certificate file
269
+ """
270
+ self.key_file = None
271
+ """client key file
272
+ """
273
+ self.assert_hostname = None
274
+ """Set this to True/False to enable/disable SSL hostname verification.
275
+ """
276
+ self.tls_server_name = None
277
+ """SSL/TLS Server Name Indication (SNI)
278
+ Set this to the SNI value expected by the server.
279
+ """
280
+
281
+ self.connection_pool_maxsize = multiprocessing.cpu_count() * 5
282
+ """urllib3 connection pool's maximum number of connections saved
283
+ per pool. urllib3 uses 1 connection as default value, but this is
284
+ not the best value when you are making a lot of possibly parallel
285
+ requests to the same host, which is often the case here.
286
+ cpu_count * 5 is used as default value to increase performance.
287
+ """
288
+
289
+ self.proxy: Optional[str] = None
290
+ """Proxy URL
291
+ """
292
+ self.proxy_headers = None
293
+ """Proxy headers
294
+ """
295
+ self.safe_chars_for_path_param = ''
296
+ """Safe chars for path_param
297
+ """
298
+ self.retries = retries
299
+ """Adding retries to override urllib3 default value 3
300
+ """
301
+ # Enable client side validation
302
+ self.client_side_validation = True
303
+
304
+ self.socket_options = None
305
+ """Options to pass down to the underlying urllib3 socket
306
+ """
307
+
308
+ self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
309
+ """datetime format
310
+ """
311
+
312
+ self.date_format = "%Y-%m-%d"
313
+ """date format
314
+ """
315
+
316
+ def __deepcopy__(self, memo: Dict[int, Any]) -> Self:
317
+ cls = self.__class__
318
+ result = cls.__new__(cls)
319
+ memo[id(self)] = result
320
+ for k, v in self.__dict__.items():
321
+ if k not in ('logger', 'logger_file_handler'):
322
+ setattr(result, k, copy.deepcopy(v, memo))
323
+ # shallow copy of loggers
324
+ result.logger = copy.copy(self.logger)
325
+ # use setters to configure loggers
326
+ result.logger_file = self.logger_file
327
+ result.debug = self.debug
328
+ return result
329
+
330
+ def __setattr__(self, name: str, value: Any) -> None:
331
+ object.__setattr__(self, name, value)
332
+
333
+ @classmethod
334
+ def set_default(cls, default: Optional[Self]) -> None:
335
+ """Set default instance of configuration.
336
+
337
+ It stores default configuration, which can be
338
+ returned by get_default_copy method.
339
+
340
+ :param default: object of Configuration
341
+ """
342
+ cls._default = default
343
+
344
+ @classmethod
345
+ def get_default_copy(cls) -> Self:
346
+ """Deprecated. Please use `get_default` instead.
347
+
348
+ Deprecated. Please use `get_default` instead.
349
+
350
+ :return: The configuration object.
351
+ """
352
+ return cls.get_default()
353
+
354
+ @classmethod
355
+ def get_default(cls) -> Self:
356
+ """Return the default configuration.
357
+
358
+ This method returns newly created, based on default constructor,
359
+ object of Configuration class or returns a copy of default
360
+ configuration.
361
+
362
+ :return: The configuration object.
363
+ """
364
+ if cls._default is None:
365
+ cls._default = cls()
366
+ return cls._default
367
+
368
+ @property
369
+ def logger_file(self) -> Optional[str]:
370
+ """The logger file.
371
+
372
+ If the logger_file is None, then add stream handler and remove file
373
+ handler. Otherwise, add file handler and remove stream handler.
374
+
375
+ :param value: The logger_file path.
376
+ :type: str
377
+ """
378
+ return self.__logger_file
379
+
380
+ @logger_file.setter
381
+ def logger_file(self, value: Optional[str]) -> None:
382
+ """The logger file.
383
+
384
+ If the logger_file is None, then add stream handler and remove file
385
+ handler. Otherwise, add file handler and remove stream handler.
386
+
387
+ :param value: The logger_file path.
388
+ :type: str
389
+ """
390
+ self.__logger_file = value
391
+ if self.__logger_file:
392
+ # If set logging file,
393
+ # then add file handler and remove stream handler.
394
+ self.logger_file_handler = logging.FileHandler(self.__logger_file)
395
+ self.logger_file_handler.setFormatter(self.logger_formatter)
396
+ for _, logger in self.logger.items():
397
+ logger.addHandler(self.logger_file_handler)
398
+
399
+ @property
400
+ def debug(self) -> bool:
401
+ """Debug status
402
+
403
+ :param value: The debug status, True or False.
404
+ :type: bool
405
+ """
406
+ return self.__debug
407
+
408
+ @debug.setter
409
+ def debug(self, value: bool) -> None:
410
+ """Debug status
411
+
412
+ :param value: The debug status, True or False.
413
+ :type: bool
414
+ """
415
+ self.__debug = value
416
+ if self.__debug:
417
+ # if debug status is True, turn on debug logging
418
+ for _, logger in self.logger.items():
419
+ logger.setLevel(logging.DEBUG)
420
+ # turn on httplib debug
421
+ httplib.HTTPConnection.debuglevel = 1
422
+ else:
423
+ # if debug status is False, turn off debug logging,
424
+ # setting log level to default `logging.WARNING`
425
+ for _, logger in self.logger.items():
426
+ logger.setLevel(logging.WARNING)
427
+ # turn off httplib debug
428
+ httplib.HTTPConnection.debuglevel = 0
429
+
430
+ @property
431
+ def logger_format(self) -> str:
432
+ """The logger format.
433
+
434
+ The logger_formatter will be updated when sets logger_format.
435
+
436
+ :param value: The format string.
437
+ :type: str
438
+ """
439
+ return self.__logger_format
440
+
441
+ @logger_format.setter
442
+ def logger_format(self, value: str) -> None:
443
+ """The logger format.
444
+
445
+ The logger_formatter will be updated when sets logger_format.
446
+
447
+ :param value: The format string.
448
+ :type: str
449
+ """
450
+ self.__logger_format = value
451
+ self.logger_formatter = logging.Formatter(self.__logger_format)
452
+
453
+ def get_api_key_with_prefix(self, identifier: str, alias: Optional[str]=None) -> Optional[str]:
454
+ """Gets API key (with prefix if set).
455
+
456
+ :param identifier: The identifier of apiKey.
457
+ :param alias: The alternative identifier of apiKey.
458
+ :return: The token for api key authentication.
459
+ """
460
+ if self.refresh_api_key_hook is not None:
461
+ self.refresh_api_key_hook(self)
462
+ key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None)
463
+ if key:
464
+ prefix = self.api_key_prefix.get(identifier)
465
+ if prefix:
466
+ return "%s %s" % (prefix, key)
467
+ else:
468
+ return key
469
+
470
+ return None
471
+
472
+ def get_basic_auth_token(self) -> Optional[str]:
473
+ """Gets HTTP basic authentication header (string).
474
+
475
+ :return: The token for basic HTTP authentication.
476
+ """
477
+ username = ""
478
+ if self.username is not None:
479
+ username = self.username
480
+ password = ""
481
+ if self.password is not None:
482
+ password = self.password
483
+ return urllib3.util.make_headers(
484
+ basic_auth=username + ':' + password
485
+ ).get('authorization')
486
+
487
+ def auth_settings(self)-> AuthSettings:
488
+ """Gets Auth Settings dict for api client.
489
+
490
+ :return: The Auth Settings information dict.
491
+ """
492
+ auth: AuthSettings = {}
493
+ if self.access_token is not None:
494
+ auth['apiToken'] = {
495
+ 'type': 'bearer',
496
+ 'in': 'header',
497
+ 'key': 'Authorization',
498
+ 'value': 'Bearer ' + self.access_token
499
+ }
500
+ return auth
501
+
502
+ def to_debug_report(self) -> str:
503
+ """Gets the essential information for debugging.
504
+
505
+ :return: The report for debugging.
506
+ """
507
+ return "Python SDK Debug Report:\n"\
508
+ "OS: {env}\n"\
509
+ "Python Version: {pyversion}\n"\
510
+ "Version of the API: 0.0.1-beta\n"\
511
+ "SDK Package Version: 1.0.0".\
512
+ format(env=sys.platform, pyversion=sys.version)
513
+
514
+ def get_host_settings(self) -> List[HostSetting]:
515
+ """Gets an array of host settings
516
+
517
+ :return: An array of host settings
518
+ """
519
+ return [
520
+ {
521
+ 'url': "https://developers.hostinger.com",
522
+ 'description': "Production API Server",
523
+ }
524
+ ]
525
+
526
+ def get_host_from_settings(
527
+ self,
528
+ index: Optional[int],
529
+ variables: Optional[ServerVariablesT]=None,
530
+ servers: Optional[List[HostSetting]]=None,
531
+ ) -> str:
532
+ """Gets host URL based on the index and variables
533
+ :param index: array index of the host settings
534
+ :param variables: hash of variable and the corresponding value
535
+ :param servers: an array of host settings or None
536
+ :return: URL based on host settings
537
+ """
538
+ if index is None:
539
+ return self._base_path
540
+
541
+ variables = {} if variables is None else variables
542
+ servers = self.get_host_settings() if servers is None else servers
543
+
544
+ try:
545
+ server = servers[index]
546
+ except IndexError:
547
+ raise ValueError(
548
+ "Invalid index {0} when selecting the host settings. "
549
+ "Must be less than {1}".format(index, len(servers)))
550
+
551
+ url = server['url']
552
+
553
+ # go through variables and replace placeholders
554
+ for variable_name, variable in server.get('variables', {}).items():
555
+ used_value = variables.get(
556
+ variable_name, variable['default_value'])
557
+
558
+ if 'enum_values' in variable \
559
+ and used_value not in variable['enum_values']:
560
+ raise ValueError(
561
+ "The variable `{0}` in the host URL has invalid value "
562
+ "{1}. Must be {2}.".format(
563
+ variable_name, variables[variable_name],
564
+ variable['enum_values']))
565
+
566
+ url = url.replace("{" + variable_name + "}", used_value)
567
+
568
+ return url
569
+
570
+ @property
571
+ def host(self) -> str:
572
+ """Return generated host."""
573
+ return self.get_host_from_settings(self.server_index, variables=self.server_variables)
574
+
575
+ @host.setter
576
+ def host(self, value: str) -> None:
577
+ """Fix base path."""
578
+ self._base_path = value
579
+ self.server_index = None