Reformatted and cleaned up code across whole project.

This commit is contained in:
alphafetus committed 2023-10-24 09:04:04 -04:00
1 parent 42a7871ed4
commit 99cb9268dd
25 files changed
+272 -319

No files matched your search

+2 -4
View File
@@ -3,10 +3,8 @@ using PcgsInvUi.Models;
namespace PcgsInvUi.Services;
public class CoinCollection
{
public IEnumerable<Coin> GetItems() => new[]
{
public class CoinCollection {
public IEnumerable<Coin> GetItems() => new[] {
new Coin(),
new Coin(),
new Coin(),
+2 -3
View File
@@ -1,6 +1,5 @@
namespace PcgsInvUi.Services;
public class Database
{
// TODO Create a database using SQLite.
public class Database {
public Database() { }
}
+12 -21
View File
@@ -4,31 +4,26 @@ using System.Net.Http.Headers;
using System.Threading.Tasks;
// using Newtonsoft.Json;
using PcgsInvUi.Models;
using System.Text.Json;
using System.Text.Json.Serialization;
namespace PcgsInvUi.Services;
public class PcgsClient
{
public class PcgsClient {
private string _apiUri = "https://api.pcgs.com/publicapi";
private readonly string _apiKey;
public PcgsClient(string apiKey)
{
public PcgsClient(string apiKey) {
// _apiKey = apiKey;
_apiKey =
"E8xivTVN_k4Q8ubk8Xv_uU11U91WX0wDht4S4m4BAf2HPmKnGrZ0J2f9nccM7Ns1VkGoT1SXYR74I7aNaMKqXlJGEy3oobseKV0nGiqu1IKvFkOTVjhV37SWUVExSDFMC6FLzs7xJQIHwkcxr5JFOQNmc4ZytEh_-hmCN3NL-z0fEk98tzBmPJ_F7bq_xNru86QMD2A9yalu_dWe-lCysfyE2bCA2EDqwvWenRYf-0XnNtp6qlxxCMlCd-TDqqRKLC3qefCwpXSemwBiNSP5gbC9pwcKrZugkruuJ0nyxxThZymm";
}
public async Task<Coin> GetCoinFactsByGrade(int pcgsNumber, string grade, bool plusGrade = false)
{
public async Task<Coin> GetCoinFactsByGrade(int pcgsNumber, string grade, bool plusGrade = false) {
Coin newCoin = null;
using (HttpClient client = new HttpClient())
{
using (HttpClient client = new HttpClient()) {
var gradeParam = GetGradeFromString(grade);
string requestUri =
$"{_apiUri}/coindetail/GetCoinFactsByGrade/?PCGSNo={pcgsNumber}&GradeNo={gradeParam}&PlusGrade={plusGrade}";
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", _apiKey);
@@ -36,14 +31,12 @@ public class PcgsClient
HttpResponseMessage response = await client.GetAsync(requestUri);
Console.WriteLine("Got response.");
if (response.IsSuccessStatusCode)
{
if (response.IsSuccessStatusCode) {
string jsonResponse = await response.Content.ReadAsStringAsync();
newCoin = ParseJsonResponse(jsonResponse);
Console.WriteLine("Coin created.");
}
else
{
else {
Console.WriteLine($"Error: {response.StatusCode} - {response.ReasonPhrase}");
}
}
@@ -51,24 +44,22 @@ public class PcgsClient
return newCoin;
}
private int GetGradeFromString(string grade)
{
private int GetGradeFromString(string grade) {
var actualGrade = int.Parse(grade.Substring(grade.Length - 2));
Console.WriteLine($"Grade is {actualGrade}");
return actualGrade;
}
// TODO Will eventually create the other methods that are included in the Public API.
private Coin ParseJsonResponse(string json)
{
private Coin ParseJsonResponse(string json) {
Console.WriteLine(json);
Coin newCoin = JsonSerializer.Deserialize<Coin>(json);
Console.WriteLine($"New Coin has pcgs number {newCoin.PCGSNo}");
string test = JsonSerializer.Serialize(newCoin);
Console.WriteLine(test);
return newCoin;
}
}