Once again pushing broken code

This commit is contained in:
alphafetus committed 2023-11-30 16:56:24 -05:00
1 parent fab011b898
commit 683a2cf87b
2 files changed
+43 -4

No files matched your search

+25 -1
View File
@@ -25,10 +25,34 @@ public class PcgsClient : ReactiveObject {
private readonly string _apiKey;
private int _numApiRequests;
public PcgsClient(string apiKey) {
/// <summary>
/// Creates a new instance of the PcgsClient class.
/// Although this is a constructor, it's meant to be called only from the CreateClient method.
/// </summary>
private PcgsClient(string apiKey) {
_apiKey = apiKey;
// "E8xivTVN_k4Q8ubk8Xv_uU11U91WX0wDht4S4m4BAf2HPmKnGrZ0J2f9nccM7Ns1VkGoT1SXYR74I7aNaMKqXlJGEy3oobseKV0nGiqu1IKvFkOTVjhV37SWUVExSDFMC6FLzs7xJQIHwkcxr5JFOQNmc4ZytEh_-hmCN3NL-z0fEk98tzBmPJ_F7bq_xNru86QMD2A9yalu_dWe-lCysfyE2bCA2EDqwvWenRYf-0XnNtp6qlxxCMlCd-TDqqRKLC3qefCwpXSemwBiNSP5gbC9pwcKrZugkruuJ0nyxxThZymm";
}
/// <summary>
/// Creates a new instance of the PcgsClient class.
/// </summary>
/// <param name="apiKey">The api key to use for requests.</param>
/// <returns>A new instance of the PcgsClient class, or null if the key is invalid.</returns>
public static PcgsClient? CreateClient(string apiKey) {
// Check if the api key is valid.
var testClient = new PcgsClient(apiKey);
if (!testClient.VerifyCredentials()) return null;
return testClient;
}
public bool VerifyCredentials() {
// Create a way to check if the api key given is valid
// I think the best way to do this is to make a request to the api and see if it returns the expected response.
var result = this.GetCoinFactsByGrade(1, "1"); // This is a known invalid coin id - this is because the api is very fast with invalid requests.
if (result.Result.Item1 == ErrorType.ApiKeyInvalid) return false;
return true;
}
public async Task<(ErrorType, Coin?)> GetCoinFactsByGrade(int pcgsNumber, string grade, bool plusGrade = false) {
using (HttpClient client = new HttpClient()) {