Initial commit
This commit is contained in:
commit
8c7e1b917f
180 files changed
+7747
No files matched your search
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using PcgsInvUi.Models;
|
||||
|
||||
namespace PcgsInvUi.Services;
|
||||
|
||||
public class CoinCollection
|
||||
{
|
||||
public IEnumerable<Coin> GetItems() => new[]
|
||||
{
|
||||
new Coin(),
|
||||
new Coin(),
|
||||
new Coin(),
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace PcgsInvUi.Services;
|
||||
|
||||
public class Database
|
||||
{
|
||||
// TODO Create a database using SQLite.
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using PcgsInvUi.Models;
|
||||
|
||||
namespace PcgsInvUi.Services;
|
||||
|
||||
public class PcgsClient
|
||||
{
|
||||
private string _apiUri = "https://api.pcgs.com/publicapi";
|
||||
private readonly string _apiKey;
|
||||
|
||||
public PcgsClient(string apiKey)
|
||||
{
|
||||
_apiKey = apiKey;
|
||||
}
|
||||
|
||||
public async Task<Coin> GetCoinFactsByGrade(int pcgsNumber, int grade, bool plusGrade)
|
||||
{
|
||||
Coin newCoin = null;
|
||||
using (HttpClient client = new HttpClient())
|
||||
{
|
||||
string requestUri =
|
||||
$"{_apiUri}/coindetail/GetCoinFactsByGrade/?PCGSNo={pcgsNumber}&GradeNo={grade}&PlusGrade={plusGrade}";
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", _apiKey);
|
||||
HttpResponseMessage response = await client.GetAsync(requestUri);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
string jsonResponse = await response.Content.ReadAsStringAsync();
|
||||
newCoin = ParseJsonResponse(jsonResponse);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine($"Error: {response.StatusCode} - {response.ReasonPhrase}");
|
||||
}
|
||||
}
|
||||
|
||||
return newCoin;
|
||||
}
|
||||
|
||||
// TODO Will eventually create the other methods that are included in the Public API.
|
||||
|
||||
private Coin ParseJsonResponse(string json)
|
||||
{
|
||||
Coin newCoin = JsonConvert.DeserializeObject<Coin>(json);
|
||||
return newCoin;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user