public static IHttpClientBuilder AddScryfallApiClient(this IServiceCollection services, Action <ScryfallApiClientConfig> configure) { var clientConfig = ScryfallApiClientConfig.GetDefault(); configure(clientConfig); return(AddScryfallApiClient(services, clientConfig)); }
static async Task Main(string[] args) { var httpClient = new HttpClient { BaseAddress = ScryfallApiClientConfig.GetDefault().ScryfallApiBaseAddress }; var client = new ScryfallApiClient(httpClient); do { try { var randomCard = await client.Cards.GetRandom(); Console.Clear(); Console.WriteLine(DrawCard(randomCard)); } catch (ScryfallApiException ex) { Console.Clear(); Console.WriteLine($"Error: {ex.Message}"); Console.WriteLine($"Status Code: {ex.ResponseStatusCode}"); Console.WriteLine($"Remote Call: {ex.RequestMethod} {ex.RequestUri}"); } Console.WriteLine(Environment.NewLine + "Press any key for a new card. Press Esc to quit."); } while (Console.ReadKey().Key != ConsoleKey.Escape); }
/// <summary> /// Instantiate a new Scryfall API client. /// </summary> /// <param name="httpClient"></param> /// <param name="clientConfig"></param> /// <param name="cache"></param> public ScryfallApiClient(HttpClient httpClient, ScryfallApiClientConfig clientConfig = null, IMemoryCache cache = null) { if (clientConfig is null) { clientConfig = ScryfallApiClientConfig.GetDefault(); clientConfig.EnableCaching = cache is not null; } var restService = new BaseRestService(httpClient, clientConfig, cache); _cards = new Lazy <ICards>(() => new Cards(restService)); _catalogs = new Lazy <ICatalogs>(() => new Catalogs(restService)); _sets = new Lazy <ISets>(() => new Sets(restService)); _symbology = new Lazy <ISymbology>(() => new Symbology(restService)); _bulkData = new Lazy <IBulkData>(() => new BulkData(restService)); }
public static IHttpClientBuilder AddScryfallApiClient(this IServiceCollection services) => AddScryfallApiClient(services, ScryfallApiClientConfig.GetDefault());