Skip to content

Commit

Permalink
[IGNORE] Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Kieburg committed Dec 13, 2023
1 parent 57cf93d commit b47b255
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 39 deletions.
1 change: 1 addition & 0 deletions MtgCsvHelper.Tests/ScryfallApiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ public void DownloadSetsTest()
{
var sets = _scryfallApi.GetSets();
sets.Should().NotBeNullOrEmpty();
sets.Count().Should().BeGreaterThan(800);
}
}
2 changes: 1 addition & 1 deletion MtgCsvHelper/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
},
"DsToMf": {
"commandName": "Project",
"commandLineArgs": "-f SampleCsvs/Samples/dragonshield-sample.csv --in DRAGONSHIELD --out MOXFIELD"
"commandLineArgs": "-f Resources/SampleCsvs/Samples/dragonshield-sample.csv --in DRAGONSHIELD --out MOXFIELD"
}
}
}
47 changes: 9 additions & 38 deletions MtgCsvHelper/Services/ScryfallApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,9 @@ public class ScryfallApi : IMtgApi

public IEnumerable<Set> GetSets()
{
// URL of the API endpoint
var apiUrl = "https://api.scryfall.com/sets/";

// Download JSON data
var jsonData = DownloadJsonAsync(apiUrl).GetAwaiter().GetResult();

// Deserialize JSON data into IEnumerable<Set>
var sets = DeserializeJson(jsonData);

// Do something with the sets
foreach (var set in sets)
{
Console.WriteLine($"Code: {set.Code}, FullName: {set.FullName}, ReleaseDate: {set.ReleaseDate}");
}

return sets;
}

Expand All @@ -47,34 +35,17 @@ static async Task<string> DownloadJsonAsync(string apiUrl)
static IEnumerable<Set> DeserializeJson(string jsonData)
{
// Parse the JSON to a JsonDocument
using (var jsonDocument = JsonDocument.Parse(jsonData))
{
// Access the "data" array
var dataElement = jsonDocument.RootElement.GetProperty("data");
using var jsonDocument = JsonDocument.Parse(jsonData);
var dataElement = jsonDocument.RootElement.GetProperty("data");

// Deserialize the "data" array into List<Set>
var sets = new List<Set>();
foreach (var setElement in dataElement.EnumerateArray())
{
var set = new Set
{
FullName = setElement.GetProperty("name").GetString(),
Code = setElement.GetProperty("code").GetString()!
};
sets.Add(set);
}
var sets = dataElement.EnumerateArray().Select(ConvertToSet).ToList();

// Access the sets
foreach (var set in sets)
{
Console.WriteLine($"Name: {set.FullName}, Code: {set.Code}");
}


// Use System.Text.Json.JsonSerializer to deserialize JSON into IEnumerable<Set>

return sets;
}
return sets;

Set ConvertToSet(JsonElement setElement) => new()
{
FullName = setElement.GetProperty("name").GetString(),
Code = setElement.GetProperty("code").GetString()!
};
}
}

0 comments on commit b47b255

Please sign in to comment.