Пример #1
0
            /// <summary>
            /// Querys the API endpoint asynchronously and returns a <see cref="RiesgoPaisResponse"/> object.
            /// </summary>
            /// <returns>A task that contains a normalized <see cref="RiesgoPaisResponse"/> object.</returns>
            public async Task <RiesgoPaisResponse> GetRiesgoPais()
            {
                RiesgoPaisResponse cachedResponse = cache.GetObject <RiesgoPaisResponse>(RIESGO_PAIS_CACHE_KEY);

                if (cachedResponse != null)
                {
                    return(cachedResponse);
                }
                else
                {
                    RestRequest request = new RestRequest(RIESGO_PAIS_ENDPOINT, DataFormat.Json);
                    IRestResponse <RiesgoPaisResponse> response = await client.ExecuteGetAsync <RiesgoPaisResponse>(request).ConfigureAwait(false);

                    if (response.IsSuccessful)
                    {
                        cache.SaveObject(RIESGO_PAIS_CACHE_KEY, response.Data);
                        return(response.Data);
                    }
                    else
                    {
                        OnError(response);
                        return(null);
                    }
                }
            }
Пример #2
0
        public async Task GetRiesgoPaisValueAsync()
        {
            using (Context.Channel.EnterTypingState())
            {
                RiesgoPaisResponse result = await Api.DolarArgentina.GetRiesgoPais().ConfigureAwait(false);

                if (result != null)
                {
                    EmbedBuilder embed = CreateRiesgoPaisEmbed(result);
                    await ReplyAsync(embed : embed.Build()).ConfigureAwait(false);
                }
                else
                {
                    await ReplyAsync(REQUEST_ERROR_MESSAGE).ConfigureAwait(false);
                }
            }
        }