tesla_api 1.5.0 → 2.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 +4 -4
- data/.tool-versions +1 -0
- data/.travis.yml +6 -2
- data/docs/miscellaneous/endpoints.md +6 -1
- data/docs/vehicle/optioncodes.md +104 -23
- data/docs/vehicle/state/data.md +2 -0
- data/docs/vehicle/state/vehiclestate.md +9 -0
- data/lib/tesla_api/client.rb +51 -22
- data/lib/tesla_api/version.rb +1 -1
- data/spec/cassettes/client-refresh.yml +51 -0
- data/spec/cassettes/vehicle-activate_speed_limit.yml +2 -2
- data/spec/cassettes/vehicle-cancel_software_update.yml +2 -2
- data/spec/cassettes/vehicle-charge_port_door_close.yml +2 -2
- data/spec/cassettes/vehicle-clear_speed_limit_pin.yml +2 -2
- data/spec/cassettes/vehicle-data.yml +2 -2
- data/spec/cassettes/vehicle-deactivate_speed_limit.yml +2 -2
- data/spec/cassettes/vehicle-navigation_request.yml +2 -2
- data/spec/cassettes/vehicle-nearby_charging_sites.yml +2 -2
- data/spec/cassettes/vehicle-open_frunk.yml +2 -2
- data/spec/cassettes/vehicle-open_trunk.yml +2 -2
- data/spec/cassettes/vehicle-reset_valet_pin.yml +2 -2
- data/spec/cassettes/vehicle-schedule_software_update.yml +2 -2
- data/spec/cassettes/vehicle-seat_heater_request.yml +2 -2
- data/spec/cassettes/vehicle-set_sentry_mode.yml +2 -2
- data/spec/cassettes/vehicle-set_speed_limit.yml +2 -2
- data/spec/cassettes/vehicle-set_valet_mode.yml +2 -2
- data/spec/cassettes/vehicle-steering_wheel_heater_request.yml +2 -2
- data/spec/lib/tesla_api/client_spec.rb +59 -43
- data/spec/lib/tesla_api/vehicle_spec.rb +1 -5
- data/spec/spec_helper.rb +2 -2
- data/tesla_api.gemspec +0 -1
- metadata +6 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a0a2c77105e4ceabe402f838427c9efbfb917d7f74b49d3f5f6637e3581e0678
|
|
4
|
+
data.tar.gz: f07b11556f4d3a4a874d68ed9ced60ba40e71f759f251b0449a07fcf1513b8a0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ba1727791cdb0493e9a703e55d3b400d4c59dc300d5e1d463482c3622466f0f6172904c6185273405188735337b42c7ffaf055c1fe1e1b7fbd984a7894f85b34
|
|
7
|
+
data.tar.gz: 5d73d9cf6960742d4d63b013b2ece343879a4809cb4f9dccf4ac1e1dd3f9e36f6b2e3b731bf9675d70a512f6afc6ddea9a03052ab81f65283be26e8cc6124d39
|
data/.tool-versions
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ruby 2.6.4
|
data/.travis.yml
CHANGED
|
@@ -2,11 +2,15 @@ language: ruby
|
|
|
2
2
|
rvm:
|
|
3
3
|
- 2.6
|
|
4
4
|
env:
|
|
5
|
-
global:
|
|
5
|
+
global:
|
|
6
6
|
- TESLA_EMAIL=elon.musk@teslamotors.com
|
|
7
7
|
- TESLA_PASS=oilLOL
|
|
8
8
|
- TESLA_CLIENT_ID=1
|
|
9
9
|
- TESLA_CLIENT_SECRET=2
|
|
10
|
-
-
|
|
10
|
+
- TESLA_ACCESS_TOKEN=3
|
|
11
|
+
- TESLA_REFRESH_TOKEN=4
|
|
12
|
+
before_install:
|
|
13
|
+
- gem update --system
|
|
14
|
+
- gem install bundler
|
|
11
15
|
notifications:
|
|
12
16
|
email: false
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Endpoints File
|
|
2
2
|
|
|
3
|
-
This the latest contents of the ownerapi_endpoints.json file from the 3.
|
|
3
|
+
This the latest contents of the ownerapi_endpoints.json file from the 3.9.0 version of the app.
|
|
4
4
|
|
|
5
5
|
```json
|
|
6
6
|
{
|
|
@@ -415,6 +415,11 @@ This the latest contents of the ownerapi_endpoints.json file from the 3.8.4 vers
|
|
|
415
415
|
"URI": "api/1/energy_sites/{site_id}/history",
|
|
416
416
|
"AUTH": true
|
|
417
417
|
},
|
|
418
|
+
"CALENDAR_HISTORY_DATA": {
|
|
419
|
+
"TYPE": "GET",
|
|
420
|
+
"URI": "api/1/energy_sites/{site_id}/calendar_history",
|
|
421
|
+
"AUTH": true
|
|
422
|
+
},
|
|
418
423
|
"BACKUP_RESERVE": {
|
|
419
424
|
"TYPE": "POST",
|
|
420
425
|
"URI": "api/1/energy_sites/{site_id}/backup",
|
data/docs/vehicle/optioncodes.md
CHANGED
|
@@ -17,6 +17,7 @@ appreciated!_
|
|
|
17
17
|
| MS04 | Model S | This vehicle is a Model S |
|
|
18
18
|
| MDLX | Model X | This vehicle is a Model X |
|
|
19
19
|
| MDL3 | Model 3 | This vehicle is a Model 3 |
|
|
20
|
+
| MDLY | Model Y | This vehicle is a Model Y |
|
|
20
21
|
| RENA | Region: North America | |
|
|
21
22
|
| RENC | Region: Canada | |
|
|
22
23
|
| REEU | Region: Europe | |
|
|
@@ -25,8 +26,17 @@ appreciated!_
|
|
|
25
26
|
| AD05 | European 3-Phase, IT | |
|
|
26
27
|
| AD06 | Schuko (1 phase, 230V 13A) | |
|
|
27
28
|
| AD07 | Red IEC309 (3 phase, 400V 16A) | |
|
|
29
|
+
| AD08 | Blue Charging Adapter | |
|
|
30
|
+
| AD09 | Adapter, Swiss (1 phase, 10A) | |
|
|
31
|
+
| AD10 | Adapter, Denmark (1 phase, 13A) | |
|
|
32
|
+
| AD11 | Adapter, Italy (1 phase, 13A) | |
|
|
28
33
|
| AD15 | ? | |
|
|
29
34
|
| ADPX2 | Type 2 Public Charging Connector | |
|
|
35
|
+
| ADX4 | No European 3-Phase | |
|
|
36
|
+
| ADX5 | European 3-Phase, IT | |
|
|
37
|
+
| ADX6 | No - Adapter, Schuko (1 phase, 13A) | |
|
|
38
|
+
| ADX7 | No - 3-ph Red IEC309 (3 phase, 16A) | |
|
|
39
|
+
| ADX9 | No - Adapter, Swiss (1 phase, 10A) | |
|
|
30
40
|
| ADX8 | Blue IEC309 (1 phase, 230V 32A) | |
|
|
31
41
|
| AF00 | No HEPA Filter | |
|
|
32
42
|
| AF02 | HEPA Filter | |
|
|
@@ -37,15 +47,19 @@ appreciated!_
|
|
|
37
47
|
| APF2 | Full Self-Driving Capability | |
|
|
38
48
|
| APH0 | Autopilot 2.0 Hardware | |
|
|
39
49
|
| APH2 | Autopilot 2.0 Hardware | |
|
|
50
|
+
| APBS | Autopilot | Model 3 Autopilot |
|
|
51
|
+
| APF2 | Full Self-Driving Capability | |
|
|
40
52
|
| APH3 | Autopilot 2.5 Hardware | |
|
|
41
53
|
| APH4 | Autopilot 3.0 Hardware | Full Self-Driving Computer |
|
|
42
54
|
| APPA | Autopilot 1.0 Hardware | |
|
|
43
55
|
| APPB | Enhanced Autopilot | |
|
|
44
56
|
| AU00 | No Audio Package | |
|
|
45
57
|
| AU01 | Ultra High Fidelity Sound | |
|
|
46
|
-
| BC0B |
|
|
47
|
-
| BC0R |
|
|
58
|
+
| BC0B | Black Brake Calipers | |
|
|
59
|
+
| BC0R | Red Brake Calipers | |
|
|
60
|
+
| BC3B | Black Brake Calipers, Model 3 | |
|
|
48
61
|
| BCMB | Black Brake Calipers | |
|
|
62
|
+
| BCYR | Performance Brakes | |
|
|
49
63
|
| BP00 | No Ludicrous | |
|
|
50
64
|
| BP01 | Ludicrous Speed Upgrade | |
|
|
51
65
|
| BR00 | No Battery Firmware Limit | |
|
|
@@ -63,8 +77,13 @@ appreciated!_
|
|
|
63
77
|
| BTX6 | 100 kWh | |
|
|
64
78
|
| BTX7 | 75 kWh | |
|
|
65
79
|
| BTX8 | 85 kWh | |
|
|
80
|
+
| CC01 | Five Seat Interior | |
|
|
81
|
+
| CC02 | Six Seat Interior | |
|
|
66
82
|
| CC04 | Seven Seat Interior | |
|
|
83
|
+
| CC12 | Six Seat Interior with Center Console | |
|
|
67
84
|
| CDM0 | No CHAdeMO Charging Adaptor | |
|
|
85
|
+
| CF00 | High Power Charger | |
|
|
86
|
+
| CF01 | 48amp charger | |
|
|
68
87
|
| CH00 | Standard Charger (40 Amp) | |
|
|
69
88
|
| CH01 | Dual Chargers (80 Amp) | |
|
|
70
89
|
| CH04 | 72 Amp Charger (Model S/X) | |
|
|
@@ -75,7 +94,8 @@ appreciated!_
|
|
|
75
94
|
| COL2 | Metallic | |
|
|
76
95
|
| COL3 | Tesla Multi-Coat | |
|
|
77
96
|
| COUS | Country: United States | |
|
|
78
|
-
| CONL | Country: Netherlands | |
|
|
97
|
+
| CONL | Country: Netherlands | |
|
|
98
|
+
| CPW1 | 20" Performance Wheels | |
|
|
79
99
|
| CW00 | No Cold Weather Package | |
|
|
80
100
|
| CW02 | Subzero Weather Package | |
|
|
81
101
|
| DA00 | No Autopilot | |
|
|
@@ -83,6 +103,7 @@ appreciated!_
|
|
|
83
103
|
| DA02 | Autopilot Convenience Features | |
|
|
84
104
|
| DCF0 | Autopilot Convenience Features (DCF0) | |
|
|
85
105
|
| DRLH | Left Hand Drive | |
|
|
106
|
+
| BC3R | Performance Brakes | Model 3 |
|
|
86
107
|
| DRRH | Right Hand Drive | |
|
|
87
108
|
| DSH5 | PUR Dash Pad | |
|
|
88
109
|
| DSH7 | Alcantara Dashboard Accents | |
|
|
@@ -96,6 +117,7 @@ appreciated!_
|
|
|
96
117
|
| FG02 | Exterior Lighting Package | |
|
|
97
118
|
| FMP6 | FMP6 | |
|
|
98
119
|
| FR01 | Base Front Row | |
|
|
120
|
+
| FR02 | Ventilated Front Seats | |
|
|
99
121
|
| FR03 | FR03 | |
|
|
100
122
|
| FR04 | FR04 | |
|
|
101
123
|
| HC00 | No Home Charging installation | |
|
|
@@ -106,6 +128,7 @@ appreciated!_
|
|
|
106
128
|
| IDBA | Dark Ash Wood Decor | |
|
|
107
129
|
| IDBO | Figured Ash Wood Decor | |
|
|
108
130
|
| IDCF | Carbon Fiber Decor | |
|
|
131
|
+
| IDOK | Oak Decor | |
|
|
109
132
|
| IDOM | Matte Obeche Wood Decor | |
|
|
110
133
|
| IDOG | Gloss Obeche Wood Decor | |
|
|
111
134
|
| IDLW | Lacewood Decor | |
|
|
@@ -120,6 +143,8 @@ appreciated!_
|
|
|
120
143
|
| INLPC | Cream | |
|
|
121
144
|
| INLPP | Black / Light Headliner | |
|
|
122
145
|
| INWPT | Tan Interior | |
|
|
146
|
+
| INYPB | All Black Premium Interior | |
|
|
147
|
+
| INYPW | Black and White Premium Interior | |
|
|
123
148
|
| IVBPP | All Black Interior | |
|
|
124
149
|
| IVBSW | Ultra White Interior | |
|
|
125
150
|
| IVBTB | All Black Interior | |
|
|
@@ -138,53 +163,78 @@ appreciated!_
|
|
|
138
163
|
| LT4W | LT4W | |
|
|
139
164
|
| LT5C | LT5C | |
|
|
140
165
|
| LT5P | LT5P | |
|
|
141
|
-
| LT6P | LT6P | |
|
|
166
|
+
| LT6P | LT6P | |
|
|
167
|
+
| LTPB | Lower Trim PUR Black | |
|
|
168
|
+
| ME01 | Memory Seats | |
|
|
142
169
|
| ME02 | Memory Seats | |
|
|
143
170
|
| MI00 | 2015 Production Refresh | |
|
|
144
171
|
| MI01 | 2016 Production Refresh | |
|
|
145
172
|
| MI02 | 2017 Production Refresh | |
|
|
146
|
-
| MI03 | 201? Production Refresh
|
|
173
|
+
| MI03 | 201? Production Refresh | Found on Model X ordered 11/2018 delivered 3/2019 |
|
|
174
|
+
| MT300 | Standard Range Rear-Wheel Drive | |
|
|
147
175
|
| MT301 | Standard Range Plus Rear-Wheel Drive | |
|
|
176
|
+
| MT302 | Long Range Rear-Wheel Drive | |
|
|
177
|
+
| MT303 | Long Range All-Wheel Drive | |
|
|
178
|
+
| MT304 | Long Range All-Wheel Drive Performance | |
|
|
148
179
|
| MT305 | Mid Range Rear-Wheel Drive | |
|
|
149
|
-
|
|
|
180
|
+
| MTY02 | Long Range Rear-Wheel Drive | |
|
|
181
|
+
| MTY03 | Long Range All-Wheel Drive | |
|
|
182
|
+
| MTY04 | Long Range All-Wheel Drive Performance | |
|
|
183
|
+
| OSSB | Safety CA Black | |
|
|
184
|
+
| OSSW | Safety CA White | |
|
|
150
185
|
| PA00 | No Paint Armor | |
|
|
151
|
-
| PBCW |
|
|
152
|
-
| PBSB |
|
|
186
|
+
| PBCW | Solid White Color | |
|
|
187
|
+
| PBSB | Solid Black Color | |
|
|
153
188
|
| PBT8 | Performance 85kWh | |
|
|
189
|
+
| PC30 | No Performance Chassis | |
|
|
190
|
+
| PC31 | Performance Chassis | |
|
|
154
191
|
| PF00 | No Performance Legacy Package | |
|
|
155
192
|
| PF01 | Performance Legacy Package | |
|
|
156
193
|
| PI00 | No Premium Interior | |
|
|
157
194
|
| PI01 | Premium Upgrades Package | |
|
|
158
195
|
| PK00 | LEGACY No Parking Sensors | |
|
|
159
|
-
| PMAB | Anza Brown Metallic | |
|
|
160
|
-
| PMBL | Obsidian Black Multi-Coat | |
|
|
161
|
-
| PMMB | Monterey Blue Metallic | |
|
|
162
|
-
| PMMR | Multi-Coat
|
|
163
|
-
| PMNG | Midnight Silver Metallic |
|
|
164
|
-
| PMSG |
|
|
165
|
-
| PMSS | San Simeon Silver Metallic | |
|
|
166
|
-
| PMTG | Dolphin Grey Metallic | |
|
|
167
|
-
| PPMR |
|
|
168
|
-
| PPSB | Deep Blue Metallic |
|
|
169
|
-
| PPSR | Signature Red | |
|
|
170
|
-
| PPSW |
|
|
171
|
-
| PPTI | Titanium Metallic | |
|
|
196
|
+
| PMAB | Anza Brown Metallic Color | |
|
|
197
|
+
| PMBL | Obsidian Black Multi-Coat Color | |
|
|
198
|
+
| PMMB | Monterey Blue Metallic Color | |
|
|
199
|
+
| PMMR | Red Multi-Coat Color | |
|
|
200
|
+
| PMNG | Midnight Silver Metallic Color | |
|
|
201
|
+
| PMSG | Green Metallic Color| |
|
|
202
|
+
| PMSS | San Simeon Silver Metallic Color | |
|
|
203
|
+
| PMTG | Dolphin Grey Metallic Color | |
|
|
204
|
+
| PPMR | Red Multi-Coat Color | |
|
|
205
|
+
| PPSB | Deep Blue Metallic Color | |
|
|
206
|
+
| PPSR | Signature Red Color | |
|
|
207
|
+
| PPSW | Pearl White Multi-Coat Color | |
|
|
208
|
+
| PPTI | Titanium Metallic Color | |
|
|
209
|
+
| PL31 | Performance Pedals | Model 3 |
|
|
172
210
|
| PRM30 | Partial Premium Interior | |
|
|
173
211
|
| PRM31 | Premium Interior | |
|
|
212
|
+
| PRM3S | Standard Interior | |
|
|
213
|
+
| PRMY1 | Premium Interior | |
|
|
174
214
|
| PS00 | No Parcel Shelf | |
|
|
175
215
|
| PS01 | Parcel Shelf | |
|
|
176
216
|
| PX00 | No Performance Plus Package | |
|
|
177
217
|
| PX01 | Performance Plus | |
|
|
178
218
|
| PX6D | Zero to 60 in 2.5 sec | |
|
|
179
219
|
| P85D | P85D | |
|
|
220
|
+
| QLBS | Black Premium Interior | |
|
|
221
|
+
| QLFC | Cream Premium Interior | |
|
|
222
|
+
| QLFP | Black Premium Interior | |
|
|
223
|
+
| QLFW | White Premium Interior | |
|
|
224
|
+
| QLWS | White Premium Interior | |
|
|
180
225
|
| QNET | Tan NextGen | |
|
|
226
|
+
| QPBT | Black Textile Interior | |
|
|
181
227
|
| QPMP | Black seats | |
|
|
228
|
+
| QTBS | Black Premium Interior | |
|
|
182
229
|
| QTBW | White Premium Seats | |
|
|
230
|
+
| QTFC | Cream Premium Interior | |
|
|
183
231
|
| QTFP | Black Premium Seats | |
|
|
232
|
+
| QTFW | White Premium Interior | |
|
|
184
233
|
| QTPC | Cream Premium Seats | |
|
|
185
234
|
| QTPP | Black Premium Seats | |
|
|
186
235
|
| QTPT | Tan Premium Seats | |
|
|
187
|
-
| QTTB | Multi-Pattern Black Seats | |
|
|
236
|
+
| QTTB | Multi-Pattern Black Seats | |
|
|
237
|
+
| QTWS | White Premium Interior | |
|
|
188
238
|
| QVBM | Multi-Pattern Black Seats | |
|
|
189
239
|
| QVPC | Vegan Cream Seats | |
|
|
190
240
|
| QVPP | Vegan Cream Seats | |
|
|
@@ -206,12 +256,14 @@ appreciated!_
|
|
|
206
256
|
| SC01 | Supercharging Enabled | |
|
|
207
257
|
| SC04 | Pay Per Use Supercharging | |
|
|
208
258
|
| SC05 | Free Supercharging | |
|
|
209
|
-
| SP00 | No Security Package | |
|
|
259
|
+
| SP00 | No Security Package | |
|
|
210
260
|
| SR01 | Standard 2nd row | |
|
|
211
261
|
| SR06 | Seven Seat Interior | |
|
|
212
262
|
| SR07 | Standard 2nd row | |
|
|
213
263
|
| ST00 | Non-leather Steering Wheel | |
|
|
214
264
|
| ST01 | Non-heated Leather Steering Wheel | |
|
|
265
|
+
| STY5S | Five Seat Interior | |
|
|
266
|
+
| STY7S | Seven Seat Interior | |
|
|
215
267
|
| SU00 | Standard Suspension | |
|
|
216
268
|
| SU01 | Smart Air Suspension | |
|
|
217
269
|
| TIC4 | All-Season Tires | |
|
|
@@ -232,20 +284,49 @@ appreciated!_
|
|
|
232
284
|
| UTAW | Light Headliner | |
|
|
233
285
|
| UTPB | Dark Headliner | |
|
|
234
286
|
| UTSB | Dark Headliner | |
|
|
287
|
+
| UTZW | Light Headliner | |
|
|
288
|
+
| SLR1 | Carbon Fibre Spoiler | Model 3 |
|
|
289
|
+
| SPT31 | Performance Upgrade | Model 3 |
|
|
290
|
+
| SPTY1 | Performance Upgrade | Model Y |
|
|
291
|
+
| W32P | 20" Performance Wheels | Model 3 |
|
|
235
292
|
| W38B | 18" Aero Wheels | For the Model 3 and Model Y |
|
|
236
293
|
| W39B | 19" Sport Wheels | |
|
|
237
294
|
| WT20 | 20" Silver Slipstream Wheels | |
|
|
295
|
+
| WT22 | 22" Silver Turbine Wheels | |
|
|
296
|
+
| WTAB | 21" Black Arachnid Wheels | |
|
|
238
297
|
| WTAS | 19" Silver Slipstream Wheels | |
|
|
239
298
|
| WTDS | 19" Grey Slipstream Wheels | |
|
|
299
|
+
| WTNN | 20" Nokian Winter Tires (non-studded) | |
|
|
300
|
+
| WTNS | 20" Nokian Winter Tires (studded) | |
|
|
301
|
+
| WTP2 | 20" Pirelli Winter Tires | |
|
|
302
|
+
| WTSC | 20" Sonic Carbon Wheels | |
|
|
240
303
|
| WTSG | 21" Turbine Wheels | |
|
|
241
304
|
| WTSP | 21" Turbine Wheels | |
|
|
242
305
|
| WTSS | 21" Turbine Wheels | |
|
|
243
306
|
| WTTB | 19" Cyclone Wheels | |
|
|
307
|
+
| WTTC | 21" Sonic Carbon Twin Turbine Wheels | |
|
|
308
|
+
| WTUT | 22" Onyx Black Wheels | |
|
|
309
|
+
| WTW2 | 19" Nokian Winter Wheel Set | |
|
|
310
|
+
| WTW3 | 19" Pirelli Winter Wheel Set | |
|
|
244
311
|
| WTW4 | 19" Winter Tire Set | |
|
|
245
312
|
| WTW5 | 21" Winter Tire Set | |
|
|
313
|
+
| WTW6 | 19" Nokian Winter Tires (studded) | |
|
|
314
|
+
| WTW7 | 19" Nokian Winter Tires (non-studded) | |
|
|
315
|
+
| WTW8 | 19" Pirelli Winter Tires | |
|
|
246
316
|
| WTX1 | 19" Michelin Primacy Tire Upgrade | |
|
|
317
|
+
| WXNN | No 20" Nokian Winter Tires (non-studded) | |
|
|
318
|
+
| WXNS | No 20" Nokian Winter Tires (studded) | |
|
|
319
|
+
| WXP2 | No 20" Pirelli Winter Tires | |
|
|
320
|
+
| WXW2 | No 19" Wheels with Nokian Winter Tyres | |
|
|
321
|
+
| WXW3 | No 19" Wheels with Pirelli Winter Tyres | |
|
|
247
322
|
| WXW4 | No 19" Winter Tire Set | |
|
|
248
323
|
| WXW5 | No 21" Winter Tire Set | |
|
|
324
|
+
| WXW6 | No 19" Nokian Winter Tires (studded) | |
|
|
325
|
+
| WXW7 | No 19" Nokian Winter Tires (non-studded) | |
|
|
326
|
+
| WXW8 | No 19" Pirelli Winter Tires | |
|
|
327
|
+
| WY18B | 18" Aero Wheels | |
|
|
328
|
+
| WY19B | 19" Sport Wheels | |
|
|
329
|
+
| WY20P | 20" Performance Wheels | |
|
|
249
330
|
| X001 | Override: Power Liftgate | |
|
|
250
331
|
| X003 | Maps & Navigation | |
|
|
251
332
|
| X004 | Override: No Navigation | |
|
data/docs/vehicle/state/data.md
CHANGED
|
@@ -50,3 +50,12 @@ Returns the vehicle's physical state, such as which doors are open.
|
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
```
|
|
53
|
+
|
|
54
|
+
### Center Display States
|
|
55
|
+
| State | Description |
|
|
56
|
+
|-------|-----------------|
|
|
57
|
+
| 0 | Off |
|
|
58
|
+
| 2 | Normal On |
|
|
59
|
+
| 3 | Charging Screen |
|
|
60
|
+
| 7 | Sentry Mode |
|
|
61
|
+
| 8 | Dog Mode |
|
data/lib/tesla_api/client.rb
CHANGED
|
@@ -4,36 +4,57 @@ module TeslaApi
|
|
|
4
4
|
base_uri 'https://owner-api.teslamotors.com/api/1'
|
|
5
5
|
headers 'User-Agent' => "github.com/timdorr/tesla-api v:#{VERSION}"
|
|
6
6
|
format :json
|
|
7
|
+
raise_on [401]
|
|
7
8
|
|
|
8
|
-
attr_reader :email, :
|
|
9
|
+
attr_reader :email, :access_token, :access_token_expires_at, :refresh_token, :client_id, :client_secret
|
|
9
10
|
|
|
10
|
-
def initialize(
|
|
11
|
+
def initialize(
|
|
12
|
+
email: nil,
|
|
13
|
+
access_token: nil,
|
|
14
|
+
access_token_expires_at: nil,
|
|
15
|
+
refresh_token: nil,
|
|
16
|
+
client_id: ENV['TESLA_CLIENT_ID'],
|
|
17
|
+
client_secret: ENV['TESLA_CLIENT_SECRET']
|
|
18
|
+
)
|
|
11
19
|
@email = email
|
|
20
|
+
|
|
12
21
|
@client_id = client_id
|
|
13
22
|
@client_secret = client_secret
|
|
14
|
-
end
|
|
15
23
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
24
|
+
self.update_token(
|
|
25
|
+
access_token: access_token,
|
|
26
|
+
access_token_expires_at: access_token_expires_at,
|
|
27
|
+
refresh_token: refresh_token
|
|
28
|
+
)
|
|
19
29
|
end
|
|
20
30
|
|
|
21
|
-
def
|
|
22
|
-
@
|
|
23
|
-
|
|
31
|
+
def update_token(access_token:, access_token_expires_at:, refresh_token:)
|
|
32
|
+
@access_token = access_token
|
|
33
|
+
@access_token_expires_at = access_token_expires_at
|
|
34
|
+
@refresh_token = refresh_token
|
|
35
|
+
self.class.headers 'Authorization' => "Bearer #{access_token}" if access_token
|
|
24
36
|
|
|
25
|
-
|
|
26
|
-
@created_at = Time.at(timestamp.to_f).to_datetime
|
|
37
|
+
access_token
|
|
27
38
|
end
|
|
28
39
|
|
|
29
|
-
def
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
40
|
+
def refresh_access_token
|
|
41
|
+
response = self.class.post(
|
|
42
|
+
'https://owner-api.teslamotors.com/oauth/token',
|
|
43
|
+
body: {
|
|
44
|
+
grant_type: 'refresh_token',
|
|
45
|
+
client_id: client_id,
|
|
46
|
+
client_secret: client_secret,
|
|
47
|
+
refresh_token: refresh_token
|
|
48
|
+
}
|
|
49
|
+
)
|
|
33
50
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
51
|
+
self.update_token(
|
|
52
|
+
access_token: response['access_token'],
|
|
53
|
+
access_token_expires_at: Time.at(response['created_at'] + response['expires_in']).to_datetime,
|
|
54
|
+
refresh_token: response['refresh_token']
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
response
|
|
37
58
|
end
|
|
38
59
|
|
|
39
60
|
def login!(password)
|
|
@@ -48,10 +69,18 @@ module TeslaApi
|
|
|
48
69
|
}
|
|
49
70
|
)
|
|
50
71
|
|
|
51
|
-
self.
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
72
|
+
self.update_token(
|
|
73
|
+
access_token: response['access_token'],
|
|
74
|
+
access_token_expires_at: Time.at(response['created_at'] + response['expires_in']).to_datetime,
|
|
75
|
+
refresh_token: response['refresh_token']
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
response
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def expired?
|
|
82
|
+
return true if access_token_expires_at.nil?
|
|
83
|
+
access_token_expires_at <= DateTime.now
|
|
55
84
|
end
|
|
56
85
|
|
|
57
86
|
def vehicles
|
data/lib/tesla_api/version.rb
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
http_interactions:
|
|
3
|
+
- request:
|
|
4
|
+
method: post
|
|
5
|
+
uri: https://owner-api.teslamotors.com/oauth/token
|
|
6
|
+
body:
|
|
7
|
+
encoding: UTF-8
|
|
8
|
+
string: grant_type=refresh_token&client_id=<TESLA_CLIENT_ID>&client_secret=<TESLA_CLIENT_SECRET>&refresh_token=<TESLA_REFRESH_TOKEN>
|
|
9
|
+
headers:
|
|
10
|
+
User-Agent:
|
|
11
|
+
- github.com/timdorr/tesla-api v:1.5.0
|
|
12
|
+
Authorization:
|
|
13
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
14
|
+
response:
|
|
15
|
+
status:
|
|
16
|
+
code: 200
|
|
17
|
+
message: OK
|
|
18
|
+
headers:
|
|
19
|
+
Server:
|
|
20
|
+
- nginx
|
|
21
|
+
Date:
|
|
22
|
+
- Mon, 23 Sep 2019 17:25:05 GMT
|
|
23
|
+
Content-Type:
|
|
24
|
+
- application/json; charset=utf-8
|
|
25
|
+
Transfer-Encoding:
|
|
26
|
+
- chunked
|
|
27
|
+
Connection:
|
|
28
|
+
- keep-alive
|
|
29
|
+
X-Frame-Options:
|
|
30
|
+
- SAMEORIGIN
|
|
31
|
+
- SAMEORIGIN
|
|
32
|
+
X-Xss-Protection:
|
|
33
|
+
- 1; mode=block
|
|
34
|
+
X-Content-Type-Options:
|
|
35
|
+
- nosniff
|
|
36
|
+
Cache-Control:
|
|
37
|
+
- no-store
|
|
38
|
+
Pragma:
|
|
39
|
+
- no-cache
|
|
40
|
+
Etag:
|
|
41
|
+
- W/"25e04c26d708b6763d3dca87bcaeb2a7"
|
|
42
|
+
X-Request-Id:
|
|
43
|
+
- d153d7b0-ce0b-4c24-a109-e60488df7f48
|
|
44
|
+
X-Runtime:
|
|
45
|
+
- '0.020946'
|
|
46
|
+
body:
|
|
47
|
+
encoding: UTF-8
|
|
48
|
+
string: '{"access_token":"bb91d9892b8af05ad389f2d05b9689657a076f61c4d97ff398f23d86112fb5ca","token_type":"bearer","expires_in":3888000,"refresh_token":"21879d76c4e00309b3d69c6ecb128b89e0c7e210838404601d9f433e9a069022","created_at":1569259505}'
|
|
49
|
+
http_version:
|
|
50
|
+
recorded_at: Mon, 23 Sep 2019 17:25:05 GMT
|
|
51
|
+
recorded_with: VCR 4.0.0
|
|
@@ -8,7 +8,7 @@ http_interactions:
|
|
|
8
8
|
string: ''
|
|
9
9
|
headers:
|
|
10
10
|
Authorization:
|
|
11
|
-
- Bearer <
|
|
11
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
12
12
|
response:
|
|
13
13
|
status:
|
|
14
14
|
code: 200
|
|
@@ -54,7 +54,7 @@ http_interactions:
|
|
|
54
54
|
string: pin=1234
|
|
55
55
|
headers:
|
|
56
56
|
Authorization:
|
|
57
|
-
- Bearer <
|
|
57
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
58
58
|
response:
|
|
59
59
|
status:
|
|
60
60
|
code: 200
|
|
@@ -10,7 +10,7 @@ http_interactions:
|
|
|
10
10
|
User-Agent:
|
|
11
11
|
- github.com/timdorr/tesla-api v:1.3.0
|
|
12
12
|
Authorization:
|
|
13
|
-
- Bearer <
|
|
13
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
14
14
|
response:
|
|
15
15
|
status:
|
|
16
16
|
code: 200
|
|
@@ -59,7 +59,7 @@ http_interactions:
|
|
|
59
59
|
User-Agent:
|
|
60
60
|
- github.com/timdorr/tesla-api v:1.3.0
|
|
61
61
|
Authorization:
|
|
62
|
-
- Bearer <
|
|
62
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
63
63
|
response:
|
|
64
64
|
status:
|
|
65
65
|
code: 200
|
|
@@ -10,7 +10,7 @@ http_interactions:
|
|
|
10
10
|
User-Agent:
|
|
11
11
|
- github.com/timdorr/tesla-api v:1.3.0
|
|
12
12
|
Authorization:
|
|
13
|
-
- Bearer <
|
|
13
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
14
14
|
response:
|
|
15
15
|
status:
|
|
16
16
|
code: 200
|
|
@@ -59,7 +59,7 @@ http_interactions:
|
|
|
59
59
|
User-Agent:
|
|
60
60
|
- github.com/timdorr/tesla-api v:1.3.0
|
|
61
61
|
Authorization:
|
|
62
|
-
- Bearer <
|
|
62
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
63
63
|
response:
|
|
64
64
|
status:
|
|
65
65
|
code: 200
|
|
@@ -8,7 +8,7 @@ http_interactions:
|
|
|
8
8
|
string: ''
|
|
9
9
|
headers:
|
|
10
10
|
Authorization:
|
|
11
|
-
- Bearer <
|
|
11
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
12
12
|
response:
|
|
13
13
|
status:
|
|
14
14
|
code: 200
|
|
@@ -54,7 +54,7 @@ http_interactions:
|
|
|
54
54
|
string: pin=1234
|
|
55
55
|
headers:
|
|
56
56
|
Authorization:
|
|
57
|
-
- Bearer <
|
|
57
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
58
58
|
response:
|
|
59
59
|
status:
|
|
60
60
|
code: 200
|
|
@@ -10,7 +10,7 @@ http_interactions:
|
|
|
10
10
|
User-Agent:
|
|
11
11
|
- github.com/timdorr/tesla-api v:1.3.0
|
|
12
12
|
Authorization:
|
|
13
|
-
- Bearer <
|
|
13
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
14
14
|
response:
|
|
15
15
|
status:
|
|
16
16
|
code: 200
|
|
@@ -59,7 +59,7 @@ http_interactions:
|
|
|
59
59
|
User-Agent:
|
|
60
60
|
- github.com/timdorr/tesla-api v:1.3.0
|
|
61
61
|
Authorization:
|
|
62
|
-
- Bearer <
|
|
62
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
63
63
|
response:
|
|
64
64
|
status:
|
|
65
65
|
code: 200
|
|
@@ -8,7 +8,7 @@ http_interactions:
|
|
|
8
8
|
string: ''
|
|
9
9
|
headers:
|
|
10
10
|
Authorization:
|
|
11
|
-
- Bearer <
|
|
11
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
12
12
|
response:
|
|
13
13
|
status:
|
|
14
14
|
code: 200
|
|
@@ -54,7 +54,7 @@ http_interactions:
|
|
|
54
54
|
string: pin=1234
|
|
55
55
|
headers:
|
|
56
56
|
Authorization:
|
|
57
|
-
- Bearer <
|
|
57
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
58
58
|
response:
|
|
59
59
|
status:
|
|
60
60
|
code: 200
|
|
@@ -10,7 +10,7 @@ http_interactions:
|
|
|
10
10
|
User-Agent:
|
|
11
11
|
- github.com/timdorr/tesla-api v:1.3.0
|
|
12
12
|
Authorization:
|
|
13
|
-
- Bearer <
|
|
13
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
14
14
|
response:
|
|
15
15
|
status:
|
|
16
16
|
code: 200
|
|
@@ -59,7 +59,7 @@ http_interactions:
|
|
|
59
59
|
User-Agent:
|
|
60
60
|
- github.com/timdorr/tesla-api v:1.3.0
|
|
61
61
|
Authorization:
|
|
62
|
-
- Bearer <
|
|
62
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
63
63
|
response:
|
|
64
64
|
status:
|
|
65
65
|
code: 200
|
|
@@ -10,7 +10,7 @@ http_interactions:
|
|
|
10
10
|
User-Agent:
|
|
11
11
|
- github.com/timdorr/tesla-api v:1.3.0
|
|
12
12
|
Authorization:
|
|
13
|
-
- Bearer <
|
|
13
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
14
14
|
response:
|
|
15
15
|
status:
|
|
16
16
|
code: 200
|
|
@@ -59,7 +59,7 @@ http_interactions:
|
|
|
59
59
|
User-Agent:
|
|
60
60
|
- github.com/timdorr/tesla-api v:1.3.0
|
|
61
61
|
Authorization:
|
|
62
|
-
- Bearer <
|
|
62
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
63
63
|
response:
|
|
64
64
|
status:
|
|
65
65
|
code: 400
|
|
@@ -8,7 +8,7 @@ http_interactions:
|
|
|
8
8
|
string: ''
|
|
9
9
|
headers:
|
|
10
10
|
Authorization:
|
|
11
|
-
- Bearer <
|
|
11
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
12
12
|
response:
|
|
13
13
|
status:
|
|
14
14
|
code: 200
|
|
@@ -54,7 +54,7 @@ http_interactions:
|
|
|
54
54
|
string: which_trunk=front
|
|
55
55
|
headers:
|
|
56
56
|
Authorization:
|
|
57
|
-
- Bearer <
|
|
57
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
58
58
|
response:
|
|
59
59
|
status:
|
|
60
60
|
code: 200
|
|
@@ -8,7 +8,7 @@ http_interactions:
|
|
|
8
8
|
string: ''
|
|
9
9
|
headers:
|
|
10
10
|
Authorization:
|
|
11
|
-
- Bearer <
|
|
11
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
12
12
|
response:
|
|
13
13
|
status:
|
|
14
14
|
code: 200
|
|
@@ -54,7 +54,7 @@ http_interactions:
|
|
|
54
54
|
string: which_trunk=front
|
|
55
55
|
headers:
|
|
56
56
|
Authorization:
|
|
57
|
-
- Bearer <
|
|
57
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
58
58
|
response:
|
|
59
59
|
status:
|
|
60
60
|
code: 200
|
|
@@ -8,7 +8,7 @@ http_interactions:
|
|
|
8
8
|
string: ''
|
|
9
9
|
headers:
|
|
10
10
|
Authorization:
|
|
11
|
-
- Bearer <
|
|
11
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
12
12
|
response:
|
|
13
13
|
status:
|
|
14
14
|
code: 200
|
|
@@ -49,7 +49,7 @@ http_interactions:
|
|
|
49
49
|
string: ''
|
|
50
50
|
headers:
|
|
51
51
|
Authorization:
|
|
52
|
-
- Bearer <
|
|
52
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
53
53
|
response:
|
|
54
54
|
status:
|
|
55
55
|
code: 200
|
|
@@ -10,7 +10,7 @@ http_interactions:
|
|
|
10
10
|
User-Agent:
|
|
11
11
|
- github.com/timdorr/tesla-api v:1.3.0
|
|
12
12
|
Authorization:
|
|
13
|
-
- Bearer <
|
|
13
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
14
14
|
response:
|
|
15
15
|
status:
|
|
16
16
|
code: 200
|
|
@@ -59,7 +59,7 @@ http_interactions:
|
|
|
59
59
|
User-Agent:
|
|
60
60
|
- github.com/timdorr/tesla-api v:1.3.0
|
|
61
61
|
Authorization:
|
|
62
|
-
- Bearer <
|
|
62
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
63
63
|
response:
|
|
64
64
|
status:
|
|
65
65
|
code: 200
|
|
@@ -10,7 +10,7 @@ http_interactions:
|
|
|
10
10
|
User-Agent:
|
|
11
11
|
- github.com/timdorr/tesla-api v:1.4.1
|
|
12
12
|
Authorization:
|
|
13
|
-
- Bearer <
|
|
13
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
14
14
|
response:
|
|
15
15
|
status:
|
|
16
16
|
code: 200
|
|
@@ -59,7 +59,7 @@ http_interactions:
|
|
|
59
59
|
User-Agent:
|
|
60
60
|
- github.com/timdorr/tesla-api v:1.4.1
|
|
61
61
|
Authorization:
|
|
62
|
-
- Bearer <
|
|
62
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
63
63
|
response:
|
|
64
64
|
status:
|
|
65
65
|
code: 200
|
|
@@ -10,7 +10,7 @@ http_interactions:
|
|
|
10
10
|
User-Agent:
|
|
11
11
|
- github.com/timdorr/tesla-api v:1.4.1
|
|
12
12
|
Authorization:
|
|
13
|
-
- Bearer <
|
|
13
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
14
14
|
response:
|
|
15
15
|
status:
|
|
16
16
|
code: 200
|
|
@@ -59,7 +59,7 @@ http_interactions:
|
|
|
59
59
|
User-Agent:
|
|
60
60
|
- github.com/timdorr/tesla-api v:1.4.1
|
|
61
61
|
Authorization:
|
|
62
|
-
- Bearer <
|
|
62
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
63
63
|
response:
|
|
64
64
|
status:
|
|
65
65
|
code: 200
|
|
@@ -8,7 +8,7 @@ http_interactions:
|
|
|
8
8
|
string: ''
|
|
9
9
|
headers:
|
|
10
10
|
Authorization:
|
|
11
|
-
- Bearer <
|
|
11
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
12
12
|
response:
|
|
13
13
|
status:
|
|
14
14
|
code: 200
|
|
@@ -54,7 +54,7 @@ http_interactions:
|
|
|
54
54
|
string: limit_mph=65
|
|
55
55
|
headers:
|
|
56
56
|
Authorization:
|
|
57
|
-
- Bearer <
|
|
57
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
58
58
|
response:
|
|
59
59
|
status:
|
|
60
60
|
code: 200
|
|
@@ -8,7 +8,7 @@ http_interactions:
|
|
|
8
8
|
string: ''
|
|
9
9
|
headers:
|
|
10
10
|
Authorization:
|
|
11
|
-
- Bearer <
|
|
11
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
12
12
|
response:
|
|
13
13
|
status:
|
|
14
14
|
code: 200
|
|
@@ -49,7 +49,7 @@ http_interactions:
|
|
|
49
49
|
string: on=true&password=1234
|
|
50
50
|
headers:
|
|
51
51
|
Authorization:
|
|
52
|
-
- Bearer <
|
|
52
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
53
53
|
response:
|
|
54
54
|
status:
|
|
55
55
|
code: 200
|
|
@@ -10,7 +10,7 @@ http_interactions:
|
|
|
10
10
|
User-Agent:
|
|
11
11
|
- github.com/timdorr/tesla-api v:1.4.1
|
|
12
12
|
Authorization:
|
|
13
|
-
- Bearer <
|
|
13
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
14
14
|
response:
|
|
15
15
|
status:
|
|
16
16
|
code: 200
|
|
@@ -59,7 +59,7 @@ http_interactions:
|
|
|
59
59
|
User-Agent:
|
|
60
60
|
- github.com/timdorr/tesla-api v:1.4.1
|
|
61
61
|
Authorization:
|
|
62
|
-
- Bearer <
|
|
62
|
+
- Bearer <TESLA_ACCESS_TOKEN>
|
|
63
63
|
response:
|
|
64
64
|
status:
|
|
65
65
|
code: 200
|
|
@@ -1,63 +1,79 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
RSpec.describe TeslaApi::Client do
|
|
4
|
-
subject(:tesla_api) { TeslaApi::Client.new(ENV['TESLA_EMAIL']) }
|
|
4
|
+
subject(:tesla_api) { TeslaApi::Client.new(email: ENV['TESLA_EMAIL']) }
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
context 'password grant auth' do
|
|
7
|
+
describe '#new' do
|
|
8
|
+
it 'has no expiry date' do
|
|
9
|
+
expect(tesla_api.access_token_expires_at).to eq(nil)
|
|
10
|
+
end
|
|
10
11
|
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
it 'has a expiry status set to true' do
|
|
13
|
+
expect(tesla_api.expired?).to eq(true)
|
|
14
|
+
end
|
|
13
15
|
end
|
|
14
|
-
end
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
tesla_api.token = Faker::Lorem.characters(32)
|
|
19
|
-
expect(tesla_api.class.headers).to include({'Authorization' => /Bearer [a-z0-9]{32}/})
|
|
20
|
-
end
|
|
21
|
-
end
|
|
17
|
+
describe '#login!', vcr: { cassette_name: 'client-login' } do
|
|
18
|
+
it { is_expected.to be_a(TeslaApi::Client) }
|
|
22
19
|
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
it 'logs into the API' do
|
|
21
|
+
tesla_api.login!(ENV['TESLA_PASS'])
|
|
22
|
+
expect(a_request(:post, "https://#{URI.parse(tesla_api.class.base_uri).host}/oauth/token")).to have_been_made.once
|
|
23
|
+
end
|
|
25
24
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
it 'sets a Bearer token header' do
|
|
26
|
+
tesla_api.login!(ENV['TESLA_PASS'])
|
|
27
|
+
expect(tesla_api.class.headers).to include({'Authorization' => /Bearer [a-z0-9]{32}/})
|
|
28
|
+
end
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
30
|
+
it 'obtains a Bearer token' do
|
|
31
|
+
tesla_api.login!(ENV['TESLA_PASS'])
|
|
32
|
+
expect(tesla_api.access_token).to match(/[a-z0-9]{32}/)
|
|
33
|
+
end
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
end
|
|
35
|
+
it 'set a expiry date' do
|
|
36
|
+
tesla_api.login!(ENV['TESLA_PASS'])
|
|
37
|
+
expect(tesla_api.access_token_expires_at).to eq(Time.at(1475777133 + 7776000).to_datetime)
|
|
38
|
+
end
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
end
|
|
40
|
+
it 'obtains a refresh token' do
|
|
41
|
+
tesla_api.login!(ENV['TESLA_PASS'])
|
|
42
|
+
expect(tesla_api.refresh_token).to match(/[a-z0-9]{32}/)
|
|
43
|
+
end
|
|
47
44
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
it 'expose expiry status' do
|
|
46
|
+
tesla_api.login!(ENV['TESLA_PASS'])
|
|
47
|
+
expect(tesla_api.expired?).to eq(true)
|
|
48
|
+
end
|
|
51
49
|
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
context 'token grant auth' do
|
|
53
|
+
subject(:tesla_api) { TeslaApi::Client.new(
|
|
54
|
+
access_token: access_token,
|
|
55
|
+
access_token_expires_at: DateTime.now + 1,
|
|
56
|
+
refresh_token: refresh_token
|
|
57
|
+
) }
|
|
58
|
+
|
|
59
|
+
let(:access_token) { ENV['TESLA_ACCESS_TOKEN'] }
|
|
60
|
+
let(:refresh_token) { ENV['TESLA_REFRESH_TOKEN'] }
|
|
61
|
+
|
|
62
|
+
describe '#new' do
|
|
63
|
+
it 'is not expired' do
|
|
64
|
+
expect(tesla_api.expired?).to eq(false)
|
|
65
|
+
end
|
|
52
66
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
67
|
+
it 'sets a Bearer token header' do
|
|
68
|
+
expect(tesla_api.class.headers).to include({'Authorization' => "Bearer #{access_token}"})
|
|
69
|
+
end
|
|
56
70
|
end
|
|
57
71
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
72
|
+
describe '#refresh_access_token', vcr: {cassette_name: 'client-refresh'} do
|
|
73
|
+
it 'refreshes the access token' do
|
|
74
|
+
tesla_api.refresh_access_token
|
|
75
|
+
expect(tesla_api.access_token).not_to eq(access_token)
|
|
76
|
+
end
|
|
61
77
|
end
|
|
62
78
|
end
|
|
63
79
|
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
RSpec.describe TeslaApi::Vehicle do
|
|
4
|
-
let(:tesla_api) { TeslaApi::Client.new(ENV['
|
|
5
|
-
|
|
6
|
-
before do
|
|
7
|
-
tesla_api.token = ENV['TESLA_API_TOKEN']
|
|
8
|
-
end
|
|
4
|
+
let(:tesla_api) { TeslaApi::Client.new(access_token: ENV['TESLA_ACCESS_TOKEN']) }
|
|
9
5
|
|
|
10
6
|
subject(:vehicle) { tesla_api.vehicles.first }
|
|
11
7
|
|
data/spec/spec_helper.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
require 'dotenv'
|
|
2
|
-
require 'faker'
|
|
3
2
|
require 'vcr'
|
|
4
3
|
require 'webmock/rspec'
|
|
5
4
|
|
|
@@ -17,7 +16,8 @@ VCR.configure do |c|
|
|
|
17
16
|
c.define_cassette_placeholder('<TESLA_PASS>') { ENV['TESLA_PASS'] }
|
|
18
17
|
c.define_cassette_placeholder('<TESLA_CLIENT_ID>') { ENV['TESLA_CLIENT_ID'] }
|
|
19
18
|
c.define_cassette_placeholder('<TESLA_CLIENT_SECRET>') { ENV['TESLA_CLIENT_SECRET'] }
|
|
20
|
-
c.define_cassette_placeholder('<
|
|
19
|
+
c.define_cassette_placeholder('<TESLA_ACCESS_TOKEN>') { ENV['TESLA_ACCESS_TOKEN'] }
|
|
20
|
+
c.define_cassette_placeholder('<TESLA_REFRESH_TOKEN>') { ENV['TESLA_REFRESH_TOKEN'] }
|
|
21
21
|
end
|
|
22
22
|
|
|
23
23
|
RSpec.configure do |config|
|
data/tesla_api.gemspec
CHANGED
|
@@ -21,7 +21,6 @@ Gem::Specification.new do |spec|
|
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
|
22
22
|
spec.add_development_dependency 'rake', '~> 12.0'
|
|
23
23
|
spec.add_development_dependency 'rspec', '~> 3.1'
|
|
24
|
-
spec.add_development_dependency 'faker', '~> 1.4'
|
|
25
24
|
spec.add_development_dependency 'vcr', '~> 4.0'
|
|
26
25
|
spec.add_development_dependency 'webmock', '~> 3.0'
|
|
27
26
|
spec.add_development_dependency 'dotenv', '~> 2.0'
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: tesla_api
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 2.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tim Dorr
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-09-23 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: httparty
|
|
@@ -94,20 +94,6 @@ dependencies:
|
|
|
94
94
|
- - "~>"
|
|
95
95
|
- !ruby/object:Gem::Version
|
|
96
96
|
version: '3.1'
|
|
97
|
-
- !ruby/object:Gem::Dependency
|
|
98
|
-
name: faker
|
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
|
100
|
-
requirements:
|
|
101
|
-
- - "~>"
|
|
102
|
-
- !ruby/object:Gem::Version
|
|
103
|
-
version: '1.4'
|
|
104
|
-
type: :development
|
|
105
|
-
prerelease: false
|
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
107
|
-
requirements:
|
|
108
|
-
- - "~>"
|
|
109
|
-
- !ruby/object:Gem::Version
|
|
110
|
-
version: '1.4'
|
|
111
97
|
- !ruby/object:Gem::Dependency
|
|
112
98
|
name: vcr
|
|
113
99
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -161,6 +147,7 @@ files:
|
|
|
161
147
|
- ".gitbook.yml"
|
|
162
148
|
- ".gitignore"
|
|
163
149
|
- ".rspec"
|
|
150
|
+
- ".tool-versions"
|
|
164
151
|
- ".travis.yml"
|
|
165
152
|
- Gemfile
|
|
166
153
|
- LICENSE
|
|
@@ -209,6 +196,7 @@ files:
|
|
|
209
196
|
- lib/tesla_api/vehicle.rb
|
|
210
197
|
- lib/tesla_api/version.rb
|
|
211
198
|
- spec/cassettes/client-login.yml
|
|
199
|
+
- spec/cassettes/client-refresh.yml
|
|
212
200
|
- spec/cassettes/client-vehicles.yml
|
|
213
201
|
- spec/cassettes/vehicle-activate_speed_limit.yml
|
|
214
202
|
- spec/cassettes/vehicle-auto_conditioning_start.yml
|
|
@@ -280,12 +268,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
280
268
|
- !ruby/object:Gem::Version
|
|
281
269
|
version: '0'
|
|
282
270
|
requirements: []
|
|
283
|
-
rubygems_version: 3.0.
|
|
271
|
+
rubygems_version: 3.0.6
|
|
284
272
|
signing_key:
|
|
285
273
|
specification_version: 4
|
|
286
274
|
summary: A wrapper for the Tesla JSON API
|
|
287
275
|
test_files:
|
|
288
276
|
- spec/cassettes/client-login.yml
|
|
277
|
+
- spec/cassettes/client-refresh.yml
|
|
289
278
|
- spec/cassettes/client-vehicles.yml
|
|
290
279
|
- spec/cassettes/vehicle-activate_speed_limit.yml
|
|
291
280
|
- spec/cassettes/vehicle-auto_conditioning_start.yml
|