< Summary

Information
Class: LifeChart.Infrastructure.CrisisResources.FindAHelplineService
Assembly: LifeChart.Infrastructure
File(s): /home/runner/work/lifechart/lifechart/src/LifeChart.Infrastructure/CrisisResources/FindAHelplineService.cs
Tag: 113_29159449707
Line coverage
0%
Covered lines: 0
Uncovered lines: 20
Coverable lines: 20
Total lines: 56
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 8
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
GetForRegionAsync()0%2040%
get_Organizations()100%210%
get_Name()100%210%
get_PhoneNumber()100%210%
get_Url()100%210%
get_Available24h()100%210%

File(s)

/home/runner/work/lifechart/lifechart/src/LifeChart.Infrastructure/CrisisResources/FindAHelplineService.cs

#LineLine coverage
 1using System.Net.Http.Json;
 2using System.Text.Json.Serialization;
 3using LifeChart.Application.DTOs;
 4using LifeChart.Application.Interfaces;
 5
 6namespace LifeChart.Infrastructure.CrisisResources;
 7
 8// API-Dokumentation: https://findahelpline.com
 9// Endpunkt wird bei Bedarf angepasst wenn offizielle Docs verfügbar sind.
 10public class FindAHelplineService : ICrisisResourceService
 11{
 12    private readonly HttpClient _httpClient;
 13
 014    public FindAHelplineService(HttpClient httpClient)
 15    {
 016        _httpClient = httpClient;
 017        _httpClient.BaseAddress = new Uri("https://findahelpline.com");
 018        _httpClient.Timeout = TimeSpan.FromSeconds(5);
 019    }
 20
 21    public async Task<IEnumerable<CrisisResourceDto>> GetForRegionAsync(string regionCode)
 22    {
 023        var response = await _httpClient.GetFromJsonAsync<FindAHelplineResponse>(
 024            $"/api/v1/organizations?countryCode={regionCode}");
 25
 026        if (response?.Organizations is null)
 027            return [];
 28
 029        return response.Organizations.Select(o => new CrisisResourceDto(
 030            o.Name ?? string.Empty,
 031            o.PhoneNumber ?? string.Empty,
 032            o.Url,
 033            o.Available24h));
 034    }
 35
 36    private sealed class FindAHelplineResponse
 37    {
 38        [JsonPropertyName("organizations")]
 039        public List<FindAHelplineOrganization>? Organizations { get; set; }
 40    }
 41
 42    private sealed class FindAHelplineOrganization
 43    {
 44        [JsonPropertyName("name")]
 045        public string? Name { get; set; }
 46
 47        [JsonPropertyName("phone")]
 048        public string? PhoneNumber { get; set; }
 49
 50        [JsonPropertyName("url")]
 051        public string? Url { get; set; }
 52
 53        [JsonPropertyName("available_24h")]
 054        public bool Available24h { get; set; }
 55    }
 56}