< Summary

Information
Class: Services.ApiServices.StudioApi.InterpartsApiClient
Assembly: Services
File(s): /home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiServices/StudioApi/InterpartsApiClient.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 38
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
MakeRequestGet(...)100%210%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/AppRepository/ApiServices/StudioApi/InterpartsApiClient.cs

#LineLine coverage
 1using System.Net;
 2using Newtonsoft.Json;
 3using Newtonsoft.Json.Linq;
 4using Services.ApiServices.StudioApi.Models.Response;
 5
 6#pragma warning disable SYSLIB0014 // HttpWebRequest — legacy Interparts client, migrate to HttpClient separately
 7
 8namespace Services.ApiServices.StudioApi;
 9
 10public class InterpartsApiClient
 11{
 12    private readonly string _token;
 13
 014    public InterpartsApiClient(string token)
 15    {
 016        _token = token;
 017    }
 18
 19    public JObject MakeRequestGet(string requestUri)
 20    {
 21        try
 22        {
 023            var request = (HttpWebRequest)WebRequest.Create(requestUri);
 024            request.Method = "GET";
 025            request.ContentType = "application/json";
 026            request.Headers["Authorization"] = _token;
 27
 028            using var response = (HttpWebResponse)request.GetResponse();
 029            using var streamReader = new StreamReader(response.GetResponseStream());
 030            string jsonResponse = streamReader.ReadToEnd();
 031            return JObject.Parse(jsonResponse);
 32        }
 033        catch (WebException ex) when (ex.Response is HttpWebResponse httpResponse)
 34        {
 035            throw new Exception($"Request failed. Status: {httpResponse.StatusCode}");
 36        }
 037    }
 38}