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); }
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); } }
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); } }