tesla-api-sdk 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 (119) hide show
  1. tesla_api_sdk-1.0.0.dist-info/METADATA +145 -0
  2. tesla_api_sdk-1.0.0.dist-info/RECORD +119 -0
  3. tesla_api_sdk-1.0.0.dist-info/WHEEL +5 -0
  4. tesla_api_sdk-1.0.0.dist-info/licenses/LICENSE +28 -0
  5. tesla_api_sdk-1.0.0.dist-info/top_level.txt +1 -0
  6. teslafleetmanagementapi/__init__.py +13 -0
  7. teslafleetmanagementapi/api_helper.py +19 -0
  8. teslafleetmanagementapi/configuration.py +270 -0
  9. teslafleetmanagementapi/controllers/__init__.py +11 -0
  10. teslafleetmanagementapi/controllers/base_controller.py +70 -0
  11. teslafleetmanagementapi/controllers/charging_controller.py +140 -0
  12. teslafleetmanagementapi/controllers/energy_controller.py +572 -0
  13. teslafleetmanagementapi/controllers/oauth_authorization_controller.py +165 -0
  14. teslafleetmanagementapi/controllers/partner_controller.py +181 -0
  15. teslafleetmanagementapi/controllers/user_controller.py +158 -0
  16. teslafleetmanagementapi/controllers/vehicles_controller.py +832 -0
  17. teslafleetmanagementapi/exceptions/__init__.py +6 -0
  18. teslafleetmanagementapi/exceptions/api_exception.py +36 -0
  19. teslafleetmanagementapi/exceptions/oauth_provider_exception.py +75 -0
  20. teslafleetmanagementapi/http/__init__.py +11 -0
  21. teslafleetmanagementapi/http/api_response.py +67 -0
  22. teslafleetmanagementapi/http/auth/__init__.py +6 -0
  23. teslafleetmanagementapi/http/auth/bearer_auth.py +103 -0
  24. teslafleetmanagementapi/http/auth/oauth_2.py +311 -0
  25. teslafleetmanagementapi/http/http_call_back.py +20 -0
  26. teslafleetmanagementapi/http/http_client_provider.py +23 -0
  27. teslafleetmanagementapi/http/http_method_enum.py +25 -0
  28. teslafleetmanagementapi/http/http_request.py +55 -0
  29. teslafleetmanagementapi/http/http_response.py +45 -0
  30. teslafleetmanagementapi/http/proxy_settings.py +50 -0
  31. teslafleetmanagementapi/logging/__init__.py +6 -0
  32. teslafleetmanagementapi/logging/configuration/__init__.py +5 -0
  33. teslafleetmanagementapi/logging/configuration/api_logging_configuration.py +398 -0
  34. teslafleetmanagementapi/logging/sdk_logger.py +28 -0
  35. teslafleetmanagementapi/models/__init__.py +85 -0
  36. teslafleetmanagementapi/models/api_1_dx_vehicles_options_response.py +110 -0
  37. teslafleetmanagementapi/models/api_1_dx_warranty_details_response.py +110 -0
  38. teslafleetmanagementapi/models/api_1_vehicles_mobile_enabled_response.py +109 -0
  39. teslafleetmanagementapi/models/api_1_vehicles_nearby_charging_sites_response.py +109 -0
  40. teslafleetmanagementapi/models/api_1_vehicles_response.py +162 -0
  41. teslafleetmanagementapi/models/api_1_vehicles_response_get_vehicle.py +109 -0
  42. teslafleetmanagementapi/models/api_1_vehicles_wake_up_response.py +109 -0
  43. teslafleetmanagementapi/models/backup_request.py +92 -0
  44. teslafleetmanagementapi/models/backup_response.py +95 -0
  45. teslafleetmanagementapi/models/calendar_history_response.py +96 -0
  46. teslafleetmanagementapi/models/charge_duration.py +92 -0
  47. teslafleetmanagementapi/models/charge_history.py +125 -0
  48. teslafleetmanagementapi/models/charge_history_response.py +96 -0
  49. teslafleetmanagementapi/models/charge_start_time.py +92 -0
  50. teslafleetmanagementapi/models/charging_dimension.py +128 -0
  51. teslafleetmanagementapi/models/charging_fee.py +641 -0
  52. teslafleetmanagementapi/models/charging_history_data.py +98 -0
  53. teslafleetmanagementapi/models/charging_history_item.py +336 -0
  54. teslafleetmanagementapi/models/charging_history_response.py +96 -0
  55. teslafleetmanagementapi/models/charging_invoice.py +151 -0
  56. teslafleetmanagementapi/models/charging_location.py +293 -0
  57. teslafleetmanagementapi/models/charging_period.py +136 -0
  58. teslafleetmanagementapi/models/charging_session.py +355 -0
  59. teslafleetmanagementapi/models/charging_sessions_data.py +182 -0
  60. teslafleetmanagementapi/models/charging_sessions_response.py +96 -0
  61. teslafleetmanagementapi/models/default_real_mode.py +45 -0
  62. teslafleetmanagementapi/models/driver.py +289 -0
  63. teslafleetmanagementapi/models/drivers_response.py +135 -0
  64. teslafleetmanagementapi/models/enterprise_payer_request.py +141 -0
  65. teslafleetmanagementapi/models/event.py +107 -0
  66. teslafleetmanagementapi/models/fleet_status_request.py +105 -0
  67. teslafleetmanagementapi/models/fleet_telemetry_error.py +118 -0
  68. teslafleetmanagementapi/models/fleet_telemetry_errors_response.py +96 -0
  69. teslafleetmanagementapi/models/fleet_telemetry_jws_request.py +128 -0
  70. teslafleetmanagementapi/models/generic_update_response.py +95 -0
  71. teslafleetmanagementapi/models/kind.py +45 -0
  72. teslafleetmanagementapi/models/kind_get_wall_connector_charging_history.py +42 -0
  73. teslafleetmanagementapi/models/live_status_response.py +96 -0
  74. teslafleetmanagementapi/models/location.py +128 -0
  75. teslafleetmanagementapi/models/location_1.py +128 -0
  76. teslafleetmanagementapi/models/me_response.py +95 -0
  77. teslafleetmanagementapi/models/mobile_enabled.py +128 -0
  78. teslafleetmanagementapi/models/oauth_provider_error.py +67 -0
  79. teslafleetmanagementapi/models/oauth_token.py +115 -0
  80. teslafleetmanagementapi/models/off_grid_vehicle_charging_reserve_request.py +95 -0
  81. teslafleetmanagementapi/models/operation_request.py +93 -0
  82. teslafleetmanagementapi/models/orders_response.py +111 -0
  83. teslafleetmanagementapi/models/pagination.py +225 -0
  84. teslafleetmanagementapi/models/price_component.py +151 -0
  85. teslafleetmanagementapi/models/products_response.py +128 -0
  86. teslafleetmanagementapi/models/public_key_response.py +96 -0
  87. teslafleetmanagementapi/models/region_response.py +96 -0
  88. teslafleetmanagementapi/models/register_partner_request.py +92 -0
  89. teslafleetmanagementapi/models/register_partner_response.py +96 -0
  90. teslafleetmanagementapi/models/response.py +105 -0
  91. teslafleetmanagementapi/models/response_1.py +92 -0
  92. teslafleetmanagementapi/models/response_2.py +95 -0
  93. teslafleetmanagementapi/models/response_3.py +164 -0
  94. teslafleetmanagementapi/models/response_api_1_dx_vehicles_options_response.py +112 -0
  95. teslafleetmanagementapi/models/response_api_1_dx_warranty_details_response.py +169 -0
  96. teslafleetmanagementapi/models/response_calendar_history_response.py +110 -0
  97. teslafleetmanagementapi/models/response_charge_history_response.py +98 -0
  98. teslafleetmanagementapi/models/response_fleet_telemetry_errors_response.py +98 -0
  99. teslafleetmanagementapi/models/response_live_status_response.py +310 -0
  100. teslafleetmanagementapi/models/response_me_response.py +131 -0
  101. teslafleetmanagementapi/models/response_orders_response.py +209 -0
  102. teslafleetmanagementapi/models/response_public_key_response.py +92 -0
  103. teslafleetmanagementapi/models/response_region_response.py +105 -0
  104. teslafleetmanagementapi/models/response_register_partner_response.py +331 -0
  105. teslafleetmanagementapi/models/signaling.py +118 -0
  106. teslafleetmanagementapi/models/simple_ok_response.py +105 -0
  107. teslafleetmanagementapi/models/site_info_response.py +105 -0
  108. teslafleetmanagementapi/models/storm_mode_request.py +92 -0
  109. teslafleetmanagementapi/models/tariff_element.py +136 -0
  110. teslafleetmanagementapi/models/tariffs.py +136 -0
  111. teslafleetmanagementapi/models/time_of_use_settings_request.py +95 -0
  112. teslafleetmanagementapi/models/total_cost.py +151 -0
  113. teslafleetmanagementapi/models/tou_settings.py +105 -0
  114. teslafleetmanagementapi/models/vehicle_base.py +266 -0
  115. teslafleetmanagementapi/models/vehicle_option.py +178 -0
  116. teslafleetmanagementapi/models/warranty_item.py +249 -0
  117. teslafleetmanagementapi/teslafleetmanagementapi_client.py +128 -0
  118. teslafleetmanagementapi/utilities/__init__.py +6 -0
  119. teslafleetmanagementapi/utilities/file_wrapper.py +45 -0
