Compare commits

...

2 Commits

3 changed files with 25 additions and 8 deletions

View File

@ -31,6 +31,7 @@ import com.github.prominence.openweathermap.api.request.onecall.OneCallWeatherRe
import com.github.prominence.openweathermap.api.request.weather.CurrentWeatherRequester; 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.ALL;
import static com.github.prominence.openweathermap.api.enums.SubscriptionPlan.SPECIAL;
/** /**
* The main public API client to communicate with OpenWeatherMap services. * 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. * @return requester for retrieving one call weather information.
*/ */
@SubscriptionAvailability(plans = ALL) @SubscriptionAvailability(plans = ALL)
@Deprecated
public OneCallWeatherRequester oneCall() { public OneCallWeatherRequester oneCall() {
return new OneCallWeatherRequester(new RequestSettings(apiKey, timeoutSettings)); 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>. * 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()} * 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. * @return requester for retrieving one call weather information for the OneCall 3 API.
*/ */
@SubscriptionAvailability(plans = ALL) @SubscriptionAvailability(plans = SPECIAL)
public OneCallWeatherRequester oneCall3() { public OneCallWeatherRequester oneCall3() {
RequestSettings requestSettings = new RequestSettings(apiKey, timeoutSettings); RequestSettings requestSettings = new RequestSettings(apiKey, timeoutSettings);
requestSettings.setUseApi3(); requestSettings.setUseApi3();

View File

@ -56,4 +56,9 @@ public enum SubscriptionPlan {
* All existing subscription plans. * All existing subscription plans.
*/ */
ALL, ALL,
/**
* Special subscription cases.
*/
SPECIAL,
} }

View File

@ -29,13 +29,11 @@ import com.github.prominence.openweathermap.api.request.RequestSettings;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.BufferedReader; import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -44,8 +42,8 @@ import java.util.stream.Collectors;
*/ */
public final class RequestUtils { 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 = "https://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_3_0 = "https://api.openweathermap.org/data/3.0/";
private static final Logger logger = LoggerFactory.getLogger(RequestUtils.class); private static final Logger logger = LoggerFactory.getLogger(RequestUtils.class);
@ -60,7 +58,13 @@ public final class RequestUtils {
requestUrlBuilder.append(requestSettings.getUrlAppender()); requestUrlBuilder.append(requestSettings.getUrlAppender());
requestUrlBuilder.append('?'); requestUrlBuilder.append('?');
String parameters = requestSettings.getRequestParameters().entrySet().stream() 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("&")); .collect(Collectors.joining("&"));
requestUrlBuilder.append(parameters); requestUrlBuilder.append(parameters);