Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions src/main/java/HWLesson_6/WeatherApp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package HWLesson_6;

import java.io.IOException;
import java.util.Objects;

import okhttp3.HttpUrl;
import okhttp3.OkHttpClient;
import okhttp3.Request;

public class WeatherApp {
private static final String BASE_HOST = "dataservice.accuweather.com";
private static final String FORECAST = "forecasts";
private static final String API_VERSION = "v1";
private static final String FORECAST_TYPE = "daily";
private static final String FORECAST_PERIOD = "5day";
private static final String SAINT_PETERSBURG_KEY = "295212";
private static final String API_KEY = "NMhWOUAJY8cgKzdgm5fBqcOsGluxsD5T";


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Перестанте ставить столько пустых строк, достаточно одной


public static void main(String[] args) throws IOException {

OkHttpClient client = new OkHttpClient();
HttpUrl url = new HttpUrl.Builder()
.scheme("http")
.host(BASE_HOST)
.addPathSegment(FORECAST)
.addPathSegment(API_VERSION)
.addPathSegment(FORECAST_TYPE)
.addPathSegment(FORECAST_PERIOD)
.addPathSegment(SAINT_PETERSBURG_KEY)
.addQueryParameter("apikey", API_KEY)
.addQueryParameter("language", "ru-ru")
.addQueryParameter("metric", "true")
.build();

System.out.println(url);

Request requesthttp = new Request.Builder()
.addHeader("accept", "application/json")
.url(url)
.build();

String jsonResponse = Objects.requireNonNull(client.newCall(requesthttp).execute().body()).string();
System.out.println(jsonResponse);


Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем \n ?

}

}