tesla-api-sdk 1.0.0
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.
- checksums.yaml +7 -0
- data/LICENSE +28 -0
- data/README.md +160 -0
- data/bin/console +15 -0
- data/lib/tesla_fleet_management_api/api_helper.rb +10 -0
- data/lib/tesla_fleet_management_api/client.rb +110 -0
- data/lib/tesla_fleet_management_api/configuration.rb +181 -0
- data/lib/tesla_fleet_management_api/controllers/base_controller.rb +65 -0
- data/lib/tesla_fleet_management_api/controllers/charging_controller.rb +62 -0
- data/lib/tesla_fleet_management_api/controllers/energy_controller.rb +315 -0
- data/lib/tesla_fleet_management_api/controllers/oauth_authorization_controller.rb +87 -0
- data/lib/tesla_fleet_management_api/controllers/partner_controller.rb +82 -0
- data/lib/tesla_fleet_management_api/controllers/user_controller.rb +73 -0
- data/lib/tesla_fleet_management_api/controllers/vehicles_controller.rb +431 -0
- data/lib/tesla_fleet_management_api/exceptions/api_exception.rb +21 -0
- data/lib/tesla_fleet_management_api/exceptions/oauth_provider_exception.rb +64 -0
- data/lib/tesla_fleet_management_api/http/api_response.rb +19 -0
- data/lib/tesla_fleet_management_api/http/auth/bearer_auth.rb +53 -0
- data/lib/tesla_fleet_management_api/http/auth/oauth_2.rb +154 -0
- data/lib/tesla_fleet_management_api/http/http_call_back.rb +10 -0
- data/lib/tesla_fleet_management_api/http/http_method_enum.rb +10 -0
- data/lib/tesla_fleet_management_api/http/http_request.rb +10 -0
- data/lib/tesla_fleet_management_api/http/http_response.rb +10 -0
- data/lib/tesla_fleet_management_api/http/proxy_settings.rb +22 -0
- data/lib/tesla_fleet_management_api/logging/configuration/api_logging_configuration.rb +186 -0
- data/lib/tesla_fleet_management_api/logging/sdk_logger.rb +17 -0
- data/lib/tesla_fleet_management_api/models/api1_dx_vehicles_options_response.rb +76 -0
- data/lib/tesla_fleet_management_api/models/api1_dx_warranty_details_response.rb +76 -0
- data/lib/tesla_fleet_management_api/models/api1_vehicles_mobile_enabled_response.rb +75 -0
- data/lib/tesla_fleet_management_api/models/api1_vehicles_nearby_charging_sites_response.rb +75 -0
- data/lib/tesla_fleet_management_api/models/api1_vehicles_response.rb +104 -0
- data/lib/tesla_fleet_management_api/models/api1_vehicles_response_get_vehicle.rb +75 -0
- data/lib/tesla_fleet_management_api/models/api1_vehicles_wake_up_response.rb +75 -0
- data/lib/tesla_fleet_management_api/models/backup_request.rb +75 -0
- data/lib/tesla_fleet_management_api/models/backup_response.rb +73 -0
- data/lib/tesla_fleet_management_api/models/base_model.rb +110 -0
- data/lib/tesla_fleet_management_api/models/calendar_history_response.rb +73 -0
- data/lib/tesla_fleet_management_api/models/charge_duration.rb +73 -0
- data/lib/tesla_fleet_management_api/models/charge_history.rb +96 -0
- data/lib/tesla_fleet_management_api/models/charge_history_response.rb +73 -0
- data/lib/tesla_fleet_management_api/models/charge_start_time.rb +73 -0
- data/lib/tesla_fleet_management_api/models/charging_dimension.rb +85 -0
- data/lib/tesla_fleet_management_api/models/charging_fee.rb +312 -0
- data/lib/tesla_fleet_management_api/models/charging_history_data.rb +81 -0
- data/lib/tesla_fleet_management_api/models/charging_history_item.rb +222 -0
- data/lib/tesla_fleet_management_api/models/charging_history_response.rb +73 -0
- data/lib/tesla_fleet_management_api/models/charging_invoice.rb +95 -0
- data/lib/tesla_fleet_management_api/models/charging_location.rb +158 -0
- data/lib/tesla_fleet_management_api/models/charging_period.rb +96 -0
- data/lib/tesla_fleet_management_api/models/charging_session.rb +187 -0
- data/lib/tesla_fleet_management_api/models/charging_sessions_data.rb +116 -0
- data/lib/tesla_fleet_management_api/models/charging_sessions_response.rb +73 -0
- data/lib/tesla_fleet_management_api/models/default_real_mode.rb +36 -0
- data/lib/tesla_fleet_management_api/models/driver.rb +164 -0
- data/lib/tesla_fleet_management_api/models/drivers_response.rb +94 -0
- data/lib/tesla_fleet_management_api/models/enterprise_payer_request.rb +94 -0
- data/lib/tesla_fleet_management_api/models/event.rb +89 -0
- data/lib/tesla_fleet_management_api/models/fleet_status_request.rb +74 -0
- data/lib/tesla_fleet_management_api/models/fleet_telemetry_error.rb +90 -0
- data/lib/tesla_fleet_management_api/models/fleet_telemetry_errors_response.rb +74 -0
- data/lib/tesla_fleet_management_api/models/fleet_telemetry_jws_request.rb +85 -0
- data/lib/tesla_fleet_management_api/models/generic_update_response.rb +73 -0
- data/lib/tesla_fleet_management_api/models/kind.rb +36 -0
- data/lib/tesla_fleet_management_api/models/kind_get_wall_connector_charging_history.rb +26 -0
- data/lib/tesla_fleet_management_api/models/live_status_response.rb +73 -0
- data/lib/tesla_fleet_management_api/models/location.rb +85 -0
- data/lib/tesla_fleet_management_api/models/location1.rb +85 -0
- data/lib/tesla_fleet_management_api/models/me_response.rb +73 -0
- data/lib/tesla_fleet_management_api/models/mobile_enabled.rb +85 -0
- data/lib/tesla_fleet_management_api/models/oauth_provider_error.rb +62 -0
- data/lib/tesla_fleet_management_api/models/oauth_token.rb +96 -0
- data/lib/tesla_fleet_management_api/models/off_grid_vehicle_charging_reserve_request.rb +79 -0
- data/lib/tesla_fleet_management_api/models/operation_request.rb +75 -0
- data/lib/tesla_fleet_management_api/models/orders_response.rb +91 -0
- data/lib/tesla_fleet_management_api/models/pagination.rb +127 -0
- data/lib/tesla_fleet_management_api/models/price_component.rb +95 -0
- data/lib/tesla_fleet_management_api/models/products_response.rb +85 -0
- data/lib/tesla_fleet_management_api/models/public_key_response.rb +73 -0
- data/lib/tesla_fleet_management_api/models/region_response.rb +73 -0
- data/lib/tesla_fleet_management_api/models/register_partner_request.rb +73 -0
- data/lib/tesla_fleet_management_api/models/register_partner_response.rb +73 -0
- data/lib/tesla_fleet_management_api/models/response.rb +82 -0
- data/lib/tesla_fleet_management_api/models/response1.rb +75 -0
- data/lib/tesla_fleet_management_api/models/response2.rb +74 -0
- data/lib/tesla_fleet_management_api/models/response3.rb +115 -0
- data/lib/tesla_fleet_management_api/models/response_api1_dx_vehicles_options_response.rb +84 -0
- data/lib/tesla_fleet_management_api/models/response_api1_dx_warranty_details_response.rb +124 -0
- data/lib/tesla_fleet_management_api/models/response_calendar_history_response.rb +91 -0
- data/lib/tesla_fleet_management_api/models/response_charge_history_response.rb +83 -0
- data/lib/tesla_fleet_management_api/models/response_fleet_telemetry_errors_response.rb +83 -0
- data/lib/tesla_fleet_management_api/models/response_live_status_response.rb +196 -0
- data/lib/tesla_fleet_management_api/models/response_me_response.rb +102 -0
- data/lib/tesla_fleet_management_api/models/response_orders_response.rb +157 -0
- data/lib/tesla_fleet_management_api/models/response_public_key_response.rb +74 -0
- data/lib/tesla_fleet_management_api/models/response_region_response.rb +83 -0
- data/lib/tesla_fleet_management_api/models/response_register_partner_response.rb +223 -0
- data/lib/tesla_fleet_management_api/models/signaling.rb +94 -0
- data/lib/tesla_fleet_management_api/models/simple_ok_response.rb +75 -0
- data/lib/tesla_fleet_management_api/models/site_info_response.rb +75 -0
- data/lib/tesla_fleet_management_api/models/storm_mode_request.rb +73 -0
- data/lib/tesla_fleet_management_api/models/tariff_element.rb +95 -0
- data/lib/tesla_fleet_management_api/models/tariffs.rb +94 -0
- data/lib/tesla_fleet_management_api/models/time_of_use_settings_request.rb +74 -0
- data/lib/tesla_fleet_management_api/models/total_cost.rb +95 -0
- data/lib/tesla_fleet_management_api/models/tou_settings.rb +77 -0
- data/lib/tesla_fleet_management_api/models/vehicle_base.rb +147 -0
- data/lib/tesla_fleet_management_api/models/vehicle_option.rb +107 -0
- data/lib/tesla_fleet_management_api/models/warranty_item.rb +155 -0
- data/lib/tesla_fleet_management_api/utilities/date_time_helper.rb +11 -0
- data/lib/tesla_fleet_management_api/utilities/file_wrapper.rb +28 -0
- data/lib/tesla_fleet_management_api.rb +153 -0
- metadata +195 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e0d2c59ada8fe4a1d1f361431367412ed21cae6b749642781a77778a75061f3d
|
|
4
|
+
data.tar.gz: 420d9fae93d5a8ef5a10bbf52ff38b92e55fd86fdf098aef75f86b7e49f400c8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e78c6d2c472a55310a5fffc0d12ae4ac377b4215819fc394d1479d6c94ff589afac0071b84332727af0e3912a1a0767922c25cfcb94da37875712bbe86c886f5
|
|
7
|
+
data.tar.gz: 05e01298e85f299d587a3947ec4f2b1e04ba2a5d33ac8b986c0c1f03db6cd4ca493c555e9f1396526a621dc9dca6bcdfa903feb606551b74c5a6209aaad076c4
|
data/LICENSE
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
License:
|
|
2
|
+
========
|
|
3
|
+
The MIT License (MIT)
|
|
4
|
+
http://opensource.org/licenses/MIT
|
|
5
|
+
|
|
6
|
+
Copyright (c) 2014 - 2026 APIMATIC Limited
|
|
7
|
+
|
|
8
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
in the Software without restriction, including without limitation the rights
|
|
11
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
furnished to do so, subject to the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be included in
|
|
16
|
+
all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
THE SOFTWARE.
|
|
25
|
+
|
|
26
|
+
Trade Mark:
|
|
27
|
+
==========
|
|
28
|
+
APIMATIC is a trade mark for APIMATIC Limited
|
data/README.md
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
|
|
2
|
+
# Getting Started with Tesla Fleet Management API
|
|
3
|
+
|
|
4
|
+
## Introduction
|
|
5
|
+
|
|
6
|
+
Unofficial OpenAPI specification for Tesla Fleet Management Charging endpoints.
|
|
7
|
+
|
|
8
|
+
## Install the Package
|
|
9
|
+
|
|
10
|
+
Install the gem from the command line:
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
gem install tesla-api-sdk -v 1.0.0
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or add the gem to your Gemfile and run `bundle`:
|
|
17
|
+
|
|
18
|
+
```ruby
|
|
19
|
+
gem 'tesla-api-sdk', '1.0.0'
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
For additional gem details, see the [RubyGems page for the tesla-api-sdk gem](https://rubygems.org/gems/tesla-api-sdk/versions/1.0.0).
|
|
23
|
+
|
|
24
|
+
## IRB Console Usage
|
|
25
|
+
|
|
26
|
+
You can explore the SDK interactively using IRB in two ways
|
|
27
|
+
|
|
28
|
+
### 1. Use IRB with Installed Gem
|
|
29
|
+
|
|
30
|
+
Open your system terminal (Command Prompt, Git Bash or macOS Terminal) and type the following command to start the irb console.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
irb
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Now you can load the SDK in the IRB
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
require 'tesla_fleet_management_api'
|
|
40
|
+
include TeslaFleetManagementApi
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### 2. Use IRB within SDK
|
|
44
|
+
|
|
45
|
+
Open your system terminal (Command Prompt, Git Bash or macOS Terminal) and navigate to the root folder of SDK.
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
cd path/to/tesla_fleet_management_api
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Now you can start the preconfigured irb console by running the following command
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
ruby bin/console
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**_Note:_** This automatically loads the SDK from lib/
|
|
58
|
+
|
|
59
|
+
## Initialize the API Client
|
|
60
|
+
|
|
61
|
+
**_Note:_** Documentation for the client can be found [here.](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/client.md)
|
|
62
|
+
|
|
63
|
+
The following parameters are configurable for the API Client:
|
|
64
|
+
|
|
65
|
+
| Parameter | Type | Description |
|
|
66
|
+
| --- | --- | --- |
|
|
67
|
+
| environment | `Environment` | The API environment. <br> **Default: `Environment.PRODUCTION`** |
|
|
68
|
+
| connection | `Faraday::Connection` | The Faraday connection object passed by the SDK user for making requests |
|
|
69
|
+
| adapter | `Faraday::Adapter` | The Faraday adapter object passed by the SDK user for performing http requests |
|
|
70
|
+
| timeout | `Float` | The value to use for connection timeout. <br> **Default: 60** |
|
|
71
|
+
| max_retries | `Integer` | The number of times to retry an endpoint call if it fails. <br> **Default: 0** |
|
|
72
|
+
| retry_interval | `Float` | Pause in seconds between retries. <br> **Default: 1** |
|
|
73
|
+
| backoff_factor | `Float` | The amount to multiply each successive retry's interval amount by in order to provide backoff. <br> **Default: 2** |
|
|
74
|
+
| retry_statuses | `Array` | A list of HTTP statuses to retry. <br> **Default: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524]** |
|
|
75
|
+
| retry_methods | `Array` | A list of HTTP methods to retry. <br> **Default: %i[get put]** |
|
|
76
|
+
| http_callback | `HttpCallBack` | The Http CallBack allows defining callables for pre and post API calls. |
|
|
77
|
+
| proxy_settings | [`ProxySettings`](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/proxy-settings.md) | Optional proxy configuration to route HTTP requests through a proxy server. |
|
|
78
|
+
| logging_configuration | [`LoggingConfiguration`](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/logging-configuration.md) | The SDK logging configuration for API calls |
|
|
79
|
+
| bearer_auth_credentials | [`BearerAuthCredentials`](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/auth/oauth-2-bearer-token.md) | The credential object for OAuth 2 Bearer token |
|
|
80
|
+
| oauth_2_credentials | [`Oauth2Credentials`](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/auth/oauth-2-authorization-code-grant.md) | The credential object for OAuth 2 Authorization Code Grant |
|
|
81
|
+
|
|
82
|
+
The API client can be initialized as follows:
|
|
83
|
+
|
|
84
|
+
### Code-Based Client Initialization
|
|
85
|
+
|
|
86
|
+
```ruby
|
|
87
|
+
require 'tesla_fleet_management_api'
|
|
88
|
+
include TeslaFleetManagementApi
|
|
89
|
+
|
|
90
|
+
client = Client.new(
|
|
91
|
+
bearer_auth_credentials: BearerAuthCredentials.new(
|
|
92
|
+
access_token: 'AccessToken'
|
|
93
|
+
),
|
|
94
|
+
oauth_2_credentials: Oauth2Credentials.new(
|
|
95
|
+
oauth_client_id: 'OAuthClientId',
|
|
96
|
+
oauth_client_secret: 'OAuthClientSecret',
|
|
97
|
+
oauth_redirect_uri: 'OAuthRedirectUri'
|
|
98
|
+
),
|
|
99
|
+
environment: Environment::PRODUCTION,
|
|
100
|
+
logging_configuration: LoggingConfiguration.new(
|
|
101
|
+
log_level: Logger::INFO,
|
|
102
|
+
request_logging_config: RequestLoggingConfiguration.new(
|
|
103
|
+
log_body: true
|
|
104
|
+
),
|
|
105
|
+
response_logging_config: ResponseLoggingConfiguration.new(
|
|
106
|
+
log_headers: true
|
|
107
|
+
)
|
|
108
|
+
)
|
|
109
|
+
)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Environment-Based Client Initialization
|
|
113
|
+
|
|
114
|
+
```ruby
|
|
115
|
+
require 'tesla_fleet_management_api'
|
|
116
|
+
include TeslaFleetManagementApi
|
|
117
|
+
|
|
118
|
+
# Create client from environment
|
|
119
|
+
client = Client.from_env
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
See the [`Environment-Based Client Initialization`](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/environment-based-client-initialization.md) section for details.
|
|
123
|
+
|
|
124
|
+
## Authorization
|
|
125
|
+
|
|
126
|
+
This API uses the following authentication schemes.
|
|
127
|
+
|
|
128
|
+
* [`bearerAuth (OAuth 2 Bearer token)`](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/auth/oauth-2-bearer-token.md)
|
|
129
|
+
* [`oauth2 (OAuth 2 Authorization Code Grant)`](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/auth/oauth-2-authorization-code-grant.md)
|
|
130
|
+
|
|
131
|
+
## List of APIs
|
|
132
|
+
|
|
133
|
+
* [Charging](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/controllers/charging.md)
|
|
134
|
+
* [Energy](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/controllers/energy.md)
|
|
135
|
+
* [Partner](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/controllers/partner.md)
|
|
136
|
+
* [User](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/controllers/user.md)
|
|
137
|
+
* [Vehicles](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/controllers/vehicles.md)
|
|
138
|
+
|
|
139
|
+
## SDK Infrastructure
|
|
140
|
+
|
|
141
|
+
### Configuration
|
|
142
|
+
|
|
143
|
+
* [ProxySettings](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/proxy-settings.md)
|
|
144
|
+
* [Environment-Based Client Initialization](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/environment-based-client-initialization.md)
|
|
145
|
+
* [AbstractLogger](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/abstract-logger.md)
|
|
146
|
+
* [LoggingConfiguration](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/logging-configuration.md)
|
|
147
|
+
* [RequestLoggingConfiguration](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/request-logging-configuration.md)
|
|
148
|
+
* [ResponseLoggingConfiguration](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/response-logging-configuration.md)
|
|
149
|
+
|
|
150
|
+
### HTTP
|
|
151
|
+
|
|
152
|
+
* [HttpResponse](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/http-response.md)
|
|
153
|
+
* [HttpRequest](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/http-request.md)
|
|
154
|
+
|
|
155
|
+
### Utilities
|
|
156
|
+
|
|
157
|
+
* [ApiResponse](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/api-response.md)
|
|
158
|
+
* [ApiHelper](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/api-helper.md)
|
|
159
|
+
* [DateTimeHelper](https://www.github.com/sdks-io/tesla-api-ruby-sdk/tree/1.0.0/doc/date-time-helper.md)
|
|
160
|
+
|
data/bin/console
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# Load the lib folder into Ruby's load path
|
|
4
|
+
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
|
5
|
+
|
|
6
|
+
# Require the gem
|
|
7
|
+
require 'tesla_fleet_management_api'
|
|
8
|
+
|
|
9
|
+
puts 'TeslaFleetManagementApi SDK loaded!'
|
|
10
|
+
puts 'You can now create a client with: client = TeslaFleetManagementApi::Client.new'
|
|
11
|
+
puts 'Or use from_env: client = TeslaFleetManagementApi::Client.from_env'
|
|
12
|
+
|
|
13
|
+
# Start an interactive IRB session
|
|
14
|
+
require 'irb'
|
|
15
|
+
IRB.start
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# tesla_fleet_management_api
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by
|
|
4
|
+
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module TeslaFleetManagementApi
|
|
7
|
+
# tesla_fleet_management_api client class.
|
|
8
|
+
class Client
|
|
9
|
+
include CoreLibrary
|
|
10
|
+
attr_reader :config, :auth_managers
|
|
11
|
+
|
|
12
|
+
def user_agent_detail
|
|
13
|
+
config.user_agent_detail
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Returns the configured authentication oauth2 instance.
|
|
17
|
+
def oauth_2
|
|
18
|
+
@auth_managers['oauth2']
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Access to charging controller.
|
|
22
|
+
# @return [ChargingController] Returns the controller instance.
|
|
23
|
+
def charging
|
|
24
|
+
@charging ||= ChargingController.new @global_configuration
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# Access to energy controller.
|
|
28
|
+
# @return [EnergyController] Returns the controller instance.
|
|
29
|
+
def energy
|
|
30
|
+
@energy ||= EnergyController.new @global_configuration
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Access to partner controller.
|
|
34
|
+
# @return [PartnerController] Returns the controller instance.
|
|
35
|
+
def partner
|
|
36
|
+
@partner ||= PartnerController.new @global_configuration
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# Access to user controller.
|
|
40
|
+
# @return [UserController] Returns the controller instance.
|
|
41
|
+
def user
|
|
42
|
+
@user ||= UserController.new @global_configuration
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Access to vehicles controller.
|
|
46
|
+
# @return [VehiclesController] Returns the controller instance.
|
|
47
|
+
def vehicles
|
|
48
|
+
@vehicles ||= VehiclesController.new @global_configuration
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Access to oauth_authorization controller.
|
|
52
|
+
# @return [OauthAuthorizationController] Returns the controller instance.
|
|
53
|
+
def oauth_authorization
|
|
54
|
+
@oauth_authorization ||= OauthAuthorizationController.new @global_configuration
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def initialize(
|
|
58
|
+
connection: nil, adapter: :net_http_persistent, timeout: 60,
|
|
59
|
+
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
|
60
|
+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
|
61
|
+
retry_methods: %i[get put], http_callback: nil, proxy_settings: nil,
|
|
62
|
+
logging_configuration: nil, environment: Environment::PRODUCTION,
|
|
63
|
+
bearer_auth_credentials: nil, oauth_2_credentials: nil, config: nil
|
|
64
|
+
)
|
|
65
|
+
@config = if config.nil?
|
|
66
|
+
Configuration.new(
|
|
67
|
+
connection: connection, adapter: adapter, timeout: timeout,
|
|
68
|
+
max_retries: max_retries, retry_interval: retry_interval,
|
|
69
|
+
backoff_factor: backoff_factor,
|
|
70
|
+
retry_statuses: retry_statuses,
|
|
71
|
+
retry_methods: retry_methods, http_callback: http_callback,
|
|
72
|
+
proxy_settings: proxy_settings,
|
|
73
|
+
logging_configuration: logging_configuration,
|
|
74
|
+
environment: environment,
|
|
75
|
+
bearer_auth_credentials: bearer_auth_credentials,
|
|
76
|
+
oauth_2_credentials: oauth_2_credentials
|
|
77
|
+
)
|
|
78
|
+
else
|
|
79
|
+
config
|
|
80
|
+
end
|
|
81
|
+
user_agent_params = BaseController.user_agent_parameters
|
|
82
|
+
|
|
83
|
+
@global_configuration = GlobalConfiguration.new(client_configuration: @config)
|
|
84
|
+
.base_uri_executor(@config.method(:get_base_uri))
|
|
85
|
+
.global_errors(BaseController::GLOBAL_ERRORS)
|
|
86
|
+
.user_agent(BaseController.user_agent,
|
|
87
|
+
agent_parameters: user_agent_params)
|
|
88
|
+
|
|
89
|
+
initialize_auth_managers(@global_configuration)
|
|
90
|
+
@global_configuration = @global_configuration.auth_managers(@auth_managers)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# Initializes the auth managers hash used for authenticating API calls.
|
|
94
|
+
# @param [GlobalConfiguration] global_config The global configuration of the SDK)
|
|
95
|
+
def initialize_auth_managers(global_config)
|
|
96
|
+
@auth_managers = {}
|
|
97
|
+
http_client_config = global_config.client_configuration
|
|
98
|
+
%w[bearerAuth oauth2].each { |auth| @auth_managers[auth] = nil }
|
|
99
|
+
@auth_managers['bearerAuth'] = BearerAuth.new(http_client_config.bearer_auth_credentials)
|
|
100
|
+
@auth_managers['oauth2'] = Oauth2.new(http_client_config.oauth_2_credentials, global_config)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# Creates a client directly from environment variables.
|
|
104
|
+
def self.from_env(**overrides)
|
|
105
|
+
default_config = Configuration.build_default_config_from_env
|
|
106
|
+
new_config = default_config.clone_with(**overrides)
|
|
107
|
+
new(config: new_config)
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
# tesla_fleet_management_api
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by
|
|
4
|
+
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module TeslaFleetManagementApi
|
|
7
|
+
# An enum for SDK environments.
|
|
8
|
+
class Environment
|
|
9
|
+
# PRODUCTION: Production
|
|
10
|
+
ENVIRONMENT = [
|
|
11
|
+
PRODUCTION = 'production'.freeze
|
|
12
|
+
].freeze
|
|
13
|
+
|
|
14
|
+
# Converts a string or symbol into a valid Environment constant.
|
|
15
|
+
def self.from_value(value, default_value = PRODUCTION)
|
|
16
|
+
return default_value if value.nil?
|
|
17
|
+
|
|
18
|
+
default_value
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# An enum for API servers.
|
|
23
|
+
class Server
|
|
24
|
+
SERVER = [
|
|
25
|
+
DEFAULT = 'default'.freeze,
|
|
26
|
+
AUTH_SERVER = 'auth server'.freeze
|
|
27
|
+
].freeze
|
|
28
|
+
|
|
29
|
+
# Converts a string or symbol into a valid Server constant.
|
|
30
|
+
def self.from_value(value, default_value = DEFAULT)
|
|
31
|
+
return default_value if value.nil?
|
|
32
|
+
|
|
33
|
+
str = value.to_s.strip.downcase
|
|
34
|
+
case str
|
|
35
|
+
when 'default' then DEFAULT
|
|
36
|
+
when 'auth_server' then AUTH_SERVER
|
|
37
|
+
|
|
38
|
+
else
|
|
39
|
+
warn "[Server] Unknown server '#{value}', falling back to #{default_value} "
|
|
40
|
+
default_value
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# All configuration including auth info and base URI for the API access
|
|
46
|
+
# are configured in this class.
|
|
47
|
+
class Configuration < CoreLibrary::HttpClientConfiguration
|
|
48
|
+
# The attribute readers for properties.
|
|
49
|
+
attr_reader :environment, :bearer_auth_credentials, :oauth_2_credentials
|
|
50
|
+
|
|
51
|
+
class << self
|
|
52
|
+
attr_reader :environments
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def initialize(
|
|
56
|
+
connection: nil, adapter: :net_http_persistent, timeout: 60,
|
|
57
|
+
max_retries: 0, retry_interval: 1, backoff_factor: 2,
|
|
58
|
+
retry_statuses: [408, 413, 429, 500, 502, 503, 504, 521, 522, 524],
|
|
59
|
+
retry_methods: %i[get put], http_callback: nil, proxy_settings: nil,
|
|
60
|
+
logging_configuration: nil, environment: Environment::PRODUCTION,
|
|
61
|
+
bearer_auth_credentials: nil, oauth_2_credentials: nil
|
|
62
|
+
)
|
|
63
|
+
super connection: connection, adapter: adapter, timeout: timeout,
|
|
64
|
+
max_retries: max_retries, retry_interval: retry_interval,
|
|
65
|
+
backoff_factor: backoff_factor, retry_statuses: retry_statuses,
|
|
66
|
+
retry_methods: retry_methods, http_callback: http_callback,
|
|
67
|
+
proxy_settings: proxy_settings,
|
|
68
|
+
logging_configuration: logging_configuration
|
|
69
|
+
|
|
70
|
+
# Current API environment
|
|
71
|
+
@environment = String(environment)
|
|
72
|
+
|
|
73
|
+
# The object holding OAuth 2 Bearer token credentials
|
|
74
|
+
@bearer_auth_credentials = bearer_auth_credentials
|
|
75
|
+
|
|
76
|
+
# The object holding OAuth 2 Authorization Code Grant credentials
|
|
77
|
+
@oauth_2_credentials = oauth_2_credentials
|
|
78
|
+
|
|
79
|
+
# The Http Client to use for making requests.
|
|
80
|
+
set_http_client CoreLibrary::FaradayClient.new(self)
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def clone_with(connection: nil, adapter: nil, timeout: nil,
|
|
84
|
+
max_retries: nil, retry_interval: nil, backoff_factor: nil,
|
|
85
|
+
retry_statuses: nil, retry_methods: nil, http_callback: nil,
|
|
86
|
+
proxy_settings: nil, logging_configuration: nil,
|
|
87
|
+
environment: nil, bearer_auth_credentials: nil,
|
|
88
|
+
oauth_2_credentials: nil)
|
|
89
|
+
connection ||= self.connection
|
|
90
|
+
adapter ||= self.adapter
|
|
91
|
+
timeout ||= self.timeout
|
|
92
|
+
max_retries ||= self.max_retries
|
|
93
|
+
retry_interval ||= self.retry_interval
|
|
94
|
+
backoff_factor ||= self.backoff_factor
|
|
95
|
+
retry_statuses ||= self.retry_statuses
|
|
96
|
+
retry_methods ||= self.retry_methods
|
|
97
|
+
http_callback ||= self.http_callback
|
|
98
|
+
proxy_settings ||= self.proxy_settings
|
|
99
|
+
logging_configuration ||= self.logging_configuration
|
|
100
|
+
environment ||= self.environment
|
|
101
|
+
bearer_auth_credentials ||= self.bearer_auth_credentials
|
|
102
|
+
oauth_2_credentials ||= self.oauth_2_credentials
|
|
103
|
+
|
|
104
|
+
Configuration.new(connection: connection, adapter: adapter,
|
|
105
|
+
timeout: timeout, max_retries: max_retries,
|
|
106
|
+
retry_interval: retry_interval,
|
|
107
|
+
backoff_factor: backoff_factor,
|
|
108
|
+
retry_statuses: retry_statuses,
|
|
109
|
+
retry_methods: retry_methods,
|
|
110
|
+
http_callback: http_callback,
|
|
111
|
+
proxy_settings: proxy_settings,
|
|
112
|
+
logging_configuration: logging_configuration,
|
|
113
|
+
environment: environment,
|
|
114
|
+
bearer_auth_credentials: bearer_auth_credentials,
|
|
115
|
+
oauth_2_credentials: oauth_2_credentials)
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
# All the environments the SDK can run in.
|
|
120
|
+
ENVIRONMENTS = {
|
|
121
|
+
Environment::PRODUCTION => {
|
|
122
|
+
Server::DEFAULT => 'https://fleet-api.prd.na.vn.cloud.tesla.com',
|
|
123
|
+
Server::AUTH_SERVER => 'https://auth.tesla.com/oauth2/v3'
|
|
124
|
+
}
|
|
125
|
+
}.freeze
|
|
126
|
+
|
|
127
|
+
# Generates the appropriate base URI for the environment and the server.
|
|
128
|
+
# @param [Configuration::Server] server The server enum for which the base URI is
|
|
129
|
+
# required.
|
|
130
|
+
# @return [String] The base URI.
|
|
131
|
+
def get_base_uri(server = Server::DEFAULT)
|
|
132
|
+
ENVIRONMENTS[environment][server].clone
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Builds a Configuration instance using environment variables.
|
|
136
|
+
def self.build_default_config_from_env
|
|
137
|
+
# === Core environment ===
|
|
138
|
+
environment = Environment.from_value(ENV.fetch('ENVIRONMENT', 'production'))
|
|
139
|
+
timeout = (ENV['TIMEOUT'] || 60).to_f
|
|
140
|
+
max_retries = (ENV['MAX_RETRIES'] || 0).to_i
|
|
141
|
+
retry_interval = (ENV['RETRY_INTERVAL'] || 1).to_f
|
|
142
|
+
backoff_factor = (ENV['BACKOFF_FACTOR'] || 2).to_f
|
|
143
|
+
retry_statuses = ENV.fetch('RETRY_STATUSES',
|
|
144
|
+
'[408, 413, 429, 500, 502, 503, 504, 521, 522, 524]').gsub(/[\[\]]/, '')
|
|
145
|
+
.split(',')
|
|
146
|
+
.map(&:strip)
|
|
147
|
+
.map do |item|
|
|
148
|
+
item.match?(/\A\d+\z/) ? item.to_i : item.downcase
|
|
149
|
+
end
|
|
150
|
+
retry_methods = ENV.fetch('RETRY_METHODS', '%i[get put]').gsub(/[\[\]]/, '')
|
|
151
|
+
.split(',')
|
|
152
|
+
.map(&:strip)
|
|
153
|
+
.map do |item|
|
|
154
|
+
item.match?(/\A\d+\z/) ? item.to_i : item.downcase
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
# === Authentication credentials ===
|
|
158
|
+
bearer_auth_credentials = BearerAuthCredentials.from_env
|
|
159
|
+
oauth_2_credentials = Oauth2Credentials.from_env
|
|
160
|
+
|
|
161
|
+
# === Proxy settings ===
|
|
162
|
+
proxy_settings = ProxySettings.from_env
|
|
163
|
+
# === Logging Configuration ===
|
|
164
|
+
logging_configuration = LoggingConfiguration.from_env if LoggingConfiguration.any_logging_configured?
|
|
165
|
+
|
|
166
|
+
Configuration.new(
|
|
167
|
+
environment: environment,
|
|
168
|
+
timeout: timeout,
|
|
169
|
+
max_retries: max_retries,
|
|
170
|
+
retry_interval: retry_interval,
|
|
171
|
+
backoff_factor: backoff_factor,
|
|
172
|
+
retry_statuses: retry_statuses,
|
|
173
|
+
retry_methods: retry_methods,
|
|
174
|
+
bearer_auth_credentials: bearer_auth_credentials,
|
|
175
|
+
oauth_2_credentials: oauth_2_credentials,
|
|
176
|
+
proxy_settings: proxy_settings,
|
|
177
|
+
logging_configuration: logging_configuration
|
|
178
|
+
)
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# tesla_fleet_management_api
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by
|
|
4
|
+
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module TeslaFleetManagementApi
|
|
7
|
+
# BaseController.
|
|
8
|
+
class BaseController
|
|
9
|
+
include CoreLibrary
|
|
10
|
+
attr_accessor :config, :http_call_back
|
|
11
|
+
|
|
12
|
+
def self.user_agent
|
|
13
|
+
'Ruby SDK, Version: 1.0.0, on OS {os-info}'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.user_agent_parameters
|
|
17
|
+
{
|
|
18
|
+
'{os-info}' => { 'value' => RUBY_PLATFORM, 'encode' => false }
|
|
19
|
+
}
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
GLOBAL_ERRORS = {
|
|
23
|
+
'default' => ErrorCase.new
|
|
24
|
+
.error_message('HTTP response not OK.')
|
|
25
|
+
.exception_type(APIException)
|
|
26
|
+
}.freeze
|
|
27
|
+
|
|
28
|
+
# Initialization constructor.
|
|
29
|
+
# @param [GlobalConfiguration] global_configuration The instance of GlobalConfiguration.
|
|
30
|
+
def initialize(global_configuration)
|
|
31
|
+
@global_configuration = global_configuration
|
|
32
|
+
@config = @global_configuration.client_configuration
|
|
33
|
+
@http_call_back = @config.http_callback
|
|
34
|
+
@api_call = ApiCall.new(@global_configuration)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Creates a new instance of the request builder.
|
|
38
|
+
# @param [String] http_method The HTTP method to use in the request.
|
|
39
|
+
# @param [String] path The endpoint path to use in the request.
|
|
40
|
+
# @param [String] server The server to extract the base uri for the request.
|
|
41
|
+
# @return [RequestBuilder] The instance of RequestBuilder.
|
|
42
|
+
def new_request_builder(http_method, path, server)
|
|
43
|
+
RequestBuilder.new
|
|
44
|
+
.http_method(http_method)
|
|
45
|
+
.path(path)
|
|
46
|
+
.server(server)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Creates a new instance of the response handler.
|
|
50
|
+
# @return [ResponseHandler] The instance of ResponseHandler.
|
|
51
|
+
def new_response_handler
|
|
52
|
+
ResponseHandler.new
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Creates a new instance of the parameter.
|
|
56
|
+
# @param [String|optional] key The key of the parameter.
|
|
57
|
+
# @param [Object] value The value of the parameter.
|
|
58
|
+
# @return [Parameter] The instance of Parameter.
|
|
59
|
+
def new_parameter(value, key: nil)
|
|
60
|
+
Parameter.new
|
|
61
|
+
.key(key)
|
|
62
|
+
.value(value)
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# tesla_fleet_management_api
|
|
2
|
+
#
|
|
3
|
+
# This file was automatically generated by
|
|
4
|
+
# APIMATIC v3.0 ( https://www.apimatic.io ).
|
|
5
|
+
|
|
6
|
+
module TeslaFleetManagementApi
|
|
7
|
+
# ChargingController
|
|
8
|
+
class ChargingController < BaseController
|
|
9
|
+
# Returns the paginated charging history for the authenticated account.
|
|
10
|
+
# @return [ApiResponse] Complete http response with raw body and status code.
|
|
11
|
+
def get_charging_history
|
|
12
|
+
@api_call
|
|
13
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
|
14
|
+
'/api/1/dx/charging/history',
|
|
15
|
+
Server::DEFAULT)
|
|
16
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
|
17
|
+
.auth(Single.new('bearerAuth')))
|
|
18
|
+
.response(new_response_handler
|
|
19
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
|
20
|
+
.deserialize_into(ChargingHistoryResponse.method(:from_hash))
|
|
21
|
+
.is_api_response(true))
|
|
22
|
+
.execute
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Returns a charging invoice PDF for a charging session.
|
|
26
|
+
# @param [String] id Required parameter: Charging session invoice
|
|
27
|
+
# identifier
|
|
28
|
+
# @return [ApiResponse] Complete http response with raw body and status code.
|
|
29
|
+
def get_charging_invoice(id)
|
|
30
|
+
@api_call
|
|
31
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
|
32
|
+
'/api/1/dx/charging/invoice/{id}',
|
|
33
|
+
Server::DEFAULT)
|
|
34
|
+
.template_param(new_parameter(id, key: 'id')
|
|
35
|
+
.is_required(true)
|
|
36
|
+
.should_encode(true))
|
|
37
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
|
38
|
+
.auth(Single.new('bearerAuth')))
|
|
39
|
+
.response(new_response_handler
|
|
40
|
+
.deserializer(APIHelper.method(:dynamic_deserializer))
|
|
41
|
+
.is_api_response(true))
|
|
42
|
+
.execute
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Returns charging session information. Only available for business fleet
|
|
46
|
+
# owners.
|
|
47
|
+
# @return [ApiResponse] Complete http response with raw body and status code.
|
|
48
|
+
def get_charging_sessions
|
|
49
|
+
@api_call
|
|
50
|
+
.request(new_request_builder(HttpMethodEnum::GET,
|
|
51
|
+
'/api/1/dx/charging/sessions',
|
|
52
|
+
Server::DEFAULT)
|
|
53
|
+
.header_param(new_parameter('application/json', key: 'accept'))
|
|
54
|
+
.auth(Single.new('bearerAuth')))
|
|
55
|
+
.response(new_response_handler
|
|
56
|
+
.deserializer(APIHelper.method(:custom_type_deserializer))
|
|
57
|
+
.deserialize_into(ChargingSessionsResponse.method(:from_hash))
|
|
58
|
+
.is_api_response(true))
|
|
59
|
+
.execute
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|