mirror of
https://github.com/Prominence/openweathermap-java-api.git
synced 2026-01-09 03:26:45 +03:00
Compare commits
2 Commits
ac1f043f51
...
d4c255385c
| Author | SHA1 | Date | |
|---|---|---|---|
| d4c255385c | |||
| 1002bc79de |
@ -31,6 +31,7 @@ import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRe
|
||||
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester;
|
||||
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.ALL;
|
||||
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.SPECIAL;
|
||||
|
||||
/**
|
||||
* The main public API client to communicate with OpenWeatherMap services.
|
||||
@ -80,6 +81,7 @@ public class OpenWeatherMapClient {
|
||||
* @return requester for retrieving one call weather information.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = ALL)
|
||||
@Deprecated
|
||||
public OneCallWeatherRequester oneCall() {
|
||||
return new OneCallWeatherRequester(new RequestSettings(apiKey, timeoutSettings));
|
||||
}
|
||||
@ -87,9 +89,15 @@ public class OpenWeatherMapClient {
|
||||
/**
|
||||
* One Call 3 API <a href="https://openweathermap.org/api/one-call-3">API</a>.
|
||||
* Includes a weather summary statement in addition to the information provided by {@link #oneCall()}
|
||||
*
|
||||
* Please note, that One Call API 3.0 is included in the "One Call by Call" subscription only.
|
||||
* This separate subscription includes 1,000 calls/day for free and allows you to pay only for the number of API calls made to this product.
|
||||
* Please note, that you do not need to subscribe to any other OpenWeather subscription plans to get access to the One Call API 3.0.
|
||||
* Please find more details on the pricing page and FAQ or ask Ulla, OpenWeather AI assistant.
|
||||
*
|
||||
* @return requester for retrieving one call weather information for the OneCall 3 API.
|
||||
*/
|
||||
@SubscriptionAvailability(plans = ALL)
|
||||
@SubscriptionAvailability(plans = SPECIAL)
|
||||
public OneCallWeatherRequester oneCall3() {
|
||||
RequestSettings requestSettings = new RequestSettings(apiKey, timeoutSettings);
|
||||
requestSettings.setUseApi3();
|
||||
|
||||
@ -56,4 +56,9 @@ public enum SubscriptionPlan {
|
||||
* All existing subscription plans.
|
||||
*/
|
||||
ALL,
|
||||
|
||||
/**
|
||||
* Special subscription cases.
|
||||
*/
|
||||
SPECIAL,
|
||||
}
|
||||
|
||||
@ -29,13 +29,11 @@ import com.github.prominence.openweathermap.api.request.RequestSettings;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -44,8 +42,8 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public final class RequestUtils {
|
||||
|
||||
private static final String OWM_URL_BASE = "http://api.openweathermap.org/data/2.5/";
|
||||
private static final String OWM_URL_BASE_3_0 = "http://api.openweathermap.org/data/3.0/";
|
||||
private static final String OWM_URL_BASE = "https://api.openweathermap.org/data/2.5/";
|
||||
private static final String OWM_URL_BASE_3_0 = "https://api.openweathermap.org/data/3.0/";
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(RequestUtils.class);
|
||||
|
||||
@ -60,7 +58,13 @@ public final class RequestUtils {
|
||||
requestUrlBuilder.append(requestSettings.getUrlAppender());
|
||||
requestUrlBuilder.append('?');
|
||||
String parameters = requestSettings.getRequestParameters().entrySet().stream()
|
||||
.map(entry -> entry.getKey() + "=" + entry.getValue())
|
||||
.map(entry -> {
|
||||
try {
|
||||
return entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), "UTF-8");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})
|
||||
.collect(Collectors.joining("&"));
|
||||
requestUrlBuilder.append(parameters);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user