-
-
Save dcomartin/dec78c54c0e38e9a67fe7a425597e6c8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IVinDecoderService | |
| { | |
| Task<VinDecoderResult> Lookup(string vin, CancellationToken cancellationToken = default); | |
| } | |
| public class VinDecoderService : IVinDecoderService | |
| { | |
| private readonly HttpClient _httpClient; | |
| public VinDecoderService(HttpClient httpClient) | |
| { | |
| _httpClient = httpClient; | |
| } | |
| public async Task<VinDecoderResult> Lookup(string vin, CancellationToken cancellationToken = default) | |
| { | |
| var response = await _httpClient.SendAsync(new HttpRequestMessage | |
| { | |
| Method = HttpMethod.Get, | |
| RequestUri = new Uri($"https://api.vindecoder.com/{vin}/specs") | |
| }, cancellationToken); | |
| if (!response.IsSuccessStatusCode) | |
| { | |
| throw new Exception("Error calling API to decode VIN"); | |
| } | |
| var result = await response.Content.ReadFromJsonAsync<VinDecoderResult>(cancellationToken: cancellationToken); | |
| return result ?? throw new Exception("Error calling API to decode VIN"); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment