public async Task <TeslaVehicleDataDriveState> GetVehicleDataDriveStateAsync(TeslaAuthorization authorization, long vehicleId) { var result = await apiClient.GetVehicleDataDriveStateAsync(authorization, vehicleId); if (!string.IsNullOrEmpty(result.Error)) { return(null); } return(result.Content?.Response); }
public async Task <IEnumerable <TeslaVehicle> > GetVehiclesAsync(TeslaAuthorization authorization) { var result = await apiClient.GetVehiclesAsync(authorization); if (!string.IsNullOrEmpty(result.Error)) { return(Enumerable.Empty <TeslaVehicle>()); } return(result.Content?.Response); }
public async Task <bool?> GetVehicleMobileEnabledAsync(TeslaAuthorization authorization, long vehicleId) { var result = await apiClient.GetVehicleMobileEnabledAsync(authorization, vehicleId); if (!string.IsNullOrEmpty(result.Error)) { return(null); } return(result.Content?.Response); }
private async Task <TeslaApiResult <T> > GetAsync <T>(string url, TeslaAuthorization authorization) { if (authorization == null) { return(new TeslaApiResult <T>()); } var response = await client.SendAsync(HttpMethod.Get, url, authorization : authorization); if (!response.IsSuccessStatusCode) { return new TeslaApiResult <T> { Error = await response.Content.ReadAsStringAsync() } } ; return(new TeslaApiResult <T> { Content = await JsonSerializer.DeserializeAsync <T>(await response.Content.ReadAsStreamAsync()) }); } }
public Task <TeslaApiResult <TeslaApiResponse <TeslaVehicleNearbyChargingSites> > > GetVehicleNearbyChargingSitesAsync(TeslaAuthorization authorization, long vehicleId) => GetAsync <TeslaApiResponse <TeslaVehicleNearbyChargingSites> >($"/api/1/vehicles/{vehicleId}/nearby_charging_sites", authorization);
public Task <TeslaApiResult <TeslaApiResponse <bool> > > GetVehicleMobileEnabledAsync(TeslaAuthorization authorization, long vehicleId) => GetAsync <TeslaApiResponse <bool> >($"/api/1/vehicles/{vehicleId}/mobile_enabled", authorization);
public Task <TeslaApiResult <TeslaApiResponse <TeslaVehicleDataVehicleConfig> > > GetVehicleDataVehicleConfigAsync(TeslaAuthorization authorization, long vehicleId) => GetAsync <TeslaApiResponse <TeslaVehicleDataVehicleConfig> >($"/api/1/vehicles/{vehicleId}/data_request/vehicle_config", authorization);
public Task <TeslaApiResult <TeslaApiResponse <TeslaVehicleDataGuiSettings> > > GetVehicleDataGuiSettingsAsync(TeslaAuthorization authorization, long vehicleId) => GetAsync <TeslaApiResponse <TeslaVehicleDataGuiSettings> >($"/api/1/vehicles/{vehicleId}/data_request/gui_settings", authorization);
public Task <TeslaApiResult <TeslaApiResponse <TeslaVehicleDataDriveState> > > GetVehicleDataDriveStateAsync(TeslaAuthorization authorization, long vehicleId) => GetAsync <TeslaApiResponse <TeslaVehicleDataDriveState> >($"/api/1/vehicles/{vehicleId}/data_request/drive_state", authorization);
public Task <TeslaApiResult <TeslaApiResponse <TeslaVehicleData> > > GetVehicleDataAsync(TeslaAuthorization authorization, long vehicleId) => GetAsync <TeslaApiResponse <TeslaVehicleData> >($"/api/1/vehicles/{vehicleId}/vehicle_data", authorization);
public Task <TeslaApiResult <TeslaApiListResponse <TeslaVehicle> > > GetVehiclesAsync(TeslaAuthorization authorization) => GetAsync <TeslaApiListResponse <TeslaVehicle> >("/api/1/vehicles", authorization);
public void SaveAuthorization(TeslaAuthorization authorization) => storageService.Save(authorizationFileName, authorization);
public static async Task <HttpResponseMessage> SendAsync(this HttpClient client, HttpMethod method, string url, object content = null, TeslaAuthorization authorization = null) { var request = new HttpRequestMessage(method, url); if (authorization != null) { request.Headers.Authorization = new AuthenticationHeaderValue(authorization.TokenType, authorization.AccessToken); } if (content != null) { request.Content = new StringContent(JsonSerializer.Serialize(content, new JsonSerializerOptions { IgnoreNullValues = true }), Encoding.UTF8, "application/json"); } return(await client.SendAsync(request)); }