@@ -0,0 +1,6 @@
1
+ # ruff: noqa: D104 | Missing docstring in public package
2
+ # ruff: noqa: RUF022 | `__all__` is not sorted
3
+ __all__ = [
4
+ "api_exception",
5
+ "oauth_provider_exception",
6
+ ]
@@ -0,0 +1,36 @@
1
+ """teslafleetmanagementapi.
2
+
3
+ This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
4
+ """
5
+
6
+
7
+ class ApiException(Exception):
8
+ """Class that handles HTTP Exceptions when fetching API Endpoints.
9
+
10
+ Attributes:
11
+ response_code (int): The status code of the response.
12
+ response (HttpResponse): The HttpResponse of the API call.
13
+
14
+ """
15
+
16
+ def __init__(self,
17
+ reason,
18
+ response):
19
+ """Initialize ApiException object.
20
+
21
+ Args:
22
+ reason (string): The reason (or error message) for the Exception
23
+ to be raised.
24
+ response (HttpResponse): The HttpResponse of the API call.
25
+
26
+ """
27
+ super(ApiException, self).__init__(reason)
28
+ self.reason = reason
29
+ self.response = response
30
+ self.response_code = response.status_code
31
+
32
+ def __str__(self):
33
+ """Return a human-readable string representation."""
34
+ return (f"{self.__class__.__name__}("
35
+ f"status_code={self.response_code!s}, "
36
+ f"message={self.reason!s})")
@@ -0,0 +1,75 @@
1
+ """teslafleetmanagementapi.
2
+
3
+ This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
4
+ """
5
+
6
+ # ruff: noqa: E501
7
+ from teslafleetmanagementapi.api_helper import (
8
+ APIHelper,
9
+ )
10
+ from teslafleetmanagementapi.exceptions.api_exception import (
11
+ ApiException,
12
+ )
13
+
14
+
15
+ class OauthProviderException(ApiException):
16
+ def __init__(self, reason, response):
17
+ """Initialize OauthProviderException object.
18
+
19
+ Args:
20
+ reason (string): The reason (or error message) for the Exception
21
+ to be raised.
22
+ response (HttpResponse): The HttpResponse of the API call.
23
+
24
+ """
25
+ super(OauthProviderException, self).__init__(reason, response)
26
+ dictionary = APIHelper.json_deserialize(self.response.text)
27
+ if isinstance(dictionary, dict):
28
+ self.unbox(dictionary)
29
+
30
+ def unbox(self, dictionary):
31
+ """Populate the properties of this object by extracting them from a dictionary.
32
+
33
+ Args:
34
+ dictionary (dictionary): A dictionary representation of the object as
35
+ obtained from the deserialization of the server's response. The keys
36
+ MUST match property names in the API description.
37
+
38
+ """
39
+ self.error =\
40
+ dictionary.get("error")\
41
+ if dictionary.get("error")\
42
+ else None
43
+ self.error_description =\
44
+ dictionary.get("error_description")\
45
+ if dictionary.get("error_description")\
46
+ else None
47
+ self.error_uri =\
48
+ dictionary.get("error_uri")\
49
+ if dictionary.get("error_uri")\
50
+ else None
51
+
52
+
53
+ def __str__(self):
54
+ """Return a human-readable string representation."""
55
+ _error=self.error
56
+ _error_description=(
57
+ self.error_description
58
+ if hasattr(self, "error_description")
59
+ else None
60
+ )
61
+ _error_uri=(
62
+ self.error_uri
63
+ if hasattr(self, "error_uri")
64
+ else None
65
+ )
66
+ _base_str = super().__str__()
67
+ _base_str = _base_str[_base_str.find("(") + 1:-1]
68
+ return (
69
+ f"{self.__class__.__name__}("
70
+ f"base_str={_base_str!s}, "
71
+ f"error={_error!s}, "
72
+ f"error_description={_error_description!s}, "
73
+ f"error_uri={_error_uri!s}, "
74
+ f")"
75
+ )
@@ -0,0 +1,11 @@
1
+ # ruff: noqa: D104 | Missing docstring in public package
2
+ # ruff: noqa: RUF022 | `__all__` is not sorted
3
+ __all__ = [
4
+ "auth",
5
+ "http_call_back",
6
+ "http_client_provider",
7
+ "http_method_enum",
8
+ "http_request",
9
+ "http_response",
10
+ "proxy_settings",
11
+ ]
@@ -0,0 +1,67 @@
1
+
2
+ """
3
+ teslafleetmanagementapi
4
+
5
+ This file was automatically generated by APIMATIC v3.0 (
6
+ https://www.apimatic.io ).
7
+ """
8
+
9
+ from apimatic_core.http.response.api_response import ApiResponse as CoreApiResponse
10
+ from apimatic_core.http.response.http_response import HttpResponse
11
+
12
+
13
+ class ApiResponse(CoreApiResponse):
14
+ """
15
+ Represent a processed API response returned by an SDK operation.
16
+
17
+ This class wraps the underlying HTTP response and provides convenient
18
+ access to the response body, headers, and any errors returned by the API.
19
+ """
20
+
21
+ def __init__(self, http_response, body=None, errors=None):
22
+ """
23
+ Initialize an ApiResponse instance.
24
+
25
+ Args:
26
+ http_response (HttpResponse): The original HTTP response.
27
+ body (object | None): The parsed response body.
28
+ errors (list[str] | None): Any errors returned by the API.
29
+
30
+ """
31
+ super().__init__(http_response, body, errors)
32
+
33
+ def __repr__(self):
34
+ """
35
+ Return a concise string representation of the response.
36
+
37
+ Returns:
38
+ str: A string identifying the ApiResponse instance.
39
+
40
+ """
41
+ return f"<ApiResponse {self.text}>"
42
+
43
+ @classmethod
44
+ def create(cls, parent_instance):
45
+ """
46
+ Create an ApiResponse instance from another response-like object.
47
+
48
+ This method is typically used to adapt an internal or intermediate
49
+ response object into a concrete ApiResponse instance.
50
+
51
+ Args:
52
+ parent_instance: An object containing HTTP response data.
53
+
54
+ Returns:
55
+ ApiResponse: A new ApiResponse instance.
56
+
57
+ """
58
+ return cls(
59
+ HttpResponse(
60
+ parent_instance.status_code,
61
+ parent_instance.reason_phrase,
62
+ parent_instance.headers,
63
+ parent_instance.text,
64
+ parent_instance.request),
65
+ parent_instance.body,
66
+ parent_instance.errors,
67
+ )
@@ -0,0 +1,6 @@
1
+ # ruff: noqa: D104 | Missing docstring in public package
2
+ # ruff: noqa: RUF022 | `__all__` is not sorted
3
+ __all__ = [
4
+ "bearer_auth",
5
+ "oauth_2",
6
+ ]
@@ -0,0 +1,103 @@
1
+
2
+ """
3
+ teslafleetmanagementapi
4
+
5
+ This file was automatically generated by APIMATIC v3.0 (
6
+ https://www.apimatic.io ).
7
+ """
8
+
9
+ import os
10
+
11
+ from apimatic_core.authentication.header_auth import (
12
+ HeaderAuth,
13
+ )
14
+
15
+
16
+ class BearerAuth(HeaderAuth):
17
+ """
18
+ An authentication handler that applies `BearerAuth` to
19
+ outgoing requests. It constructs the required credential values and integrates
20
+ with the core authentication framework.
21
+ """
22
+
23
+ @property
24
+ def error_message(self):
25
+ """Return reason about the authentication failure."""
26
+ return "BearerAuth: access_token is undefined."
27
+
28
+ def __init__(self, auth_credentials_model):
29
+ """
30
+ Initialize the authentication handler with credential data.
31
+
32
+ Args:
33
+ auth_credentials_model: The credentials object used to generate
34
+ the authorization header.
35
+
36
+ """
37
+ self._access_token = auth_credentials_model.access_token \
38
+ if auth_credentials_model is not None else None
39
+ auth_params = {}
40
+ if self._access_token:
41
+ auth_params = {"Authorization": f"Bearer {self._access_token}"}
42
+ super().__init__(auth_params=auth_params)
43
+
44
+
45
+ class BearerAuthCredentials:
46
+ """
47
+ A model for authentication credentials. Provides simple validation,
48
+ cloning support, and optional construction from environment variables.
49
+ Suitable as a pattern for other auth models.
50
+ """
51
+
52
+ @property
53
+ def access_token(self):
54
+ """
55
+ The OAuth 2.0 Access Token to use for API requests.
56
+ """
57
+ return self._access_token
58
+
59
+ def __init__(self, access_token):
60
+ """
61
+ Initialize the credentials.
62
+
63
+ Args:
64
+ access_token: The access_token property value to set.
65
+
66
+ Raises:
67
+ ValueError: If any required value is missing.
68
+
69
+ """
70
+ if access_token is None:
71
+ raise ValueError("access_token cannot be None")
72
+ self._access_token = access_token
73
+
74
+ def clone_with(self, access_token=None):
75
+ """
76
+ Return a new instance with optional value overrides.
77
+
78
+ Args:
79
+ access_token: The access_token property value to set.
80
+
81
+ """
82
+ return BearerAuthCredentials(access_token or self.access_token)
83
+
84
+ @classmethod
85
+ def from_environment(cls):
86
+ """
87
+ Create credentials from environment variables, if available.
88
+
89
+ Returns:
90
+ A credentials instance or ``None`` if values are missing.
91
+
92
+ """
93
+ access_token = os.getenv(
94
+ "BEARER_AUTH_ACCESS_TOKEN",
95
+ None,
96
+ )
97
+
98
+ if (access_token is None):
99
+ return None
100
+
101
+ return cls(
102
+ access_token=access_token,
103
+ )
@@ -0,0 +1,311 @@
1
+
2
+ """
3
+ teslafleetmanagementapi
4
+
5
+ This file was automatically generated by APIMATIC v3.0 (
6
+ https://www.apimatic.io ).
7
+ """
8
+
9
+ import os
10
+
11
+ from apimatic_core.authentication.header_auth import (
12
+ HeaderAuth,
13
+ )
14
+ from apimatic_core.utilities.auth_helper import (
15
+ AuthHelper,
16
+ )
17
+
18
+ from teslafleetmanagementapi.api_helper import (
19
+ APIHelper,
20
+ )
21
+ from teslafleetmanagementapi.configuration import (
22
+ Server,
23
+ )
24
+ from teslafleetmanagementapi.controllers.oauth_authorization_controller import (
25
+ OauthAuthorizationController,
26
+ )
27
+ from teslafleetmanagementapi.models.oauth_token import (
28
+ OauthToken,
29
+ )
30
+
31
+
32
+ class Oauth2(HeaderAuth):
33
+ """
34
+ An authentication handler that applies `AuthorizationCodeAuth` to
35
+ outgoing requests. It constructs the required credential values and integrates
36
+ with the core authentication framework.
37
+ """
38
+
39
+ @property
40
+ def error_message(self):
41
+ """Return reason about the authentication failure."""
42
+ return "Oauth2: OAuthToken is undefined or expired."
43
+
44
+ def __init__(self, auth_credentials_model, config):
45
+ """
46
+ Initialize the authentication handler with credential data.
47
+
48
+ Args:
49
+ auth_credentials_model: The credentials object used to generate
50
+ the authorization header.
51
+ config: The configuration instance.
52
+
53
+ """
54
+ self._oauth_client_id = auth_credentials_model.oauth_client_id \
55
+ if auth_credentials_model is not None else None
56
+ self._oauth_client_secret = auth_credentials_model.oauth_client_secret \
57
+ if auth_credentials_model is not None else None
58
+ self._oauth_redirect_uri = auth_credentials_model.oauth_redirect_uri \
59
+ if auth_credentials_model is not None else None
60
+ if auth_credentials_model is not None \
61
+ and isinstance(auth_credentials_model.oauth_token, OauthToken):
62
+ self._oauth_token = OauthToken.from_dictionary(
63
+ APIHelper.to_dictionary(auth_credentials_model.oauth_token))
64
+ else:
65
+ self._oauth_token = auth_credentials_model.oauth_token \
66
+ if auth_credentials_model is not None else None
67
+ self._config = config
68
+ self._o_auth_api = OauthAuthorizationController(config)
69
+ auth_params = {}
70
+ if (isinstance(self._oauth_token, OauthToken)
71
+ and hasattr(self._oauth_token, "access_token")):
72
+ auth_params = {"Authorization": f"Bearer {self._oauth_token.access_token}"}
73
+ super().__init__(auth_params=auth_params)
74
+
75
+ def is_valid(self):
76
+ """
77
+ Validate credentials for authentication.
78
+
79
+ Returns:
80
+ bool: True if the credentials are valid, False otherwise.
81
+
82
+ """
83
+ return (self._oauth_token and isinstance(self._oauth_token, OauthToken)
84
+ and not self.is_token_expired(self._oauth_token))
85
+
86
+ def get_authorization_url(self, state=None, additional_params=None):
87
+ """
88
+ Build and return an authorization URL. The user is expected to
89
+ obtain an authorization code from this URL and then call the authorize
90
+ function with that authorization code.
91
+
92
+ Args:
93
+ state (str): An opaque state string.
94
+ additional_params (dict): Any additional query parameters
95
+ to be added to the URL.
96
+
97
+ Returns:
98
+ str: The authorization URL.
99
+
100
+ """
101
+ auth_url = self._config.get_base_uri(Server.AUTH_SERVER)
102
+ auth_url += "/authorize"
103
+ query_params = {
104
+ "response_type": "code",
105
+ "client_id": self._oauth_client_id,
106
+ "redirect_uri": self._oauth_redirect_uri,
107
+ }
108
+ if state:
109
+ query_params["state"] = state
110
+ if additional_params:
111
+ query_params.update(additional_params)
112
+ auth_url = APIHelper.append_url_with_query_parameters(auth_url, query_params)
113
+ return APIHelper.clean_url(auth_url)
114
+
115
+ def build_basic_auth_header(self):
116
+ """
117
+ Build the basic auth header for endpoints in the
118
+ OAuth Authorization Controller.
119
+
120
+ Returns:
121
+ str: The value of the Authentication header.
122
+
123
+ """
124
+ encoded = AuthHelper.get_base64_encoded_value(
125
+ self._oauth_client_id,
126
+ self._oauth_client_secret,
127
+ )
128
+ return f"Basic {encoded}"
129
+
130
+ def fetch_token(self, auth_code, additional_params=None):
131
+ """
132
+ Execute call to fetch the OAuth token.
133
+
134
+ Args:
135
+ auth_code (str): The authentication code.
136
+ additional_params (dict): Any additional form parameters.
137
+
138
+ Returns:
139
+ OAuthToken: The OAuth token.
140
+
141
+ """
142
+ token = self._o_auth_api.request_token_oauth_2(
143
+ self.build_basic_auth_header(),
144
+ auth_code,
145
+ self._oauth_redirect_uri,
146
+ _optional_form_parameters=additional_params,
147
+ ).body
148
+ if hasattr(token, "expires_in"):
149
+ current_utc_timestamp = AuthHelper.get_current_utc_timestamp()
150
+ token.expiry = AuthHelper.get_token_expiry(
151
+ current_utc_timestamp,
152
+ token.expires_in,
153
+ )
154
+ return token
155
+
156
+ def is_token_expired(self, oauth_token=None):
157
+ """
158
+ Check if OAuth token has expired.
159
+
160
+ Args:
161
+ oauth_token (OauthToken): The OAuth token whose expiry is to be checked.
162
+
163
+ Returns:
164
+ bool: True if OAuth token has expired, False otherwise.
165
+
166
+ """
167
+ if oauth_token is None:
168
+ return (hasattr(self._oauth_token, "expiry")
169
+ and AuthHelper.is_token_expired(
170
+ self._oauth_token.expiry))
171
+
172
+ return (hasattr(oauth_token, "expiry")
173
+ and AuthHelper.is_token_expired(
174
+ oauth_token.expiry))
175
+
176
+ def refresh_token(self, additional_params=None):
177
+ """
178
+ Execute call to refresh the OAuth token.
179
+
180
+ Args:
181
+ additional_params (dict): Any additional form parameters.
182
+
183
+ Returns:
184
+ OAuthToken: The refreshed OAuth token.
185
+
186
+ """
187
+ token = self._o_auth_api.refresh_token_oauth_2(
188
+ self.build_basic_auth_header(),
189
+ self._oauth_token.refresh_token,
190
+ _optional_form_parameters=additional_params,
191
+ ).body
192
+ if hasattr(token, "expires_in"):
193
+ current_utc_timestamp = AuthHelper.get_current_utc_timestamp()
194
+ token.expiry = AuthHelper.get_token_expiry(
195
+ current_utc_timestamp,
196
+ token.expires_in,
197
+ )
198
+ return token
199
+
200
+
201
+ class Oauth2Credentials:
202
+ """
203
+ A model for authentication credentials. Provides simple validation,
204
+ cloning support, and optional construction from environment variables.
205
+ Suitable as a pattern for other auth models.
206
+ """
207
+
208
+ @property
209
+ def oauth_client_id(self):
210
+ """
211
+ OAuth 2 Client ID.
212
+ """
213
+ return self._oauth_client_id
214
+
215
+ @property
216
+ def oauth_client_secret(self):
217
+ """
218
+ OAuth 2 Client Secret.
219
+ """
220
+ return self._oauth_client_secret
221
+
222
+ @property
223
+ def oauth_redirect_uri(self):
224
+ """
225
+ OAuth 2 Redirection endpoint or Callback Uri.
226
+ """
227
+ return self._oauth_redirect_uri
228
+
229
+ @property
230
+ def oauth_token(self):
231
+ """
232
+ Object for storing information about the OAuth token.
233
+ """
234
+ return self._oauth_token
235
+
236
+ def __init__(self, oauth_client_id, oauth_client_secret, oauth_redirect_uri,
237
+ oauth_token=None):
238
+ """
239
+ Initialize the credentials.
240
+
241
+ Args:
242
+ oauth_client_id: The oauth_client_id property value to set.
243
+ oauth_client_secret: The oauth_client_secret property value to set.
244
+ oauth_redirect_uri: The oauth_redirect_uri property value to set.
245
+ oauth_token: The oauth_token property value to set.
246
+
247
+ Raises:
248
+ ValueError: If any required value is missing.
249
+
250
+ """
251
+ if oauth_client_id is None:
252
+ raise ValueError("oauth_client_id cannot be None")
253
+ if oauth_client_secret is None:
254
+ raise ValueError("oauth_client_secret cannot be None")
255
+ if oauth_redirect_uri is None:
256
+ raise ValueError("oauth_redirect_uri cannot be None")
257
+ self._oauth_client_id = oauth_client_id
258
+ self._oauth_client_secret = oauth_client_secret
259
+ self._oauth_redirect_uri = oauth_redirect_uri
260
+ self._oauth_token = oauth_token
261
+
262
+ def clone_with(self, oauth_client_id=None, oauth_client_secret=None,
263
+ oauth_redirect_uri=None, oauth_token=None):
264
+ """
265
+ Return a new instance with optional value overrides.
266
+
267
+ Args:
268
+ oauth_client_id: The oauth_client_id property value to set.
269
+ oauth_client_secret: The oauth_client_secret property value to set.
270
+ oauth_redirect_uri: The oauth_redirect_uri property value to set.
271
+ oauth_token: The oauth_token property value to set.
272
+
273
+ """
274
+ return Oauth2Credentials(
275
+ oauth_client_id or self.oauth_client_id,
276
+ oauth_client_secret or self.oauth_client_secret,
277
+ oauth_redirect_uri or self.oauth_redirect_uri,
278
+ oauth_token or self.oauth_token)
279
+
280
+ @classmethod
281
+ def from_environment(cls):
282
+ """
283
+ Create credentials from environment variables, if available.
284
+
285
+ Returns:
286
+ A credentials instance or ``None`` if values are missing.
287
+
288
+ """
289
+ oauth_client_id = os.getenv(
290
+ "OAUTH_2_OAUTH_CLIENT_ID",
291
+ None,
292
+ )
293
+ oauth_client_secret = os.getenv(
294
+ "OAUTH_2_OAUTH_CLIENT_SECRET",
295
+ None,
296
+ )
297
+ oauth_redirect_uri = os.getenv(
298
+ "OAUTH_2_OAUTH_REDIRECT_URI",
299
+ None,
300
+ )
301
+
302
+ if (oauth_client_id is None
303
+ or oauth_client_secret is None
304
+ or oauth_redirect_uri is None):
305
+ return None
306
+
307
+ return cls(
308
+ oauth_client_id=oauth_client_id,
309
+ oauth_client_secret=oauth_client_secret,
310
+ oauth_redirect_uri=oauth_redirect_uri,
311
+ )
@@ -0,0 +1,20 @@
1
+
2
+ """
3
+ teslafleetmanagementapi
4
+
5
+ This file was automatically generated by APIMATIC v3.0 (
6
+ https://www.apimatic.io ).
7
+ """
8
+
9
+ from apimatic_core.http.http_callback import HttpCallBack as CoreHttpCallback
10
+
11
+
12
+ class HttpCallBack(CoreHttpCallback):
13
+ """
14
+ An interface for the callback to be called before and after the
15
+ HTTP call for an endpoint is made.
16
+
17
+ This class should not be instantiated but should be used as a base class
18
+ for HttpCallBack classes.
19
+
20
+ """
@@ -0,0 +1,23 @@
1
+ """
2
+ teslafleetmanagementapi
3
+
4
+ This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
5
+ """
6
+ from abc import ABC
7
+
8
+ from apimatic_core_interfaces.client.http_client_provider import (
9
+ HttpClientProvider as CoreHttpClientProvider,
10
+ )
11
+
12
+
13
+ class HttpClientProvider(CoreHttpClientProvider, ABC):
14
+ """
15
+ Defines a contract for providing HTTP client configuration.
16
+
17
+ Classes implementing this interface are expected to supply a configured
18
+ HTTP session and timeout value that will be used by the SDK's internal
19
+ HTTP layer when making network requests.
20
+
21
+ This allows developers to inject their own custom HTTP clients while
22
+ maintaining compatibility with the SDK's request/response handling.
23
+ """
@@ -0,0 +1,25 @@
1
+
2
+ """
3
+ teslafleetmanagementapi
4
+
5
+ This file was automatically generated by APIMATIC v3.0 (
6
+ https://www.apimatic.io ).
7
+ """
8
+
9
+ from apimatic_core_interfaces.types.http_method_enum import (
10
+ HttpMethodEnum as CoreHttpMethodEnum,
11
+ )
12
+
13
+
14
+ class HttpMethodEnum(CoreHttpMethodEnum):
15
+ """
16
+ Enumeration of an HTTP Method
17
+
18
+ Attributes:
19
+ GET: A GET Request
20
+ POST: A POST Request
21
+ PUT: A PUT Request
22
+ PATCH: A PATCH Request
23
+ DELETE: A DELETE Request
24
+
25
+ """