
com.gocardless.http.UrlFormatter Maven / Gradle / Ivy
package com.gocardless.http;
import static com.google.common.net.UrlEscapers.urlPathSegmentEscaper;
import java.util.Map;
import okhttp3.HttpUrl;
final class UrlFormatter {
private final HttpUrl baseUrl;
UrlFormatter(String baseUrl) {
this.baseUrl = HttpUrl.parse(baseUrl);
}
HttpUrl formatUrl(String template, Map pathParams,
Map queryParams) {
String path = template;
for (Map.Entry entry : pathParams.entrySet()) {
path = path.replace(":" + entry.getKey(),
urlPathSegmentEscaper().escape(entry.getValue()));
}
HttpUrl.Builder builder = baseUrl.resolve(path).newBuilder();
for (Map.Entry param : queryParams.entrySet()) {
builder.addQueryParameter(param.getKey(), param.getValue().toString());
}
return builder.build();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy