Ejemplo n.º 1
0
        /// <inheritdoc cref="IFlightSection.GetListReturnAsync(IReadOnlyList{long}, CancellationToken)"/>
        public async Task <IReadOnlyList <FlightDto> > GetListReturnAsync(IReadOnlyList <long> flightIds, CancellationToken ct = default)
        {
            var requestUri = Endpoint.AppendPathSegment("returns").SetQueryParam(nameof(flightIds), flightIds);

            using var response = await HttpClient.GetAsync(requestUri, ct).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();
            var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(JsonSerializer.Deserialize <IReadOnlyList <FlightDto> >(content, Options));
        }
Ejemplo n.º 2
0
        /// <inheritdoc cref="IFlightSection.SearchFlightsAsync(Pagination, FlightSearchFiltersDto, CancellationToken)"/>
        public async Task <IReadOnlyList <FlightDto> > SearchFlightsAsync(Pagination pagination, FlightSearchFiltersDto filters, CancellationToken ct = default)
        {
            var requestUri = Endpoint.AppendPathSegment("search").SetQueryParams(pagination);
            var body       = new StringContent(JsonSerializer.Serialize(filters), Encoding.UTF8, MediaTypeNames.Application.Json);

            using var response = await HttpClient.PostAsync(requestUri, body, ct).ConfigureAwait(false);

            response.EnsureSuccessStatusCode();
            var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

            return(JsonSerializer.Deserialize <IReadOnlyList <FlightDto> >(content, Options));
        }
Ejemplo n.º 3
0
        public async Task <bool> PullInfo()
        {
            try
            {
                var result = await Endpoint.AppendPathSegment("cards/named")
                             .SetQueryParam("fuzzy", Title)
                             .GetJsonAsync <ScryfallCard>();

                if (result == null)
                {
                    Log($"Couldn't find infor for {Title}");
                    return(false);
                }
                Log($"Info for {Title}: {result.oracle_text}");
                ScryfallId   = result.id;
                Title        = result.name;
                ScryfallCard = result;

                ScryfallCard.oracle_text = ExpandText(ScryfallCard.oracle_text);

                var imageUri  = result.image_uris["small"];
                var imagePath = result.id.ToString() + "-small.jpg";
                ImageFilename = imagePath;
                if (!File.Exists(imagePath))
                {
                    var bytes = await imageUri.GetBytesAsync();

                    File.WriteAllBytes(imagePath, bytes);
                    Log($"Wrote image for {result.name} to {ImageFilename}");
                }

                return(true);
            }
            catch (Exception e)
            {
                Error($"Error getting info on {Title}: {e.Message}");
                return(false);
            }
        }