コード例 #1
0
        public Forecast5Day GetForecast5Day(HttpClient httpClient, double lat, double lon)
        {
            JsonSerializerOptions serializerOptions = new JsonSerializerOptions {
                IncludeFields = true
            };

            string url = ForecastUrl(lat, lon);

            try {
                var forecastTask = httpClient.GetFromJsonAsync <Forecast5Day>(url, serializerOptions);
                forecastTask.Wait(); // todo
                //Logger.LogLine($"Received OpenWeather forecast: {forecastTask.Result.cnt} elements");
                return(forecastTask.Result);
            } catch (Exception e) {
                Logger.LogLine($"Exception: {e}");
                return(null);
            }

            return(null);
        }
コード例 #2
0
        public Update[] GetUpdates(HttpClient httpClient)
        {
            JsonSerializerOptions serializerOptions = new JsonSerializerOptions {
                IncludeFields = true
            };
            string getUpdatesParams = nextUpdateId != -1 ?
                                      $"offset={nextUpdateId}&timeout={getUpdatesTimeout}" :
                                      $"timeout={getUpdatesTimeout}";
            string url = this.MethodUrl("getUpdates", getUpdatesParams);

            try {
                var getTask = httpClient.GetFromJsonAsync <ResponseGetUpdates>(url, serializerOptions);

                // todo: find out what to do with async
                getTask.Wait();

                TelegramApi.ResponseGetUpdates response = getTask.Result;
                //Logger.LogLine("Result:");
                //Logger.LogLine(resultStr);

                // Try to deserialize
                if (response.ok)
                {
                    // Update our nextUpdateId, we need it for requesting unconfirmed updates
                    foreach (TelegramApi.Update update in response.result)
                    {
                        nextUpdateId = update.update_id + 1;
                    }
                    return(response.result);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception e) {
                Logger.LogLine($"GetUpdates exception: {e}");
                return(null);
            }
        }
コード例 #3
0
        public User GetMe(HttpClient httpClient)
        {
            JsonSerializerOptions serializerOptions = new JsonSerializerOptions {
                IncludeFields = true
            };

            try {
                var task = httpClient.GetFromJsonAsync <ResponseGetMe>(this.MethodUrl("getMe"), serializerOptions);
                task.Wait();
                TelegramApi.ResponseGetMe response = task.Result;
                if (response.ok)
                {
                    return(response.result);
                }
                else
                {
                    return(null);
                }
            } catch (Exception e) {
                Logger.LogLine($"GetMe exception: {e}");
                return(null);
            }
        }