-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPobbinTreeImporter.cs
More file actions
27 lines (22 loc) · 918 Bytes
/
PobbinTreeImporter.cs
File metadata and controls
27 lines (22 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
using System;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace GemGuide;
public class PobbinTreeImporter
{
private static readonly Regex MaxRollUrlRegex = new Regex(@"^https://pobb\.in/(?<pobId>[^/]+)/?$", RegexOptions.Compiled);
public async Task<string> GetPobCode(string url, CancellationToken cancellationToken)
{
if (MaxRollUrlRegex.Match(url.Trim()) is not { Success: true } match)
{
throw new Exception($"url '{url}' does not match expected regex {MaxRollUrlRegex}");
}
var groupId = match.Groups["pobId"].Value;
var dataUrl = $"https://pobb.in/{groupId}/raw";
var dataString = await new HttpClient().GetStringAsync(dataUrl, cancellationToken);
return dataString;
}
public bool IsMatch(string url) => MaxRollUrlRegex.IsMatch(url.Trim());
}