| | | 1 | | using System.Net; |
| | | 2 | | using Newtonsoft.Json; |
| | | 3 | | using Newtonsoft.Json.Linq; |
| | | 4 | | using Services.ApiServices.StudioApi.Models.Response; |
| | | 5 | | |
| | | 6 | | #pragma warning disable SYSLIB0014 // HttpWebRequest — legacy Interparts client, migrate to HttpClient separately |
| | | 7 | | |
| | | 8 | | namespace Services.ApiServices.StudioApi; |
| | | 9 | | |
| | | 10 | | public class InterpartsApiClient |
| | | 11 | | { |
| | | 12 | | private readonly string _token; |
| | | 13 | | |
| | 0 | 14 | | public InterpartsApiClient(string token) |
| | | 15 | | { |
| | 0 | 16 | | _token = token; |
| | 0 | 17 | | } |
| | | 18 | | |
| | | 19 | | public JObject MakeRequestGet(string requestUri) |
| | | 20 | | { |
| | | 21 | | try |
| | | 22 | | { |
| | 0 | 23 | | var request = (HttpWebRequest)WebRequest.Create(requestUri); |
| | 0 | 24 | | request.Method = "GET"; |
| | 0 | 25 | | request.ContentType = "application/json"; |
| | 0 | 26 | | request.Headers["Authorization"] = _token; |
| | | 27 | | |
| | 0 | 28 | | using var response = (HttpWebResponse)request.GetResponse(); |
| | 0 | 29 | | using var streamReader = new StreamReader(response.GetResponseStream()); |
| | 0 | 30 | | string jsonResponse = streamReader.ReadToEnd(); |
| | 0 | 31 | | return JObject.Parse(jsonResponse); |
| | | 32 | | } |
| | 0 | 33 | | catch (WebException ex) when (ex.Response is HttpWebResponse httpResponse) |
| | | 34 | | { |
| | 0 | 35 | | throw new Exception($"Request failed. Status: {httpResponse.StatusCode}"); |
| | | 36 | | } |
| | 0 | 37 | | } |
| | | 38 | | } |