diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..5133e9c --- /dev/null +++ b/Main.java @@ -0,0 +1,49 @@ +package ru.gb.lesson6; + +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import java.io.IOException; +import java.util.Objects; + + + +public class HomeWork { + /* GET /forecasts/v1/daily/5day/294021?apikey=9XYyszHsrJS0G5ApsznzKxw0UyHZpz4A HTTP/1.1 */ + + public static final String HOST = "dataservice.accuweather.com"; + public static final String FORECAST_URL = "forecasts"; + public static final String DAILY_URL = "daily"; + public static final String FIVE_DAY_URL = "5day"; + public static final String API_VERSION = "v1"; + public static final String CITY_ID = "294021"; + public static final String API_KEY = "9XYyszHsrJS0G5ApsznzKxw0UyHZpz4A"; + public static final String LANGUAGE = "ru-ru"; + public static final String METRIC = "true"; + + public static void main(String[] args) throws IOException { + + OkHttpClient client = new OkHttpClient(); + HttpUrl url = new HttpUrl.Builder() + .scheme("http") + .host(HOST) + .addPathSegment(FORECAST_URL) + .addPathSegment(API_VERSION) + .addPathSegment(DAILY_URL) + .addPathSegment(FIVE_DAY_URL) + .addPathSegment(CITY_ID) + .addQueryParameter("apikey", API_KEY) + .addQueryParameter("language", LANGUAGE) + .addQueryParameter("metric", METRIC) + .build(); + + Request request = new Request.Builder() + .url(url) + .build(); + Response response = client.newCall(request).execute(); + + System.out.println(Objects.requireNonNull(response.body()).string()); + } + +} \ No newline at end of file diff --git a/Request.json b/Request.json new file mode 100644 index 0000000..8b5c5f7 --- /dev/null +++ b/Request.json @@ -0,0 +1,170 @@ +{ + "Headline": { + "EffectiveDate": "2021-08-28T07:00:00+03:00", + "EffectiveEpochDate": 1630123200, + "Severity": 4, + "Text": "Приятная погода в эти выходные", + "Category": "mild", + "EndDate": null, + "EndEpochDate": null, + "MobileLink": "http://www.accuweather.com/ru/ru/moscow/294021/daily-weather-forecast/294021?unit=c", + "Link": "http://www.accuweather.com/ru/ru/moscow/294021/daily-weather-forecast/294021?unit=c" + }, + "DailyForecasts": [ + { + "Date": "2021-08-27T07:00:00+03:00", + "EpochDate": 1630036800, + "Temperature": { + "Minimum": { + "Value": 14.6, + "Unit": "C", + "UnitType": 17 + }, + "Maximum": { + "Value": 22.6, + "Unit": "C", + "UnitType": 17 + } + }, + "Day": { + "Icon": 4, + "IconPhrase": "Переменная облачность", + "HasPrecipitation": false + }, + "Night": { + "Icon": 35, + "IconPhrase": "Облачно с прояснениями", + "HasPrecipitation": false + }, + "Sources": [ + "AccuWeather" + ], + "MobileLink": "http://www.accuweather.com/ru/ru/moscow/294021/daily-weather-forecast/294021?day=1&unit=c", + "Link": "http://www.accuweather.com/ru/ru/moscow/294021/daily-weather-forecast/294021?day=1&unit=c" + }, + { + "Date": "2021-08-28T07:00:00+03:00", + "EpochDate": 1630123200, + "Temperature": { + "Minimum": { + "Value": 14.4, + "Unit": "C", + "UnitType": 17 + }, + "Maximum": { + "Value": 22.8, + "Unit": "C", + "UnitType": 17 + } + }, + "Day": { + "Icon": 4, + "IconPhrase": "Переменная облачность", + "HasPrecipitation": false + }, + "Night": { + "Icon": 34, + "IconPhrase": "Преимущественно ясно", + "HasPrecipitation": false + }, + "Sources": [ + "AccuWeather" + ], + "MobileLink": "http://www.accuweather.com/ru/ru/moscow/294021/daily-weather-forecast/294021?day=2&unit=c", + "Link": "http://www.accuweather.com/ru/ru/moscow/294021/daily-weather-forecast/294021?day=2&unit=c" + }, + { + "Date": "2021-08-29T07:00:00+03:00", + "EpochDate": 1630209600, + "Temperature": { + "Minimum": { + "Value": 12.9, + "Unit": "C", + "UnitType": 17 + }, + "Maximum": { + "Value": 22.2, + "Unit": "C", + "UnitType": 17 + } + }, + "Day": { + "Icon": 3, + "IconPhrase": "Небольшая облачность", + "HasPrecipitation": false + }, + "Night": { + "Icon": 36, + "IconPhrase": "Переменная облачность", + "HasPrecipitation": false + }, + "Sources": [ + "AccuWeather" + ], + "MobileLink": "http://www.accuweather.com/ru/ru/moscow/294021/daily-weather-forecast/294021?day=3&unit=c", + "Link": "http://www.accuweather.com/ru/ru/moscow/294021/daily-weather-forecast/294021?day=3&unit=c" + }, + { + "Date": "2021-08-30T07:00:00+03:00", + "EpochDate": 1630296000, + "Temperature": { + "Minimum": { + "Value": 13.6, + "Unit": "C", + "UnitType": 17 + }, + "Maximum": { + "Value": 23.8, + "Unit": "C", + "UnitType": 17 + } + }, + "Day": { + "Icon": 3, + "IconPhrase": "Небольшая облачность", + "HasPrecipitation": false + }, + "Night": { + "Icon": 34, + "IconPhrase": "Преимущественно ясно", + "HasPrecipitation": false + }, + "Sources": [ + "AccuWeather" + ], + "MobileLink": "http://www.accuweather.com/ru/ru/moscow/294021/daily-weather-forecast/294021?day=4&unit=c", + "Link": "http://www.accuweather.com/ru/ru/moscow/294021/daily-weather-forecast/294021?day=4&unit=c" + }, + { + "Date": "2021-08-31T07:00:00+03:00", + "EpochDate": 1630382400, + "Temperature": { + "Minimum": { + "Value": 14.1, + "Unit": "C", + "UnitType": 17 + }, + "Maximum": { + "Value": 23.7, + "Unit": "C", + "UnitType": 17 + } + }, + "Day": { + "Icon": 4, + "IconPhrase": "Переменная облачность", + "HasPrecipitation": false + }, + "Night": { + "Icon": 36, + "IconPhrase": "Переменная облачность", + "HasPrecipitation": false + }, + "Sources": [ + "AccuWeather" + ], + "MobileLink": "http://www.accuweather.com/ru/ru/moscow/294021/daily-weather-forecast/294021?day=5&unit=c", + "Link": "http://www.accuweather.com/ru/ru/moscow/294021/daily-weather-forecast/294021?day=5&unit=c" + } + ] +} \ No newline at end of file